From 371c910a6ffa8d91a5376b05ab1f60352cf442d6 Mon Sep 17 00:00:00 2001 From: kmoore Date: Mon, 7 Feb 2011 15:37:15 +0000 Subject: deleted everything but the .project since these project were renamed, ready to be archived --- .../.classpath | 13 - .../.cvsignore | 6 - .../.project | 27 +- .../.settings/org.eclipse.core.resources.prefs | 3 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../META-INF/MANIFEST.MF | 24 - .../about.html | 34 - .../build.properties | 19 - .../plugin.properties | 23 - .../plugin.xml | 34 - .../extension/resource/ExtensionTestPlugin.java | 55 - .../resource/JavaTestAttributeMapping.java | 35 - .../JavaTestAttributeMappingDefinition.java | 63 - .../extension/resource/JavaTestTypeMapping.java | 42 - .../resource/JavaTestTypeMappingDefinition.java | 54 - .../extension/resource/TestJavaBasicMapping.java | 21 - .../tests/extension/resource/TestJavaEntity.java | 31 - .../tests/extension/resource/TestJpaFactory.java | 39 - .../extension/resource/TestJpaPlatformFactory.java | 66 - .../resource/TestJpaPlatformProvider.java | 163 - .../resource/TestJpaPlatformUiFactory.java | 33 - jpa/tests/org.eclipse.jpt.core.tests/.classpath | 15 - jpa/tests/org.eclipse.jpt.core.tests/.cvsignore | 5 - jpa/tests/org.eclipse.jpt.core.tests/.project | 25 +- .../.settings/org.eclipse.core.resources.prefs | 3 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../META-INF/MANIFEST.MF | 45 - jpa/tests/org.eclipse.jpt.core.tests/about.html | 34 - .../org.eclipse.jpt.core.tests/build.properties | 18 - .../org.eclipse.jpt.core.tests/plugin.properties | 23 - .../eclipse/jpt/core/tests/JptCoreTestsPlugin.java | 61 - .../src/org/eclipse/jpt/core/tests/MiscTests.java | 65 - .../jpt/core/tests/internal/JptCoreTests.java | 74 - .../internal/context/ContextModelTestCase.java | 221 -- .../core/tests/internal/context/JpaFileTests.java | 411 --- .../tests/internal/context/JpaProjectTests.java | 172 - .../internal/context/JptCoreContextModelTests.java | 52 - .../java/GenericJavaPersistentAttributeTests.java | 236 -- .../java/GenericJavaPersistentTypeTests.java | 759 ----- .../context/java/JavaAssociationOverrideTests.java | 446 --- .../context/java/JavaAttributeOverrideTests.java | 260 -- .../context/java/JavaBasicMappingTests.java | 995 ------ .../internal/context/java/JavaCascadeTests.java | 321 -- .../internal/context/java/JavaColumnTests.java | 843 ----- .../context/java/JavaDiscriminatorColumnTests.java | 458 --- .../internal/context/java/JavaEmbeddableTests.java | 171 - .../context/java/JavaEmbeddedIdMappingTests.java | 659 ---- .../context/java/JavaEmbeddedMappingTests.java | 863 ----- .../internal/context/java/JavaEntityTests.java | 3417 -------------------- .../context/java/JavaGeneratedValueTests.java | 150 - .../internal/context/java/JavaIdMappingTests.java | 715 ---- .../internal/context/java/JavaJoinColumnTests.java | 549 ---- .../internal/context/java/JavaJoinTableTests.java | 1177 ------- .../context/java/JavaManyToManyMappingTests.java | 1180 ------- .../context/java/JavaManyToOneMappingTests.java | 960 ------ .../context/java/JavaMappedSuperclassTests.java | 288 -- .../context/java/JavaNamedNativeQueryTests.java | 432 --- .../internal/context/java/JavaNamedQueryTests.java | 333 -- .../context/java/JavaOneToManyMappingTests.java | 1160 ------- .../context/java/JavaOneToOneMappingTests.java | 1511 --------- .../java/JavaPrimaryKeyJoinColumnTests.java | 303 -- .../internal/context/java/JavaQueryHintTests.java | 145 - .../context/java/JavaSecondaryTableTests.java | 730 ----- .../context/java/JavaSequenceGeneratorTests.java | 235 -- .../context/java/JavaTableGeneratorTests.java | 671 ---- .../internal/context/java/JavaTableTests.java | 610 ---- .../context/java/JavaTransientMappingTests.java | 249 -- .../context/java/JavaVersionMappingTests.java | 400 --- .../context/java/JptCoreContextJavaModelTests.java | 59 - .../internal/context/orm/EntityMappingsTests.java | 1066 ------ .../orm/GenericOrmPersistentAttributeTests.java | 314 -- .../context/orm/GenericOrmPersistentTypeTests.java | 574 ---- .../context/orm/JptCoreOrmContextModelTests.java | 62 - .../context/orm/OrmAssociationOverrideTests.java | 267 -- .../context/orm/OrmAttributeOverrideTests.java | 99 - .../internal/context/orm/OrmBasicMappingTests.java | 711 ---- .../internal/context/orm/OrmCascadeTests.java | 280 -- .../tests/internal/context/orm/OrmColumnTests.java | 835 ----- .../context/orm/OrmDiscriminatorColumnTests.java | 456 --- .../internal/context/orm/OrmEmbeddableTests.java | 295 -- .../context/orm/OrmEmbeddedIdMappingTests.java | 923 ------ .../context/orm/OrmEmbeddedMappingTests.java | 943 ------ .../tests/internal/context/orm/OrmEntityTests.java | 2790 ---------------- .../context/orm/OrmGeneratedValueTests.java | 136 - .../internal/context/orm/OrmIdMappingTests.java | 746 ----- .../internal/context/orm/OrmJoinColumnTests.java | 506 --- .../internal/context/orm/OrmJoinTableTests.java | 1365 -------- .../context/orm/OrmManyToManyMappingTests.java | 1065 ------ .../context/orm/OrmManyToOneMappingTests.java | 618 ---- .../context/orm/OrmMappedSuperclassTests.java | 386 --- .../context/orm/OrmNamedNativeQueryTests.java | 358 -- .../internal/context/orm/OrmNamedQueryTests.java | 273 -- .../context/orm/OrmOneToManyMappingTests.java | 1058 ------ .../context/orm/OrmOneToOneMappingTests.java | 1196 ------- .../context/orm/OrmPrimaryKeyJoinColumnTests.java | 253 -- .../internal/context/orm/OrmQueryHintTests.java | 122 - .../context/orm/OrmSecondaryTableTests.java | 767 ----- .../context/orm/OrmSequenceGeneratorTests.java | 172 - .../context/orm/OrmTableGeneratorTests.java | 604 ---- .../tests/internal/context/orm/OrmTableTests.java | 827 ----- .../context/orm/OrmTransientMappingTests.java | 305 -- .../context/orm/OrmVersionMappingTests.java | 489 --- .../tests/internal/context/orm/OrmXmlTests.java | 69 - .../context/orm/PersistenceUnitDefaultsTests.java | 369 --- .../context/orm/PersistenceUnitMetadataTests.java | 104 - .../context/persistence/ClassRefTests.java | 113 - .../JptCorePersistenceContextModelTests.java | 33 - .../context/persistence/MappingFileRefTests.java | 98 - .../context/persistence/PersistenceTests.java | 134 - .../persistence/PersistenceUnitTestCase.java | 361 --- .../context/persistence/PersistenceUnitTests.java | 1247 ------- .../context/persistence/PersistenceXmlTests.java | 56 - .../context/persistence/RootContextNodeTests.java | 53 - .../context/Generic2_0ContextModelTestCase.java | 35 - .../java/Generic2_0JavaContextModelTests.java | 41 - .../GenericJavaAssociationOverride2_0Tests.java | 580 ---- .../context/java/GenericJavaCascade2_0Tests.java | 106 - .../java/GenericJavaCollectionTable2_0Tests.java | 722 ----- ...enericJavaElementCollectionMapping2_0Tests.java | 2077 ------------ .../java/GenericJavaEmbeddedMapping2_0Tests.java | 1550 --------- .../context/java/GenericJavaEntity2_0Tests.java | 2069 ------------ .../java/GenericJavaManyToManyMapping2_0Tests.java | 1218 ------- .../java/GenericJavaManyToOneMapping2_0Tests.java | 419 --- .../java/GenericJavaOneToManyMapping2_0Tests.java | 1526 --------- .../java/GenericJavaOneToOneMapping2_0Tests.java | 884 ----- .../GenericJavaPersistentAttribute2_0Tests.java | 162 - .../java/GenericJavaPersistentType2_0Tests.java | 853 ----- .../java/GenericJavaSequenceGenerator2_0Tests.java | 200 -- .../orm/Generic2_0OrmContextModelTests.java | 41 - .../orm/GenericOrmAssociationOverride2_0Tests.java | 534 --- .../context/orm/GenericOrmCascade2_0Tests.java | 89 - .../orm/GenericOrmCollectionTable2_0Tests.java | 753 ----- ...GenericOrmElementCollectionMapping2_0Tests.java | 1459 --------- .../orm/GenericOrmEmbeddedMapping2_0Tests.java | 1734 ---------- .../jpa2/context/orm/GenericOrmEntity2_0Tests.java | 1972 ----------- .../orm/GenericOrmManyToManyMapping2_0Tests.java | 939 ------ .../orm/GenericOrmManyToOneMapping2_0Tests.java | 674 ---- .../orm/GenericOrmOneToManyMapping2_0Tests.java | 1230 ------- .../orm/GenericOrmOneToOneMapping2_0Tests.java | 991 ------ .../orm/GenericOrmPersistentAttribute2_0Tests.java | 550 ---- .../orm/GenericOrmPersistentType2_0Tests.java | 283 -- .../orm/GenericOrmSequenceGenerator2_0Tests.java | 91 - .../persistence/Generic2_0ConnectionTests.java | 186 -- .../persistence/Generic2_0OptionsTests.java | 520 --- .../Generic2_0PersistenceContextModelTests.java | 30 - .../Generic2_0PersistenceUnitTests.java | 58 - .../resource/java/Access2_0AnnotationTests.java | 175 - .../resource/java/AssociationOverride2_0Tests.java | 885 ----- .../java/AssociationOverrides2_0Tests.java | 988 ------ .../resource/java/Cacheable2_0AnnotationTests.java | 106 - .../java/CollectionTable2_0AnnotationTests.java | 498 --- .../java/ElementCollection2_0AnnotationTests.java | 169 - .../jpa2/resource/java/JavaResource2_0Tests.java | 48 - .../java/JavaResourceModel2_0TestCase.java | 29 - .../java/ManyToMany2_0AnnotationTests.java | 409 --- .../resource/java/ManyToOne2_0AnnotationTests.java | 402 --- .../java/MapKeyClass2_0AnnotationTests.java | 108 - .../java/MapKeyColumn2_0AnnotationTests.java | 404 --- .../java/MapKeyEnumerated2_0AnnotationTests.java | 90 - .../java/MapKeyJoinColumn2_0AnnotationTests.java | 352 -- .../java/MapKeyJoinColumns2_0AnnotationTests.java | 420 --- .../java/MapKeyTemporal2_0AnnotationTests.java | 89 - .../resource/java/MapsId2_0AnnotationTests.java | 86 - .../resource/java/OneToMany2_0AnnotationTests.java | 412 --- .../resource/java/OneToOne2_0AnnotationTests.java | 462 --- .../java/OrderColumn2_0AnnotationTests.java | 252 -- .../java/SequenceGenerator2_0AnnotationTests.java | 123 - .../internal/model/JpaProjectManagerTests.java | 262 -- .../tests/internal/model/JptCoreModelTests.java | 28 - .../internal/platform/BaseJpaPlatformTests.java | 77 - .../platform/JpaPlatformExtensionTests.java | 96 - .../tests/internal/platform/JpaPlatformTests.java | 129 - .../tests/internal/projects/TestJpaProject.java | 128 - .../resource/JptCoreResourceModelTests.java | 42 - .../resource/java/AssociationOverrideTests.java | 253 -- .../resource/java/AssociationOverridesTests.java | 320 -- .../resource/java/AttributeOverrideTests.java | 157 - .../resource/java/AttributeOverridesTests.java | 274 -- .../tests/internal/resource/java/BasicTests.java | 151 - .../tests/internal/resource/java/ColumnTests.java | 404 --- .../resource/java/DiscriminatorColumnTests.java | 212 -- .../resource/java/DiscriminatorValueTests.java | 83 - .../internal/resource/java/EmbeddableTests.java | 74 - .../internal/resource/java/EmbeddedIdTests.java | 50 - .../internal/resource/java/EmbeddedTests.java | 50 - .../tests/internal/resource/java/EntityTests.java | 125 - .../internal/resource/java/EnumeratedTests.java | 89 - .../resource/java/GeneratedValueTests.java | 133 - .../tests/internal/resource/java/IdClassTests.java | 103 - .../core/tests/internal/resource/java/IdTests.java | 50 - .../internal/resource/java/InheritanceTests.java | 83 - .../internal/resource/java/JPTToolsTests.java | 479 --- .../resource/java/JavaResourceModelTestCase.java | 164 - .../java/JavaResourcePersistentAttributeTests.java | 870 ----- .../java/JavaResourcePersistentTypeTests.java | 937 ------ .../internal/resource/java/JoinColumnTests.java | 352 -- .../internal/resource/java/JoinColumnsTests.java | 420 --- .../internal/resource/java/JoinTableTests.java | 656 ---- .../java/JpaJavaResourceModelTestCase.java | 48 - .../resource/java/JptJavaResourceTests.java | 75 - .../tests/internal/resource/java/LobTests.java | 49 - .../internal/resource/java/ManyToManyTests.java | 394 --- .../internal/resource/java/ManyToOneTests.java | 387 --- .../tests/internal/resource/java/MapKeyTests.java | 88 - .../resource/java/MappedSuperclassTests.java | 74 - .../resource/java/NamedNativeQueriesTests.java | 421 --- .../resource/java/NamedNativeQueryTests.java | 341 -- .../internal/resource/java/NamedQueriesTests.java | 331 -- .../internal/resource/java/NamedQueryTests.java | 259 -- .../internal/resource/java/OneToManyTests.java | 397 --- .../internal/resource/java/OneToOneTests.java | 447 --- .../tests/internal/resource/java/OrderByTests.java | 87 - .../resource/java/PrimaryKeyJoinColumnTests.java | 187 -- .../resource/java/PrimaryKeyJoinColumnsTests.java | 252 -- .../internal/resource/java/QueryHintTests.java | 65 - .../resource/java/SecondaryTableTests.java | 436 --- .../resource/java/SecondaryTablesTests.java | 503 --- .../resource/java/SequenceGeneratorTests.java | 234 -- .../resource/java/TableGeneratorTests.java | 501 --- .../tests/internal/resource/java/TableTests.java | 346 -- .../internal/resource/java/TemporalTests.java | 88 - .../internal/resource/java/TransientTests.java | 50 - .../tests/internal/resource/java/VersionTests.java | 49 - jpa/tests/org.eclipse.jpt.core.tests/test.xml | 35 - jpa/tests/org.eclipse.jpt.db.tests/.classpath | 11 - jpa/tests/org.eclipse.jpt.db.tests/.cvsignore | 1 - jpa/tests/org.eclipse.jpt.db.tests/.project | 27 +- .../.settings/org.eclipse.core.resources.prefs | 3 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF | 19 - jpa/tests/org.eclipse.jpt.db.tests/about.html | 34 - .../org.eclipse.jpt.db.tests/build.properties | 14 - .../config/derby.properties | 24 - .../config/mysql.properties | 23 - .../config/oracle10g.properties | 24 - .../config/oracle10gXE.properties | 24 - .../config/oracle9i.properties | 24 - .../config/postgresql.properties | 23 - .../config/sqlserver.properties | 24 - .../config/sybase.properties | 24 - .../org.eclipse.jpt.db.tests/plugin.properties | 24 - .../eclipse/jpt/db/tests/internal/JDBCTests.java | 135 - .../eclipse/jpt/db/tests/internal/JDBCTools.java | 105 - .../eclipse/jpt/db/tests/internal/JptDbTests.java | 34 - .../jpt/db/tests/internal/JptDbTestsPlugin.java | 56 - .../tests/internal/platforms/AllPlatformTests.java | 37 - .../tests/internal/platforms/DTPPlatformTests.java | 1027 ------ .../db/tests/internal/platforms/DerbyTests.java | 482 --- .../db/tests/internal/platforms/MySQLTests.java | 404 --- .../tests/internal/platforms/Oracle10gTests.java | 397 --- .../tests/internal/platforms/Oracle10gXETests.java | 79 - .../db/tests/internal/platforms/Oracle9iTests.java | 79 - .../tests/internal/platforms/PostgreSQLTests.java | 486 --- .../tests/internal/platforms/SQLServerTests.java | 83 - .../db/tests/internal/platforms/SybaseTests.java | 443 --- .../.classpath | 13 - .../.cvsignore | 5 - .../.project | 27 +- .../.settings/org.eclipse.core.resources.prefs | 3 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../META-INF/MANIFEST.MF | 46 - .../about.html | 34 - .../build.properties | 18 - .../plugin.properties | 23 - .../tests/internal/JptEclipseLinkCoreTests.java | 93 - .../context/EclipseLinkContextModelTestCase.java | 50 - .../context/EclipseLinkJpaProjectTests.java | 149 - .../JptEclipseLink1_0CoreContextModelTests.java | 34 - .../JptEclipseLinkCoreContextModelTests.java | 45 - .../java/EclipseLinkJavaBasicMappingTests.java | 322 -- .../context/java/EclipseLinkJavaCachingTests.java | 646 ---- .../context/java/EclipseLinkJavaConvertTests.java | 224 -- .../java/EclipseLinkJavaConverterTests.java | 222 -- .../java/EclipseLinkJavaEmbeddableTests.java | 254 -- .../context/java/EclipseLinkJavaEntityTests.java | 387 --- .../java/EclipseLinkJavaIdMappingTests.java | 323 -- .../EclipseLinkJavaManyToManyMappingTests.java | 149 - .../java/EclipseLinkJavaManyToOneMappingTests.java | 148 - .../java/EclipseLinkJavaMappedSuperclassTests.java | 348 -- .../EclipseLinkJavaObjectTypeConverterTests.java | 644 ---- .../java/EclipseLinkJavaOneToManyMappingTests.java | 579 ---- .../java/EclipseLinkJavaOneToOneMappingTests.java | 449 --- .../java/EclipseLinkJavaStructConverterTests.java | 221 -- .../java/EclipseLinkJavaTypeConverterTests.java | 313 -- .../java/EclipseLinkJavaVersionMappingTests.java | 322 -- .../JptEclipseLinkCoreJavaContextModelTests.java | 43 - .../orm/EclipseLinkEntityMappingsTests.java | 675 ---- .../orm/EclipseLinkOrmBasicMappingTests.java | 389 --- .../orm/EclipseLinkOrmContextModelTestCase.java | 84 - .../context/orm/EclipseLinkOrmConverterTests.java | 194 -- .../context/orm/EclipseLinkOrmEmbeddableTests.java | 1035 ------ .../context/orm/EclipseLinkOrmEntityTests.java | 2394 -------------- .../context/orm/EclipseLinkOrmIdMappingTests.java | 389 --- .../orm/EclipseLinkOrmManyToManyMappingTests.java | 383 --- .../orm/EclipseLinkOrmManyToOneMappingTests.java | 321 -- .../orm/EclipseLinkOrmMappedSuperclassTests.java | 2147 ------------ .../EclipseLinkOrmObjectTypeConverterTests.java | 569 ---- .../orm/EclipseLinkOrmOneToManyMappingTests.java | 747 ----- .../orm/EclipseLinkOrmOneToOneMappingTests.java | 455 --- .../EclipseLinkOrmPersistentAttributeTests.java | 313 -- .../orm/EclipseLinkOrmStructConverterTests.java | 199 -- .../orm/EclipseLinkOrmTransientMappingTests.java | 62 - .../orm/EclipseLinkOrmTypeConverterTests.java | 266 -- .../orm/EclipseLinkOrmVersionMappingTests.java | 387 --- .../EclipseLinkPersistenceUnitDefaultsTests.java | 369 --- .../EclipseLinkPersistenceUnitMetadataTests.java | 105 - .../JptEclipseLinkCoreOrmContextModelTests.java | 47 - .../EclipseLinkPersistenceUnitTestCase.java | 53 - .../EclipseLinkPersistenceUnitTests.java | 178 - ...clipseLinkCorePersistenceContextModelTests.java | 43 - .../persistence/caching/CachingAdapterTests.java | 449 --- .../caching/CachingValueModelTests.java | 444 --- .../JptEclipseLinkPersistenceCachingTests.java | 33 - .../connection/EclipseLinkConnectionTests.java | 542 ---- .../JptEclipseLinkPersistenceConnectionTests.java | 33 - .../CustomizationValueModelTests.java | 204 -- .../EclipseLinkCustomizationTests.java | 762 ----- ...ptEclipseLinkPersistenceCustomizationTests.java | 33 - .../general/GeneralPropertiesAdapterTests.java | 105 - .../general/GeneralPropertiesValueModelTests.java | 162 - .../JptEclipseLinkPersistenceGeneralTests.java | 33 - .../JptEclipseLinkPersistenceLoggingTests.java | 33 - .../persistence/logging/LoggingAdapterTests.java | 339 -- .../logging/LoggingValueModelTests.java | 162 - .../JptEclipseLinkPersistenceOptionsTests.java | 33 - .../persistence/options/OptionsAdapterTests.java | 379 --- .../options/OptionsValueModelTests.java | 161 - ...clipseLinkPersistenceSchemaGenerationTests.java | 35 - .../generation/SchemaGenerationAdapterTests.java | 254 -- .../SchemaGenerationBasicAdapterTests.java | 154 - .../SchemaGenerationValueModelTests.java | 232 -- .../JptEclipselinkCoreResourceModelTests.java | 41 - .../tests/internal/resource/java/CacheTests.java | 448 --- .../resource/java/ChangeTrackingTests.java | 88 - .../java/ConversionValueAnnotationTests.java | 131 - .../resource/java/ConvertAnnotationTests.java | 105 - .../resource/java/ConverterAnnotationTests.java | 155 - .../resource/java/CustomizerAnnotationTests.java | 99 - .../java/EclipseLinkJavaResourceModelTestCase.java | 34 - .../java/EclipseLinkPrimaryKeyAnnotationTests.java | 53 - .../resource/java/ExistenceCheckingTests.java | 88 - .../internal/resource/java/JoinFetchTests.java | 92 - .../JptEclipseLinkCoreJavaResourceModelTests.java | 47 - .../resource/java/MutableAnnotationTests.java | 111 - .../java/ObjectTypeConverterAnnotationTests.java | 426 --- .../internal/resource/java/PrivateOwnedTests.java | 49 - .../internal/resource/java/ReadOnlyTests.java | 47 - .../java/ReadTransformerAnnotationTests.java | 155 - .../java/StructConverterAnnotationTests.java | 155 - .../internal/resource/java/TimeOfDayTests.java | 220 -- .../java/TransformationAnnotationTests.java | 158 - .../java/TypeConverterAnnotationTests.java | 214 -- .../java/WriteTransformerAnnotationTests.java | 219 -- .../EclipseLink1_1ContextModelTestCase.java | 33 - .../context/EclipseLink1_1JpaProjectTests.java | 173 - .../JptEclipseLink1_1CoreContextModelTests.java | 31 - .../orm/EclipseLink1_1OrmContextModelTestCase.java | 92 - .../EclipseLink1_1OrmPersistentAttributeTests.java | 429 --- .../orm/EclipseLink1_1OrmPersistentTypeTests.java | 301 -- .../EclipseLink1_1OrmTransientMappingTests.java | 63 - .../JptEclipseLink1_1CoreOrmContextModelTests.java | 33 - .../EclipseLink1_2ContextModelTestCase.java | 34 - .../context/EclipseLink1_2JpaProjectTests.java | 173 - .../JptEclipseLink1_2CoreContextModelTests.java | 30 - .../EclipseLink2_0ContextModelTestCase.java | 35 - .../JptEclipseLink2_0CoreContextModelTests.java | 39 - .../EclipseLink2_0JavaCollectionTableTests.java | 723 ----- ...seLink2_0JavaElementCollectionMappingTests.java | 2076 ------------ .../java/EclipseLink2_0JavaEntityTests.java | 1812 ----------- .../EclipseLink2_0JavaManyToManyMappingTests.java | 1303 -------- .../EclipseLink2_0JavaManyToOneMappingTests.java | 329 -- .../EclipseLink2_0JavaMappedSuperclassTests.java | 528 --- .../EclipseLink2_0JavaOneToManyMappingTests.java | 1421 -------- .../EclipseLink2_0JavaOneToOneMappingTests.java | 817 ----- .../JptEclipseLink2_0JavaContextModelTests.java | 35 - .../orm/EclipseLink2_0OrmCollectionTableTests.java | 751 ----- .../orm/EclipseLink2_0OrmContextModelTestCase.java | 92 - ...pseLink2_0OrmElementCollectionMappingTests.java | 1445 --------- .../context/orm/EclipseLink2_0OrmEntityTests.java | 1805 ----------- .../EclipseLink2_0OrmManyToManyMappingTests.java | 963 ------ .../EclipseLink2_0OrmMappedSuperclassTests.java | 2375 -------------- .../EclipseLink2_0OrmOneToManyMappingTests.java | 1076 ------ .../orm/EclipseLink2_0OrmOneToOneMappingTests.java | 910 ------ .../Eclipselink2_0OrmManyToOneMappingTests.java | 589 ---- .../orm/JptEclipseLink2_0OrmContextModelTests.java | 35 - .../persistence/EclipseLink2_0ConnectionTests.java | 172 - .../persistence/EclipseLink2_0LoggingTests.java | 430 --- .../persistence/EclipseLink2_0OptionsTests.java | 519 --- .../EclipseLink2_0PersistenceUnitTestCase.java | 57 - ...pseLink2_0CorePersistenceContextModelTests.java | 34 - .../test.xml | 49 - jpa/tests/org.eclipse.jpt.gen.tests/.classpath | 11 - jpa/tests/org.eclipse.jpt.gen.tests/.project | 27 +- .../.settings/org.eclipse.core.resources.prefs | 3 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../org.eclipse.jpt.gen.tests/META-INF/MANIFEST.MF | 14 - jpa/tests/org.eclipse.jpt.gen.tests/about.html | 34 - .../org.eclipse.jpt.gen.tests/build.properties | 18 - .../org.eclipse.jpt.gen.tests/plugin.properties | 23 - .../gen/tests/internal/EntityGenToolsTests.java | 143 - .../jpt/gen/tests/internal/JptGenTests.java | 32 - jpa/tests/org.eclipse.jpt.gen.tests/test.xml | 49 - jpa/tests/org.eclipse.jpt.ui.tests/.classpath | 13 - jpa/tests/org.eclipse.jpt.ui.tests/.project | 27 +- .../.settings/org.eclipse.core.resources.prefs | 3 - .../.settings/org.eclipse.jdt.core.prefs | 7 - .../org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF | 23 - .../org.eclipse.jpt.ui.tests/build.properties | 13 - .../org.eclipse.jpt.ui.tests/plugin.properties | 23 - .../src/org/eclipse/jpt/ui/tests/JptUiTests.java | 32 - .../platform/JpaPlatformUiExtensionTests.java | 65 - .../internal/platform/JptUiPlatformTests.java | 27 - 412 files changed, 11 insertions(+), 143518 deletions(-) delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.classpath delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.cvsignore delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.core.resources.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.jdt.core.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/META-INF/MANIFEST.MF delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/about.html delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/build.properties delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.properties delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.xml delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/ExtensionTestPlugin.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMapping.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMappingDefinition.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMapping.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMappingDefinition.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaBasicMapping.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaFactory.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformFactory.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformProvider.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUiFactory.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/.classpath delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/.cvsignore delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.core.resources.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/about.html delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/build.properties delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/plugin.properties delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/MiscTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaProjectTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentAttributeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/ClassRefTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/MappingFileRefTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceXmlTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/RootContextNodeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Access2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverride2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverrides2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Cacheable2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/CollectionTable2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResource2_0Tests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToMany2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToOne2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyColumn2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyEnumerated2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumn2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumns2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyTemporal2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapsId2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToMany2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToOne2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OrderColumn2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaProjectManagerTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JptCoreModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/BaseJpaPlatformTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJpaProject.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/JptCoreResourceModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverrideTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverridesTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverrideTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverridesTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/BasicTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorValueTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedIdTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EntityTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EnumeratedTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/GeneratedValueTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdClassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/InheritanceTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JptJavaResourceTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/LobTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToManyTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToOneTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MapKeyTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MappedSuperclassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueriesTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueryTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueriesTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueryTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToManyTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToOneTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OrderByTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/QueryHintTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTablesTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SequenceGeneratorTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableGeneratorTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TemporalTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TransientTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/VersionTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.core.tests/test.xml delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/.classpath delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/.cvsignore delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.core.resources.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/about.html delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/build.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/derby.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/mysql.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/oracle10g.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/oracle10gXE.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/oracle9i.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/postgresql.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/sqlserver.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/config/sybase.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/plugin.properties delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTools.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTestsPlugin.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/AllPlatformTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DerbyTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/MySQLTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gXETests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle9iTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/PostgreSQLTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SQLServerTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SybaseTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.core.resources.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/about.html delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkJpaProjectTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLink1_0CoreContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLinkCoreContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaBasicMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaCachingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConvertTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEmbeddableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEntityTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaIdMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaMappedSuperclassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaObjectTypeConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaStructConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaTypeConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaVersionMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkEntityMappingsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmBasicMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEmbeddableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEntityTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmMappedSuperclassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmObjectTypeConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmStructConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTransientMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTypeConverterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmVersionMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitDefaultsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitMetadataTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/JptEclipseLinkCoreOrmContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/JptEclipseLinkCorePersistenceContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/JptEclipseLinkPersistenceCachingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/EclipseLinkConnectionTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/JptEclipseLinkPersistenceConnectionTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/EclipseLinkCustomizationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/JptEclipseLinkPersistenceCustomizationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesAdapterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesValueModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/JptEclipseLinkPersistenceGeneralTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/JptEclipseLinkPersistenceLoggingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingValueModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/JptEclipseLinkPersistenceOptionsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsValueModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/JptEclipseLinkPersistenceSchemaGenerationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationAdapterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationBasicAdapterTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationValueModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/JptEclipselinkCoreResourceModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CacheTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ChangeTrackingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConversionValueAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CustomizerAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkPrimaryKeyAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ExistenceCheckingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JoinFetchTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ObjectTypeConverterAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/PrivateOwnedTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadOnlyTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TimeOfDayTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1ContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1JpaProjectTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/JptEclipseLink1_1CoreContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentAttributeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentTypeTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmTransientMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/JptEclipseLink1_1CoreOrmContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2ContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2JpaProjectTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/JptEclipseLink1_2CoreContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/EclipseLink2_0ContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/JptEclipseLink2_0CoreContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaCollectionTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaElementCollectionMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaEntityTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaMappedSuperclassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/JptEclipseLink2_0JavaContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmCollectionTableTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmContextModelTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmElementCollectionMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmEntityTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmMappedSuperclassTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/JptEclipseLink2_0OrmContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0ConnectionTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0LoggingTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0PersistenceUnitTestCase.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/JptEclipseLink2_0CorePersistenceContextModelTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.eclipselink.core.tests/test.xml delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/.classpath delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.core.resources.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/META-INF/MANIFEST.MF delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/about.html delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/build.properties delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/plugin.properties delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/EntityGenToolsTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/JptGenTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.gen.tests/test.xml delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/.classpath delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.core.resources.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/build.properties delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/plugin.properties delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JpaPlatformUiExtensionTests.java delete mode 100644 jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JptUiPlatformTests.java diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.classpath b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.classpath deleted file mode 100644 index 1f8c49a2a4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.classpath +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.cvsignore b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.cvsignore deleted file mode 100644 index a196dd7686..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -bin -@dot -temp.folder -build.xml -javaCompiler...args -javaCompiler...args.* \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.project b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.project index bb6561e95f..5eca35f465 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.project +++ b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.project @@ -1,28 +1,5 @@ org.eclipse.jpt.core.tests.extension.resource - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - + renamed to org.eclipse.jpt.jpa.core.tests.extension.resource + \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 55044aaf02..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Mon Apr 07 14:26:32 EDT 2008 -eclipse.preferences.version=1 -encoding/=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.jdt.core.prefs b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 929d54536d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Sun May 27 14:59:18 EDT 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/META-INF/MANIFEST.MF deleted file mode 100644 index df3d1022b1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/META-INF/MANIFEST.MF +++ /dev/null @@ -1,24 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.core.tests.extension.resource;singleton:=true -Bundle-Version: 2.4.0.qualifier -Bundle-Activator: org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin -Bundle-ActivationPolicy: lazy -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.resources, - org.eclipse.core.runtime, - org.eclipse.jdt.core, - org.eclipse.jpt.common.core, - org.eclipse.jpt.core, - org.eclipse.jpt.ui, - org.eclipse.jpt.core, - org.eclipse.jpt.gen, - org.eclipse.jpt.jpa.db, - org.eclipse.jpt.common.utility, - org.eclipse.swt, - org.eclipse.wst.common.project.facet.core, - org.eclipse.wst.validation -Export-Package: org.eclipse.jpt.core.tests.extension.resource;x-friends:="org.eclipse.jpt.ui.tests,org.eclipse.jpt.core.tests" diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/about.html b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/about.html deleted file mode 100644 index be534ba44f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/about.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - -About - - - - - -

About This Content

- -

May 02, 2008

- -

License

- -

The Eclipse Foundation makes available all content in this plug-in -("Content"). Unless otherwise indicated below, the Content is provided to you -under the terms and conditions of the Eclipse Public License Version 1.0 -("EPL"). A copy of the EPL is available at -http://www.eclipse.org/org/documents/epl-v10.php. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the -Content is being redistributed by another party ("Redistributor") and different -terms and conditions may apply to your use of any object code in the Content. -Check the Redistributor's license that was provided with the Content. If no such -license exists, contact the Redistributor. Unless otherwise indicated below, the -terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at -http://www.eclipse.org/.

- - - diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/build.properties b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/build.properties deleted file mode 100644 index f33b241f91..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/build.properties +++ /dev/null @@ -1,19 +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 -################################################################################ -javacSource=1.5 -javacTarget=1.5 -source.. = src/ -output.. = bin/ -bin.includes = .,\ - META-INF/,\ - plugin.xml,\ - plugin.properties,\ - about.html -jars.compile.order = . diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.properties b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.properties deleted file mode 100644 index 0558789278..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2009 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 -################################################################################ -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName = Dali Java Persistence Tools - Extension Tests -providerName = Eclipse Web Tools Platform diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.xml b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.xml deleted file mode 100644 index c0577cb922..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/plugin.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/ExtensionTestPlugin.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/ExtensionTestPlugin.java deleted file mode 100644 index 47ff993fb2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/ExtensionTestPlugin.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.core.runtime.Plugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class ExtensionTestPlugin extends Plugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.jpt.core.tests.extension.resource"; //$NON-NLS-1$ - - // The shared instance - private static ExtensionTestPlugin plugin; - - /** - * The constructor - */ - public ExtensionTestPlugin() { - super(); - } - - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - @Override - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static ExtensionTestPlugin getDefault() { - return plugin; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMapping.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMapping.java deleted file mode 100644 index 35f3a4f085..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMapping.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaAttributeMapping; -import org.eclipse.jpt.core.resource.java.Annotation; - -public class JavaTestAttributeMapping - extends AbstractJavaAttributeMapping -{ - public static final String TEST_ATTRIBUTE_MAPPING_KEY = "testAttribute"; //$NON-NLS-1$ - public static final String TEST_ATTRIBUTE_ANNOTATION_NAME = "test.TestAttribute"; //$NON-NLS-1$ - - - public JavaTestAttributeMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return JavaTestAttributeMapping.TEST_ATTRIBUTE_MAPPING_KEY; - } - - @Override - protected String getAnnotationName() { - return JavaTestAttributeMapping.TEST_ATTRIBUTE_ANNOTATION_NAME; - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMappingDefinition.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMappingDefinition.java deleted file mode 100644 index acc2424667..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestAttributeMappingDefinition.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; - -public class JavaTestAttributeMappingDefinition - implements JavaAttributeMappingDefinition -{ - // singleton - private static final JavaAttributeMappingDefinition INSTANCE = new JavaTestAttributeMappingDefinition(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaTestAttributeMappingDefinition() { - super(); - } - - public String getKey() { - return JavaTestAttributeMapping.TEST_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return JavaTestAttributeMapping.TEST_ATTRIBUTE_ANNOTATION_NAME; - } - - public boolean isSpecified(JavaPersistentAttribute persistentAttribute) { - return persistentAttribute.getResourcePersistentAttribute().getAnnotation(this.getAnnotationName()) != null; - } - - public Iterable getSupportingAnnotationNames() { - return EmptyIterable.instance(); - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute persistentAttribute, JpaFactory factory) { - return ((TestJpaFactory) factory).buildJavaTestAttributeMapping(persistentAttribute); - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMapping.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMapping.java deleted file mode 100644 index 84e59367bd..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMapping.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaTypeMapping; -import org.eclipse.jpt.core.resource.java.Annotation; - -public class JavaTestTypeMapping - extends AbstractJavaTypeMapping -{ - public static final String TEST_TYPE_MAPPING_KEY = "test"; //$NON-NLS-1$ - public static final String TEST_TYPE_ANNOTATION_NAME = "test.Test"; //$NON-NLS-1$ - - - public JavaTestTypeMapping(JavaPersistentType parent) { - super(parent, null); - } - - public String getKey() { - return TEST_TYPE_MAPPING_KEY; - } - - public JavaPersistentType getIdClass() { - return null; - } - - public boolean isMapped() { - return true; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMappingDefinition.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMappingDefinition.java deleted file mode 100644 index d33e0d7157..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/JavaTestTypeMappingDefinition.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.resource.java.Annotation; - -public class JavaTestTypeMappingDefinition - implements JavaTypeMappingDefinition -{ - // singleton - private static final JavaTestTypeMappingDefinition INSTANCE = new JavaTestTypeMappingDefinition(); - - /** - * Return the singleton - */ - public static JavaTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private JavaTestTypeMappingDefinition() { - super(); - } - - public String getKey() { - return JavaTestTypeMapping.TEST_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return JavaTestTypeMapping.TEST_TYPE_ANNOTATION_NAME; - } - - public Iterable getSupportingAnnotationNames() { - return EmptyIterable.instance(); - } - - public JavaTestTypeMapping buildMapping(JavaPersistentType persistentType, Annotation annotation, JpaFactory factory) { - return ((TestJpaFactory) factory).buildJavaTestTypeMapping(persistentType); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaBasicMapping.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaBasicMapping.java deleted file mode 100644 index b1f50dd96c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaBasicMapping.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaBasicMapping; - -public class TestJavaBasicMapping - extends AbstractJavaBasicMapping -{ - public TestJavaBasicMapping(JavaPersistentAttribute parent) { - super(parent); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java deleted file mode 100644 index e11e627d1a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity; -import org.eclipse.jpt.core.jpa2.context.java.JavaCacheable2_0; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; - -public class TestJavaEntity - extends AbstractJavaEntity -{ - protected TestJavaEntity(JavaPersistentType parent, EntityAnnotation mappingAnnotation) { - super(parent, mappingAnnotation); - } - - public JavaCacheable2_0 getCacheable() { - return null; - } - - public boolean calculateDefaultCacheable() { - return false; - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaFactory.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaFactory.java deleted file mode 100644 index f40bdeaf5d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.AbstractJpaFactory; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; - -public class TestJpaFactory - extends AbstractJpaFactory -{ - @Override - public JavaEntity buildJavaEntity(JavaPersistentType parent, EntityAnnotation entityAnnotation) { - return new TestJavaEntity(parent, entityAnnotation); - } - - @Override - public JavaBasicMapping buildJavaBasicMapping(JavaPersistentAttribute parent) { - return new TestJavaBasicMapping(parent); - } - - public JavaTestTypeMapping buildJavaTestTypeMapping(JavaPersistentType parent) { - return new JavaTestTypeMapping(parent); - } - - public JavaTestAttributeMapping buildJavaTestAttributeMapping(JavaPersistentAttribute parent) { - return new JavaTestAttributeMapping(parent); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformFactory.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformFactory.java deleted file mode 100644 index b49643d527..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaPlatformFactory; -import org.eclipse.jpt.core.JpaPlatformVariation; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider; -import org.eclipse.jpt.core.internal.GenericJpaPlatform; -import org.eclipse.jpt.core.internal.GenericJpaPlatformFactory.SimpleVersion; - -/** - * All the state in the JPA platform should be "static" (i.e. unchanging once - * it is initialized). - */ -@SuppressWarnings("nls") -public class TestJpaPlatformFactory - implements JpaPlatformFactory -{ - /** - * zero-argument constructor - */ - public TestJpaPlatformFactory() { - super(); - } - - - public JpaPlatform buildJpaPlatform(String id) { - return new GenericJpaPlatform( - id, - buildJpaVersion(), - new TestJpaFactory(), - new GenericJpaAnnotationProvider(GenericJpaAnnotationDefinitionProvider.instance()), - TestJpaPlatformProvider.instance(), - buildJpaPlatformVariation()); - } - - private JpaPlatform.Version buildJpaVersion() { - return new SimpleVersion(JpaFacet.VERSION_1_0.getVersionString()) { - @Override - public String getVersion() { - return "BOOOYAH!"; - } - }; - } - - protected JpaPlatformVariation buildJpaPlatformVariation() { - return new JpaPlatformVariation() { - public Supported getTablePerConcreteClassInheritanceIsSupported() { - return Supported.MAYBE; - } - public boolean isJoinTableOverridable() { - return false; - } - }; - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformProvider.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformProvider.java deleted file mode 100644 index 318a74ab87..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformProvider.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import java.util.ArrayList; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.JptResourceType; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.core.JpaPlatformProvider; -import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.ResourceDefinition; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; -import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition; -import org.eclipse.jpt.core.internal.AbstractJpaPlatformProvider; -import org.eclipse.jpt.core.internal.JarResourceModelProvider; -import org.eclipse.jpt.core.internal.JavaResourceModelProvider; -import org.eclipse.jpt.core.internal.OrmResourceModelProvider; -import org.eclipse.jpt.core.internal.PersistenceResourceModelProvider; -import org.eclipse.jpt.core.internal.context.java.JavaBasicMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddableDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaEntityDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaIdMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaManyToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaManyToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaMappedSuperclassDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaOneToManyMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaOneToOneMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaTransientMappingDefinition; -import org.eclipse.jpt.core.internal.context.java.JavaVersionMappingDefinition; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmXmlDefinition; -import org.eclipse.jpt.core.internal.jpa1.context.persistence.GenericPersistenceXmlDefinition; - -public class TestJpaPlatformProvider extends AbstractJpaPlatformProvider -{ - public static final String ID = "core.testJpaPlatform"; //$NON-NLS-1$ - - // singleton - private static final JpaPlatformProvider INSTANCE = new TestJpaPlatformProvider(); - - - /** - * Return the singleton. - */ - public static JpaPlatformProvider instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private TestJpaPlatformProvider() { - super(); - } - - - // ********** resource models ********** - - public JptResourceType getMostRecentSupportedResourceType(IContentType contentType) { - if (contentType.equals(JptCommonCorePlugin.JAVA_SOURCE_CONTENT_TYPE)) { - return JptCommonCorePlugin.JAVA_SOURCE_RESOURCE_TYPE; - } - else if (contentType.equals(JptCommonCorePlugin.JAR_CONTENT_TYPE)) { - return JptCommonCorePlugin.JAR_RESOURCE_TYPE; - } - else if (contentType.equals(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE)) { - return JptCorePlugin.PERSISTENCE_XML_1_0_RESOURCE_TYPE; - } - else if (contentType.equals(JptCorePlugin.ORM_XML_CONTENT_TYPE)) { - return JptCorePlugin.ORM_XML_1_0_RESOURCE_TYPE; - } - else { - throw new IllegalArgumentException(contentType.toString()); - } - } - - @Override - protected void addResourceModelProvidersTo(ArrayList providers) { - CollectionTools.addAll(providers, RESOURCE_MODEL_PROVIDERS); - } - - // order should not be important here - protected static final JpaResourceModelProvider[] RESOURCE_MODEL_PROVIDERS = new JpaResourceModelProvider[] { - JavaResourceModelProvider.instance(), - JarResourceModelProvider.instance(), - PersistenceResourceModelProvider.instance(), - OrmResourceModelProvider.instance() - }; - - - // ********** Java type mappings ********** - - @Override - protected void addJavaTypeMappingDefinitionsTo(ArrayList definitions) { - CollectionTools.addAll(definitions, JAVA_TYPE_MAPPING_DEFINITIONS); - } - - // order matches that used by the Reference Implementation (EclipseLink) - protected static final JavaTypeMappingDefinition[] JAVA_TYPE_MAPPING_DEFINITIONS = new JavaTypeMappingDefinition[] { - JavaEntityDefinition.instance(), - JavaEmbeddableDefinition.instance(), - JavaMappedSuperclassDefinition.instance(), - JavaTestTypeMappingDefinition.instance() // added - }; - - - // ********** Java attribute mappings ********** - - @Override - protected void addDefaultJavaAttributeMappingDefinitionsTo(ArrayList definitions) { - CollectionTools.addAll(definitions, DEFAULT_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS); - } - - // order matches that used by the Reference Implementation (EclipseLink) - protected static final DefaultJavaAttributeMappingDefinition[] DEFAULT_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS = new DefaultJavaAttributeMappingDefinition[] { - JavaEmbeddedMappingDefinition.instance(), - JavaBasicMappingDefinition.instance() - }; - @Override - protected void addSpecifiedJavaAttributeMappingDefinitionsTo(ArrayList definitions) { - CollectionTools.addAll(definitions, SPECIFIED_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS); - } - - // order matches that used by the Reference Implementation (EclipseLink) - protected static final JavaAttributeMappingDefinition[] SPECIFIED_JAVA_ATTRIBUTE_MAPPING_DEFINITIONS = new JavaAttributeMappingDefinition[] { - JavaTransientMappingDefinition.instance(), - JavaIdMappingDefinition.instance(), - JavaVersionMappingDefinition.instance(), - JavaBasicMappingDefinition.instance(), - JavaEmbeddedMappingDefinition.instance(), - JavaEmbeddedIdMappingDefinition.instance(), - JavaManyToManyMappingDefinition.instance(), - JavaManyToOneMappingDefinition.instance(), - JavaOneToManyMappingDefinition.instance(), - JavaOneToOneMappingDefinition.instance(), - JavaTestAttributeMappingDefinition.instance() // added - }; - - - // ********** resource definitions ********** - - @Override - protected void addResourceDefinitionsTo(ArrayList definitions) { - CollectionTools.addAll(definitions, RESOURCE_DEFINITIONS); - } - - protected static final ResourceDefinition[] RESOURCE_DEFINITIONS = new ResourceDefinition[] { - GenericPersistenceXmlDefinition.instance(), - GenericOrmXmlDefinition.instance() - }; -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUiFactory.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUiFactory.java deleted file mode 100644 index c120dd3546..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUiFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.extension.resource; - -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.JpaPlatformUiFactory; -import org.eclipse.jpt.ui.internal.GenericJpaPlatformUiProvider; -import org.eclipse.jpt.ui.internal.platform.generic.GenericJpaPlatformUi; -import org.eclipse.jpt.ui.internal.platform.generic.GenericNavigatorProvider; - -public class TestJpaPlatformUiFactory implements JpaPlatformUiFactory -{ - - /** - * Zero arg constructor for extension point - */ - public TestJpaPlatformUiFactory() { - super(); - } - - public JpaPlatformUi buildJpaPlatformUi() { - return new GenericJpaPlatformUi( - new GenericNavigatorProvider(), - GenericJpaPlatformUiProvider.instance()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.classpath b/jpa/tests/org.eclipse.jpt.core.tests/.classpath deleted file mode 100644 index 10f7758f49..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.classpath +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.cvsignore b/jpa/tests/org.eclipse.jpt.core.tests/.cvsignore deleted file mode 100644 index c4ba612bad..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -bin -@dot -temp.folder -build.xml -javaCompiler...args \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.project b/jpa/tests/org.eclipse.jpt.core.tests/.project index 08395a8e86..5652fd45d3 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/.project +++ b/jpa/tests/org.eclipse.jpt.core.tests/.project @@ -1,28 +1,5 @@ org.eclipse.jpt.core.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - + renamed to rg.eclipse.jpt.jpa.core.tests diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index eb348782fa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Jan 15 11:10:55 EST 2008 -eclipse.preferences.version=1 -encoding/=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.jdt.core.prefs b/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index a2f6604d54..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Sun May 27 14:58:31 EDT 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF deleted file mode 100644 index d3a4d59378..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,45 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.core.tests;singleton:=true -Bundle-Version: 2.4.0.qualifier -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)", - org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)", - org.eclipse.jem.util;bundle-version="[2.0.100,3.0.0)", - org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)", - org.eclipse.jpt.common.core.tests;bundle-version="[1.0.0,2.0.0)", - org.eclipse.jpt.core;bundle-version="[2.0.0,3.0.0)", - org.eclipse.jpt.core.tests.extension.resource;bundle-version="[2.0.0,3.0.0)", - org.eclipse.jpt.jpa.db;bundle-version="[1.2.0,2.0.0)", - org.eclipse.jpt.common.utility;bundle-version="[1.2.0,2.0.0)", - org.eclipse.jpt.common.utility.tests;bundle-version="[1.2.0,2.0.0)", - org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.modulecore;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)", - org.junit;bundle-version="3.8.0" -Export-Package: org.eclipse.jpt.core.tests, - org.eclipse.jpt.core.tests.internal;x-friends:="org.eclipse.jpt.ui.tests", - org.eclipse.jpt.core.tests.internal.context;x-internal:=true, - org.eclipse.jpt.core.tests.internal.context.java;x-internal:=true, - org.eclipse.jpt.core.tests.internal.context.orm;x-internal:=true, - org.eclipse.jpt.core.tests.internal.context.persistence;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context.java;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context.orm;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context.persistence;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.resource.java;x-internal:=true, - org.eclipse.jpt.core.tests.internal.model;x-internal:=true, - org.eclipse.jpt.core.tests.internal.platform;x-internal:=true, - org.eclipse.jpt.core.tests.internal.projects;x-friends:="org.eclipse.jpt.ui.tests", - org.eclipse.jpt.core.tests.internal.resource;x-internal:=true, - org.eclipse.jpt.core.tests.internal.resource.java;x-internal:=true -Bundle-Activator: org.eclipse.jpt.core.tests.JptCoreTestsPlugin -Bundle-ActivationPolicy: lazy diff --git a/jpa/tests/org.eclipse.jpt.core.tests/about.html b/jpa/tests/org.eclipse.jpt.core.tests/about.html deleted file mode 100644 index be534ba44f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/about.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - -About - - - - - -

About This Content

- -

May 02, 2008

- -

License

- -

The Eclipse Foundation makes available all content in this plug-in -("Content"). Unless otherwise indicated below, the Content is provided to you -under the terms and conditions of the Eclipse Public License Version 1.0 -("EPL"). A copy of the EPL is available at -http://www.eclipse.org/org/documents/epl-v10.php. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the -Content is being redistributed by another party ("Redistributor") and different -terms and conditions may apply to your use of any object code in the Content. -Check the Redistributor's license that was provided with the Content. If no such -license exists, contact the Redistributor. Unless otherwise indicated below, the -terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at -http://www.eclipse.org/.

- - - diff --git a/jpa/tests/org.eclipse.jpt.core.tests/build.properties b/jpa/tests/org.eclipse.jpt.core.tests/build.properties deleted file mode 100644 index 96de1ee6d2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/build.properties +++ /dev/null @@ -1,18 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 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 -################################################################################ -javacSource = 1.5 -javacTarget = 1.5 -bin.includes = .,\ - META-INF/,\ - about.html,\ - test.xml,\ - plugin.properties -source.. = src/ -output.. = bin/ diff --git a/jpa/tests/org.eclipse.jpt.core.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.core.tests/plugin.properties deleted file mode 100644 index 113453a4d6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/plugin.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 2009 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 -################################################################################ -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName=Dali Java Persistence Tools - Core Tests -providerName=Eclipse Web Tools Platform diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java deleted file mode 100644 index 3f78a62d44..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.core.JpaProjectManager; -import org.eclipse.jpt.core.JptCorePlugin; -import org.osgi.framework.BundleContext; - -/** - * Configure the core for testing:
    - *
  • handle events synchronously - *
  • do not flush preferences - *
- */ -@SuppressWarnings("nls") -public class JptCoreTestsPlugin - extends Plugin -{ - - private static JptCoreTestsPlugin INSTANCE; - - public static JptCoreTestsPlugin instance() { - return INSTANCE; - } - - - // ********** plug-in implementation ********** - - public JptCoreTestsPlugin() { - super(); - if (INSTANCE != null) { - throw new IllegalStateException(); - } - // this convention is *wack*... ~bjv - INSTANCE = this; - } - - - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - JpaProjectManager jpaProjectManager = JptCorePlugin.getJpaProjectManager(); - ReflectionTools.executeMethod(jpaProjectManager, "handleEventsSynchronously"); - ReflectionTools.executeStaticMethod(JptCorePlugin.class, "doNotFlushPreferences"); - } - - @Override - public void stop(BundleContext context) throws Exception { - super.stop(context); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/MiscTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/MiscTests.java deleted file mode 100644 index 72c9ad75ac..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/MiscTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.ILock; -import org.eclipse.core.runtime.jobs.Job; - -@SuppressWarnings("nls") -public class MiscTests extends TestCase { - - public MiscTests(String name) { - super(name); - } - - /* - * - */ - public void testJobsAndLocks() throws Exception { - ILock lock = Job.getJobManager().newLock(); - Job testJob = new TestJob(lock); - testJob.schedule(); - } - - class TestJob extends Job { - private final ILock lock; - TestJob(ILock lock) { - super("test job"); - this.lock = lock; - } - @Override - protected IStatus run(IProgressMonitor monitor) { - this.run(); - return Status.OK_STATUS; - } - private void run() { - try { - this.lock.acquire(); - MiscTests.sleep(100); - } finally { - this.lock.release(); - } - } - } - - static void sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java deleted file mode 100644 index 7c085cb3fb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal; - -import java.io.File; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.context.JptCoreContextModelTests; -import org.eclipse.jpt.core.tests.internal.model.JptCoreModelTests; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.core.tests.internal.resource.JptCoreResourceModelTests; - -/** - * decentralize test creation code - * - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar= - */ -@SuppressWarnings("nls") -public class JptCoreTests { - private static final String JPA_JAR_PROPERTY = TestJpaProject.JPA_JAR_NAME_SYSTEM_PROPERTY; - - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreTests.class.getPackage().getName()); - suite.addTest(JptCoreModelTests.suite()); - suite.addTest(JptCoreResourceModelTests.suite()); - suite.addTest(JptCoreContextModelTests.suite()); - return suite; - } - - public static boolean requiredJarsExists() { - return jpaJarPropertyExists() && jpaJarFileExists(); - } - - public static boolean jpaJarPropertyExists() { - return getSystemProperty(JPA_JAR_PROPERTY) != null; - } - - public static boolean jpaJarFileExists() { - return (new File(getSystemProperty(JPA_JAR_PROPERTY))).exists(); - } - - public static String buildMissingJarErrorMessage() { - if( ! jpaJarPropertyExists()) { - return errorMissingProperty(JPA_JAR_PROPERTY); - } - return errorJarFileDoesNotExist(getSystemProperty(JPA_JAR_PROPERTY)); - } - - /*********** private **********/ - private static String errorMissingProperty(String propertyName) { - return "missing Java system property: \"" + propertyName + "\""; - } - - private static String errorJarFileDoesNotExist(String propertyValue) { - return "JAR file doesn't exist: \"" + propertyValue + "\""; - } - - private static String getSystemProperty(String propertyName) { - return System.getProperty(propertyName); - } - - private JptCoreTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java deleted file mode 100644 index 2281a019c7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.MappingFile; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider; -import org.eclipse.jpt.core.platform.GenericPlatform; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; - -@SuppressWarnings("nls") -public abstract class ContextModelTestCase extends AnnotationTestCase -{ - protected static final String BASE_PROJECT_NAME = "ContextModelTestProject"; - - protected JpaXmlResource persistenceXmlResource; - - protected JpaXmlResource ormXmlResource; - - - protected ContextModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.persistenceXmlResource = getJpaProject().getPersistenceXmlResource(); - this.ormXmlResource = getJpaProject().getDefaultOrmXmlResource(); - this.waitForWorkspaceJobsToFinish(); - } - - @Override - protected void tearDown() throws Exception { - this.persistenceXmlResource = null; - this.ormXmlResource = null; - JptCorePlugin.getWorkspacePreferences().clear(); - this.waitForWorkspaceJobsToFinish(); - super.tearDown(); - } - - @Override - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return buildJpaProject(BASE_PROJECT_NAME, autoBuild, buildJpaConfigDataModel()); - } - - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) - throws Exception { - return TestJpaProject.buildJpaProject(projectName, autoBuild, jpaConfig); - } - - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider()); - // default facet version is 2.0 - most tests use 1.0 - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_1_0.getVersionString()); - // most tests use the basic generic platform - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_1_0); - // most tests do use an orm.xml - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - protected JpaProject getJpaProject() { - return getJavaProject().getJpaProject(); - } - - protected void waitForWorkspaceJobsToFinish() throws InterruptedException { - // This job will not start running until all the other workspace jobs are done - Job waitJob = new Job("Wait job") { - @Override - protected IStatus run(IProgressMonitor monitor) { - return Status.OK_STATUS; - } - }; - waitJob.setRule(ResourcesPlugin.getWorkspace().getRoot()); - waitJob.schedule(); - waitJob.join(); - } - - protected JpaXmlResource getPersistenceXmlResource() { - return this.persistenceXmlResource; - } - - protected JpaXmlResource getOrmXmlResource() { - return this.ormXmlResource; - } - - /** - * It's nice to be able to call this method from the debugger, - * to force the XML files to be written out so you can see their current state. - */ - protected void saveXmlFiles() { - try { - this.saveXmlFiles_(); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - protected void saveXmlFiles_() throws Exception { - this.persistenceXmlResource.saveIfNecessary(); - this.ormXmlResource.saveIfNecessary(); - } - - protected XmlEntityMappings getXmlEntityMappings() { - return (XmlEntityMappings) getOrmXmlResource().getRootObject(); - } - - protected XmlPersistence getXmlPersistence() { - return (XmlPersistence) getPersistenceXmlResource().getRootObject(); - } - - protected MappingFile getMappingFile() { - return this.getPersistenceUnit().mappingFileRefs().next().getMappingFile(); - } - - protected EntityMappings getEntityMappings() { - MappingFile mappingFile = this.getMappingFile(); - return (mappingFile == null) ? null : (EntityMappings) mappingFile.getRoot(); - } - - protected XmlPersistenceUnit getXmlPersistenceUnit() { - return getXmlPersistence().getPersistenceUnits().get(0); - } - - protected PersistenceUnit getPersistenceUnit() { - return getRootContextNode().getPersistenceXml().getPersistence().persistenceUnits().next(); - } - - protected ClassRef getSpecifiedClassRef() { - return getPersistenceUnit().specifiedClassRefs().next(); - } - - protected JavaPersistentType getJavaPersistentType() { - return getSpecifiedClassRef().getJavaPersistentType(); - } - - protected JavaEntity getJavaEntity() { - return (JavaEntity) getJavaPersistentType().getMapping(); - } - - protected void addXmlClassRef(String className) { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass(className); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - } - - protected void removeXmlClassRef(String className) { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - XmlJavaClassRef xmlJavaClassRefToRemove = null; - for (XmlJavaClassRef xmlJavaClassRef : xmlPersistenceUnit.getClasses()) { - if (xmlJavaClassRef.getJavaClass().equals(className)) { - xmlJavaClassRefToRemove = xmlJavaClassRef; - } - } - if (xmlJavaClassRefToRemove == null) { - throw new IllegalArgumentException(); - } - xmlPersistenceUnit.getClasses().remove(xmlJavaClassRefToRemove); - } - - protected void addXmlMappingFileRef(String fileName) { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName(fileName); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - } - - protected JpaRootContextNode getRootContextNode() { - return getJavaProject().getJpaProject().getRootContextNode(); - } - - @Override - protected TestJpaProject getJavaProject() { - return (TestJpaProject) super.getJavaProject(); - } - - protected void deleteResource(Resource resource) throws CoreException { - WorkbenchResourceHelper.deleteResource(resource); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java deleted file mode 100644 index bd566003bb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java +++ /dev/null @@ -1,411 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; - -@SuppressWarnings("nls") -public class JpaFileTests extends ContextModelTestCase -{ - public JpaFileTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - public void testGetRootStructureNode() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - //verify the mapping file reference "wins" as the root structure node when both - //persistence.xml tag and mapping file tag exist for a particulary java class - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - getEntityMappings().removePersistentType(ormPersistentType); - - assertEquals(getJavaEntity().getPersistentType(), javaJpaFile.rootStructureNodes().next()); - - ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - } - - public void testEntityMappingsRootStructureNodeRemoved() throws Exception { - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) ormXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testImpliedEntityMappingsRootStructureNodeRemoved() throws Exception { - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertNull(getPersistenceUnit().getImpliedMappingFileRef()); - - getXmlPersistenceUnit().getMappingFiles().remove(0); - assertNotNull(getPersistenceUnit().getImpliedMappingFileRef()); - assertEquals(getPersistenceUnit().getImpliedMappingFileRef().getMappingFile().getRoot(), ormXmlJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) ormXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testEntityMappingsRootStructureNodeRemovedFromResourceModel() throws Exception { - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - getOrmXmlResource().getContents().remove(getOrmXmlResource().getRootObject()); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdatePersistenceRootStructureNodePersistenceRemoved() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateOrmJavaRootStructureNodePersistenceRemoved() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateJavaRootStructureNodePersistenceRemoved() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testPersistenceRootStructureNodeRemovedFromResourceModel() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - getRootContextNode().getPersistenceXml().getPersistence(); - assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next()); - - getPersistenceXmlResource().getContents().remove(getXmlPersistence()); - - assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateOrmJavaRootStructureNodePersistenceXmlRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - getPersistenceXmlResource().getContents().remove(getXmlPersistence()); - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateJavaRootStructureNodePersistenceXmlRemoved() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - getPersistenceXmlResource().getContents().remove(getXmlPersistence()); - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testOrmJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof OrmPersistentType); - - - getEntityMappings().removePersistentType(0); - - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof ClassRef); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - } - - public void testOrmJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof OrmPersistentType); - - getXmlEntityMappings().getEntities().remove(0); - - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof ClassRef); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - } - - public void testJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(getEntityMappings().getPersistenceUnit().specifiedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - - getEntityMappings().getPersistenceUnit().removeSpecifiedClassRef(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception { - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = getJavaPersistentType(); - Iterator rootStructureNodes = javaJpaFile.rootStructureNodes(); - JpaStructureNode rootStructureNode = rootStructureNodes.next(); - assertEquals(javaPersistentType, rootStructureNode); - assertEquals(getEntityMappings().getPersistenceUnit().specifiedClassRefs().next(), rootStructureNode.getParent()); - assertFalse(rootStructureNodes.hasNext()); - - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testImpliedJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - getJpaProject().setDiscoversAnnotatedClasses(true); - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = getPersistenceUnit().impliedClassRefs().next().getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - javaPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testJavaRootStructureNodesEntityMappingsRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getOrmXmlResource().getContents().remove(getXmlEntityMappings()); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaRootStructureNodesPersistenceUnitRemovedFromResourceModel() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getXmlPersistence().getPersistenceUnits().remove(0); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - assertEquals(0, javaJpaFile.rootStructureNodesSize()); - } - - public void testJavaRootStructureNodesPersistenceUnitRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getJpaProject().getRootContextNode().getPersistenceXml().getPersistence().removePersistenceUnit(0); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - assertEquals(0, javaJpaFile.rootStructureNodesSize()); - } - - public void testJavaRootStructureNodesOrmPersistentTypeRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getEntityMappings().removePersistentType(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaRootStructureNodesOrmTypeMappingMorphed() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - ormPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - javaPersistentType = getEntityMappings().getPersistentTypes().iterator().next().getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getEntityMappings().removePersistentType(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testUpdateOrmJavaRootStructureNodeMappingFileRefChanged() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - MappingFileRef mappingFileRef = getPersistenceUnit().mappingFileRefs().next(); - mappingFileRef.setFileName("foo"); - - ormPersistentType = ((EntityMappings) getPersistenceUnit().getImpliedMappingFileRef().getMappingFile().getRoot()).getPersistentTypes().iterator().next(); - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - IFile file = getPersistenceXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertEquals(1, ormXmlJpaFile.rootStructureNodesSize()); - } - - public void testUpdateJavaRootStructureNodeMappingFileRefChanged() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - MappingFileRef mappingFileRef = getPersistenceUnit().mappingFileRefs().next(); - mappingFileRef.setFileName("foo"); - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - } - - - public void testUpdateJavaRootStrucutreNodeDeleteOrmResource() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - - deleteResource(getOrmXmlResource()); - - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - //TODO test rootStructureNodes with a static inner class -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaProjectTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaProjectTests.java deleted file mode 100644 index 8d447f591a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaProjectTests.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context; - -import junit.framework.TestCase; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; -import org.eclipse.jpt.core.internal.operations.PersistenceFileCreationDataModelProvider; -import org.eclipse.jpt.core.platform.GenericPlatform; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class JpaProjectTests extends TestCase -{ - static final String BASE_PROJECT_NAME = JpaProjectTests.class.getSimpleName(); - - TestJpaProject jpaProject; - - - public JpaProjectTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.jpaProject = TestJpaProject.buildJpaProject(BASE_PROJECT_NAME, false, buildJpaConfigDataModel()); // false = no auto-build - } - - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider()); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_1_0.getVersionString()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_1_0); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - @Override - protected void tearDown() throws Exception { - this.jpaProject.getProject().delete(true, true, null); - this.jpaProject = null; - super.tearDown(); - } - - protected JpaProject getJpaProject() { - return this.jpaProject.getJpaProject(); - } - - public void testGetPersistenceXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getPersistenceXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/persistence.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the persistence.xml file and verify it is not returned from getPersistenceXmlResource() - resource.delete(null); - resource = this.getJpaProject().getPersistenceXmlResource(); - assertNull(resource); - - //add the persistence.xml file back - createPersistenceXmlFile(); - resource = this.getJpaProject().getPersistenceXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/persistence.xml", resource.getFile().getProjectRelativePath().toString()); - } - - private void createPersistenceXmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new PersistenceFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.getDefaultOperation().execute(null, null); - } - - public void testGetDefaultOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - //add the default orm.xml file back - createDefaultOrmXmlFile(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - } - - private void createDefaultOrmXmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.getDefaultOperation().execute(null, null); - } - - private void createOrmXmlFile(String fileName) throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, fileName); - config.getDefaultOperation().execute(null, null); - } - - public void testGetMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH); - assertNull(resource); - - //add the orm.xml file back - createDefaultOrmXmlFile(); - resource = this.getJpaProject().getMappingFileXmlResource(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - } - - public void testGetMappingFileResourceDifferentlyName() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //create the orm2.xml file - createOrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm2.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //add the orm2.xml file back - createOrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java deleted file mode 100644 index 87b709a962..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.JptCoreTests; -import org.eclipse.jpt.core.tests.internal.context.java.JptCoreContextJavaModelTests; -import org.eclipse.jpt.core.tests.internal.context.orm.JptCoreOrmContextModelTests; -import org.eclipse.jpt.core.tests.internal.context.persistence.JptCorePersistenceContextModelTests; -import org.eclipse.jpt.core.tests.internal.jpa2.context.java.Generic2_0JavaContextModelTests; -import org.eclipse.jpt.core.tests.internal.jpa2.context.orm.Generic2_0OrmContextModelTests; -import org.eclipse.jpt.core.tests.internal.jpa2.context.persistence.Generic2_0PersistenceContextModelTests; - -/** - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar= - */ -public class JptCoreContextModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreContextModelTests.class.getPackage().getName()); - - if (JptCoreTests.requiredJarsExists()) { - suite.addTestSuite(JpaProjectTests.class); - suite.addTestSuite(JpaFileTests.class); - suite.addTest(JptCorePersistenceContextModelTests.suite()); - suite.addTest(JptCoreOrmContextModelTests.suite()); - suite.addTest(JptCoreContextJavaModelTests.suite()); - suite.addTest(Generic2_0JavaContextModelTests.suite()); - suite.addTest(Generic2_0OrmContextModelTests.suite()); - suite.addTest(Generic2_0PersistenceContextModelTests.suite()); - } else { - suite.addTest(TestSuite.warning(JptCoreTests.buildMissingJarErrorMessage())); - } - return suite; - } - - private JptCoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java deleted file mode 100644 index dd01fc337a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaPersistentAttributeTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public GenericJavaPersistentAttributeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals("id", persistentAttribute.getName()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getMapping() instanceof JavaIdMapping); - - persistentAttribute.setMappingKey(null); - assertTrue(persistentAttribute.getMapping() instanceof JavaBasicMapping); - } - - public void testGetSpecifiedMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getMapping() instanceof JavaIdMapping); - - persistentAttribute.setMappingKey(null); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testGetSpecifiedMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - assertNotNull(persistentAttribute.getMapping()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setMappingKey(null); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - } - - public void testDefaultMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - } - - public void testSetSpecifiedMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertTrue(persistentAttribute.getMapping() instanceof JavaEmbeddedMapping); - } - - public void testSetSpecifiedMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertTrue(persistentAttribute.getMapping() instanceof JavaEmbeddedMapping); - } - - public void testSetSpecifiedMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.setPrimaryAnnotation(EmbeddedAnnotation.ANNOTATION_NAME, EmptyIterable.instance()); - this.getJpaProject().synchronizeContextModel(); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.setPrimaryAnnotation(BasicAnnotation.ANNOTATION_NAME, EmptyIterable.instance()); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMapping().getKey()); - } - - public void testGetAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(AccessType.FIELD, persistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, persistentAttribute.getDefaultAccess()); - assertEquals(null, persistentAttribute.getSpecifiedAccess()); - } - - public void testGetAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(AccessType.PROPERTY, persistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, persistentAttribute.getDefaultAccess()); - assertEquals(null, persistentAttribute.getSpecifiedAccess()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java deleted file mode 100644 index 3709c3d7e5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java +++ /dev/null @@ -1,759 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IField; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaPersistentTypeTests extends ContextModelTestCase -{ - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - private ICompilationUnit createTestEntityAnnotatedFieldAndMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubType() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createTestSubTypeWithFieldAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeWithMethodAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - }); - } - - private ICompilationUnit createTestSubTypePersistentExtendsNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild2.java", "AnnotationTestTypeChild2", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends AnnotationTestTypeChild "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public GenericJavaPersistentTypeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, getJavaPersistentType().getName()); - } - - public void testGetAccessNothingAnnotated() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - } - - public void testAccessFieldAndMethodAnnotated() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessInheritance() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance2() throws Exception { - createTestEntityAnnotatedField(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessInheritance3() throws Exception { - createTestEntityAnnotatedField(); - createTestSubTypeWithMethodAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance4() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inherited class having annotations set wins over the default access set on persistence-unit-defaults - public void testAccessInheritancePersistenceUnitDefaultAccess() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlNoAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception { - //xml access set to property, field annotations, JavaPersistentType access is field - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception { - //xml access set to field, property annotations, JavaPersistentType access is property - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - ormPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inheritance wins over entity-mappings specified access - public void testAccessXmlEntityMappingsAccessWithInheritance() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childEntityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - - createTestEntityAnnotatedMethod(); - createTestSubType(); - JavaPersistentType childJavaPersistentType = childEntityPersistentType.getJavaPersistentType(); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, entityPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.PROPERTY, childJavaPersistentType.getAccess()); - } - - public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception { - //xml access set to property, java has field annotations so the access should be field - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - } - - public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception { - //xml access not set, metadata complete set. JavaPersistentType access is property because properties are annotated - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testSuperPersistentType() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testSuperPersistentType2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - //super is not added to the persistenceUnit, but it should still be found - //as the superPersistentType because of impliedClassRefs and changes for bug 190317 - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType javaPersistentType = classRefs.next().getJavaPersistentType(); - - assertNotNull(javaPersistentType.getSuperPersistentType()); - } - - //Entity extends Non-Entity extends Entity - public void testSuperPersistentType3() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testInheritanceHierarchy() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testInheritanceHierarchy2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testGetMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testMappingKeyNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - resourceType.setPrimaryAnnotation(EmbeddableAnnotation.ANNOTATION_NAME, EmptyIterable.instance()); - this.getJpaProject().synchronizeContextModel(); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - resourceType.setPrimaryAnnotation(EntityAnnotation.ANNOTATION_NAME, EmptyIterable.instance()); - this.getJpaProject().synchronizeContextModel(); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testIsMapped() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaPersistentType().isMapped()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertFalse(getJavaPersistentType().isMapped()); - } - - public void testAttributes() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Iterator attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributes2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertEquals("name", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributesSize() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(1, getJavaPersistentType().attributesSize()); - } - - public void testAttributesSize2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, getJavaPersistentType().attributesSize()); - } - - public void testAttributeNamed() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("id"); - - assertEquals("id", attribute.getName()); - assertNull(getJavaPersistentType().getAttributeNamed("name")); - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testAttributeNamed2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("name"); - - assertEquals("name", attribute.getName()); - - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testRenameAttribute() throws Exception { - ICompilationUnit testType = createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute idAttribute = attributes.next(); - JavaPersistentAttribute nameAttribute = attributes.next(); - - - assertEquals("id", idAttribute.getName()); - assertEquals("name", nameAttribute.getName()); - - IField idField = testType.findPrimaryType().getField("id"); - idField.rename("id2", false, null); - - attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute nameAttribute2 = attributes.next(); - JavaPersistentAttribute id2Attribute = attributes.next(); - - assertNotSame(idAttribute, id2Attribute); - assertEquals("id2", id2Attribute.getName()); - assertEquals(nameAttribute, nameAttribute2); - assertEquals("name", nameAttribute2.getName()); - assertFalse(attributes.hasNext()); - } - - public void testSuperPersistentTypeGeneric() throws Exception { - createTestGenericEntity(); - createTestGenericMappedSuperclass(); - - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Entity2"); - - JavaPersistentType javaPersistentType = getJavaPersistentType(); - assertEquals("test.Entity1", javaPersistentType.getName()); - assertNotNull(javaPersistentType.getSuperPersistentType()); - - assertEquals("test.Entity2", javaPersistentType.getSuperPersistentType().getName()); - } - - private void createTestGenericEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 "); - sb.append("extends Entity2 {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericMappedSuperclass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class Entity2 {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity2.java", sourceWriter); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java deleted file mode 100644 index 0382e3ce2c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java +++ /dev/null @@ -1,446 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.ReadOnlyAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaAssociationOverrideTests extends ContextModelTestCase -{ - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE_NAME"; - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(CR); - sb.append(" private AnnotationTestTypeChild address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public JavaAssociationOverrideTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME_ + "AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - VirtualAssociationOverride virtualOverride = overrideContainer.virtualOverrides().next(); - AssociationOverride javaAssociationOverride = virtualOverride.convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - - //set name in the resource model, verify context model updated - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - //set name to null in the resource model - associationOverrideResource.setName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(0, overrideContainer.specifiedOverridesSize()); - assertNull(associationOverrideResource.getName()); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, overrideContainer.specifiedOverridesSize()); - javaAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - assertFalse(overrideContainer.specifiedOverrides().hasNext()); - assertFalse(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).hasNext()); - } - - public void testModifyName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - AssociationOverride javaAssociationOverride = virtualAssociationOverride.convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - - //set name in the context model, verify resource model modified - javaAssociationOverride.setName("foo"); - assertEquals("foo", javaAssociationOverride.getName()); - assertEquals("foo", associationOverrideResource.getName()); - - //set name to null in the context model - javaAssociationOverride.setName(null); - assertNull(javaAssociationOverride.getName()); - associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - assertNull(associationOverrideResource.getName()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaVirtualAssociationOverride virtualOverride = overrideContainer.virtualOverrides().next(); - JavaAssociationOverride specifiedOverride = virtualOverride.convertToSpecified(); - JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideAnnotation = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - JavaJoinColumn joinColumn1 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn1.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideAnnotation.joinColumnAt(0).getName()); - - JavaJoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", associationOverrideAnnotation.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverrideAnnotation.joinColumnAt(1).getName()); - - JavaJoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideAnnotation.joinColumnsSize()); - assertEquals("BAR", associationOverrideAnnotation.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideAnnotation.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideAnnotation.joinColumnAt(2).getName()); - assertEquals("address_id", associationOverrideAnnotation.joinColumnAt(3).getName()); // the old default join column - - assertEquals(4, joiningStrategy.specifiedJoinColumnsSize()); - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn1, joinColumns.next()); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); // the old default join column - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaVirtualAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next(); - JavaAssociationOverride specifiedOverride = javaAssociationOverride.convertToSpecified(); - JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(3, associationOverrideResource.joinColumnsSize()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, associationOverrideResource.joinColumnsSize()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, associationOverrideResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaVirtualAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next(); - JavaAssociationOverride specifiedOverride = javaAssociationOverride.convertToSpecified(); - JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaVirtualAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next(); - JavaAssociationOverride specifiedOverride = javaAssociationOverride.convertToSpecified(); - JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - JoinColumn joinColumn = joinColumns.next(); - assertEquals("address_id", joinColumn.getSpecifiedName()); - assertEquals("id", joinColumn.getSpecifiedReferencedColumnName()); - - - associationOverrideResource.addJoinColumn(0); - associationOverrideResource.addJoinColumn(1); - associationOverrideResource.addJoinColumn(2); - - associationOverrideResource.joinColumnAt(0).setName("FOO"); - associationOverrideResource.joinColumnAt(1).setName("BAR"); - associationOverrideResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("address_id", joinColumns.next().getName()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joiningStrategy.specifiedJoinColumns().hasNext()); - } - - public void testGetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals("FOO", specifiedAssociationOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - specifiedAssociationOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("FOO", associationOverrideResource.getName()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", associationOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next(); - assertTrue(associationOverride.isVirtual()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java deleted file mode 100644 index ed14078c67..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaAttributeOverrideTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE_NAME"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "MY_ATTRIBUTE_OVERRIDE_COLUMN_NAME"; - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - }); - } - - private ICompilationUnit createTestEntityWithAttributeOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public JavaAttributeOverrideTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - attributeOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertEquals("FOO", specifiedAttributeOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - specifiedAttributeOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals("FOO", attributeOverrideResource.getName()); - } - - public void testColumnGetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation columnResource = attributeOverrideResource.getColumn(); - columnResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - - column = overrideContainer.specifiedOverrides().next().getColumn(); - assertEquals("FOO", column.getName()); - } - - public void testColumnSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - column.setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation columnResource = attributeOverrideResource.getColumn(); - - assertEquals("FOO", columnResource.getName()); - - column.setSpecifiedName(null); - - attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - assertNull(attributeOverrideResource.getColumn()); - assertNotNull(specifiedAttributeOverride.getColumn()); - } - - public void testColumnDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedName("FOO"); - - attributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("FOO", attributeOverride.getColumn().getDefaultName()); - } - - public void testColumnDefaultTableName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("AnnotationTestTypeChild", attributeOverride.getColumn().getDefaultTable()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedTable("BAR"); - - attributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("BAR", attributeOverride.getColumn().getDefaultTable()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", attributeOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - ReadOnlyAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next(); - assertTrue(attributeOverride.isVirtual()); - } - - public void testSetColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - JavaVirtualAttributeOverride attributeOverride = overrideContainer.virtualOverrides().next(); - attributeOverride.convertToSpecified().getColumn().setSpecifiedName("FOO"); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals("FOO", attributeOverrideResource.getColumn().getName()); - assertEquals("FOO", overrideContainer.specifiedOverrides().next().getColumn().getSpecifiedName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java deleted file mode 100644 index 17b3e5c0c5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java +++ /dev/null @@ -1,995 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.LobConverter; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.LobAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaBasicMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithBasicMappingFetchOptionalSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch=FetchType.EAGER, optional=false)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithLob() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.LOB); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Lob").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithEnumerated() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Enumerated(EnumType.STRING)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - public JavaBasicMappingTests(String name) { - super(name); - } - - public void testDefaultBasicGetDefaultFetch() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch()); - } - - public void testSpecifiedBasicGetDefaultFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch()); - } - - public void testGetFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(FetchType.EAGER, basicMapping.getFetch()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, basicMapping.getFetch()); - } - - public void testGetSpecifiedFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getSpecifiedFetch()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - } - - public void testGetSpecifiedFetch2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(FetchType.EAGER, basicMapping.getSpecifiedFetch()); - } - - public void testSetSpecifiedFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, basic.getFetch()); - - basicMapping.setSpecifiedFetch(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedFetch2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - createOrmXmlFile(); - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableProperties().next(); - BasicAnnotation basic = (BasicAnnotation) resourceAttribute.getAnnotation(JPA.BASIC); - - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, basic.getFetch()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - assertFalse(basicMapping.isDefault()); - - basicMapping.setSpecifiedFetch(null); - assertNotNull(resourceAttribute.getAnnotation(JPA.BASIC)); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - } - - protected void createOrmXmlFile() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testSetBasicToDefault() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(basicMapping.isDefault()); - - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNotSame(basicMapping, persistentAttribute.getMapping()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertTrue(basicMapping.isDefault()); - assertEquals("FOO", basicMapping.getColumn().getSpecifiedName()); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToDefaultBasic() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(EnumeratedConverter.class); - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getEnumType()); - - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToVersion() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbedded() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbeddedId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToTransient() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - -//TODO assertEquals(FetchType.EAGER, ((IOneToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(OneToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - public void testBasicMorphToManyToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToManyToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - -//TODO assertEquals(FetchType.EAGER, ((IManyToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(ManyToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultBasicGetDefaultOptional() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(true, basicMapping.isDefaultOptional()); - } - - public void testSpecifiedBasicGetDefaultOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(true, basicMapping.isDefaultOptional()); - } - - public void testGetOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(true, basicMapping.isOptional()); - - basicMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(true, basicMapping.isOptional()); - } - - public void testGetSpecifiedOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - } - - public void testGetSpecifiedOptional2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - } - - public void testSetSpecifiedOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - - basicMapping.setSpecifiedOptional(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(Boolean.FALSE, basic.getOptional()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedOptional2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(Boolean.TRUE, basic.getOptional()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - } - - - public void testGetSpecifiedOptionalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - - basic.setOptional(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getMapping()); - - basic.setOptional(Boolean.FALSE); - attributeResource.setPrimaryAnnotation(null, EmptyIterable.instance()); - getJpaProject().synchronizeContextModel(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(true, ((BasicMapping) persistentAttribute.getMapping()).isOptional()); - } - - - public void testIsLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertFalse(basicMapping.getConverter().getType() == LobConverter.class); - } - - public void testIsLob2() throws Exception { - createTestEntityWithLob(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertTrue(basicMapping.getConverter().getType() == LobConverter.class); - } - - public void testSetLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - basicMapping.setConverter(LobConverter.class); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - - basicMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - } - - public void testIsLobUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertFalse(basicMapping.getConverter().getType() == LobConverter.class); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertTrue(basicMapping.getConverter().getType() == LobConverter.class); - - attributeResource.removeAnnotation(LobAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertFalse(basicMapping.getConverter().getType() == LobConverter.class); - } - - public void testDefaultBasicGetDefaultConverter() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getConverter().getType()); - } - - public void testSpecifiedBasicGetDefaultConverter() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getConverter().getType()); - } - - public void testGetEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getConverter().getType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumeratedAnnotation = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) basicMapping.getConverter()).getDefaultEnumType()); - - enumeratedAnnotation.setValue(org.eclipse.jpt.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - } - - public void testGetSpecifiedEnumerated() throws Exception { - createTestEntityWithEnumerated(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - } - - public void testSetSpecifiedEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getConverter().getType()); - - basicMapping.setConverter(EnumeratedConverter.class); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - - assertNotNull(enumerated); - assertEquals(null, enumerated.getValue()); - - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.core.resource.java.EnumType.STRING, enumerated.getValue()); - - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(null); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(enumerated.getValue()); - - basicMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testGetSpecifiedEnumeratedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - enumerated.setValue(org.eclipse.jpt.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - - enumerated.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getMapping()); - } - - public void testGetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(TemporalConverter.class, basicMapping.getConverter().getType()); - } - - public void testGetTemporal2() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(TemporalConverter.class, basicMapping.getConverter().getType()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) basicMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getConverter().getType()); - - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - basicMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalConverter.class, basicMapping.getConverter().getType()); - assertEquals(TemporalType.DATE, ((TemporalConverter) basicMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getConverter().getType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - assertEquals("id", basicMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - assertEquals("foo", basicMapping.getColumn().getName()); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java deleted file mode 100644 index acefab6ac2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java +++ /dev/null @@ -1,321 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaCascade; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaCascadeTests - extends ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - - public JavaCascadeTests(String name) { - super(name); - } - - - public void testUpdateCascadeAll() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isAll()); - assertFalse(annotation.isCascadeAll()); - - //set all in the resource model, verify context model updated - annotation.setCascadeAll(true); - getJpaProject().synchronizeContextModel(); - assertTrue(annotation.isCascadeAll()); - assertTrue(cascade.isAll()); - - //set all to false in the resource model - annotation.setCascadeAll(false); - getJpaProject().synchronizeContextModel(); - assertFalse(annotation.isCascadeAll()); - assertFalse(cascade.isAll()); - } - - public void testModifyCascadeAll() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isAll()); - assertFalse(annotation.isCascadeAll()); - - //set all in the context model, verify resource model updated - cascade.setAll(true); - assertTrue(annotation.isCascadeAll()); - assertTrue(cascade.isAll()); - - //set all to false in the context model - cascade.setAll(false); - assertFalse(annotation.isCascadeAll()); - assertFalse(cascade.isAll()); - } - - public void testUpdateCascadePersist() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isPersist()); - assertFalse(annotation.isCascadePersist()); - - //set persist in the resource model, verify context model updated - annotation.setCascadePersist(true); - getJpaProject().synchronizeContextModel(); - assertTrue(annotation.isCascadePersist()); - assertTrue(cascade.isPersist()); - - //set persist to false in the resource model - annotation.setCascadePersist(false); - getJpaProject().synchronizeContextModel(); - assertFalse(annotation.isCascadePersist()); - assertFalse(cascade.isPersist()); - } - - public void testModifyCascadePersist() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isPersist()); - assertFalse(annotation.isCascadePersist()); - - //set persist in the context model, verify resource model updated - cascade.setPersist(true); - assertTrue(annotation.isCascadePersist()); - assertTrue(cascade.isPersist()); - - //set persist to false in the context model - cascade.setPersist(false); - assertFalse(annotation.isCascadePersist()); - assertFalse(cascade.isPersist()); - } - - public void testUpdateCascadeMerge() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isMerge()); - assertFalse(annotation.isCascadeMerge()); - - //set merge in the resource model, verify context model updated - annotation.setCascadeMerge(true); - getJpaProject().synchronizeContextModel(); - assertTrue(annotation.isCascadeMerge()); - assertTrue(cascade.isMerge()); - - //set merge to false in the resource model - annotation.setCascadeMerge(false); - getJpaProject().synchronizeContextModel(); - assertFalse(annotation.isCascadeMerge()); - assertFalse(cascade.isMerge()); - } - - public void testModifyCascadeMerge() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isMerge()); - assertFalse(annotation.isCascadeMerge()); - - //set merge in the context model, verify resource model updated - cascade.setMerge(true); - assertTrue(annotation.isCascadeMerge()); - assertTrue(cascade.isMerge()); - - //set merge to false in the context model - cascade.setMerge(false); - assertFalse(annotation.isCascadeMerge()); - assertFalse(cascade.isMerge()); - } - - public void testUpdateCascadeRemove() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRemove()); - assertFalse(annotation.isCascadeRemove()); - - //set remove in the resource model, verify context model updated - annotation.setCascadeRemove(true); - getJpaProject().synchronizeContextModel(); - assertTrue(annotation.isCascadeRemove()); - assertTrue(cascade.isRemove()); - - //set remove to false in the resource model - annotation.setCascadeRemove(false); - getJpaProject().synchronizeContextModel(); - assertFalse(annotation.isCascadeRemove()); - assertFalse(cascade.isRemove()); - } - - public void testModifyCascadeRemove() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRemove()); - assertFalse(annotation.isCascadeRemove()); - - //set remove in the context model, verify resource model updated - cascade.setRemove(true); - assertTrue(annotation.isCascadeRemove()); - assertTrue(cascade.isRemove()); - - //set remove to false in the context model - cascade.setRemove(false); - assertFalse(annotation.isCascadeRemove()); - assertFalse(cascade.isRemove()); - } - - public void testUpdateCascadeRefresh() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRefresh()); - assertFalse(annotation.isCascadeRefresh()); - - //set refresh in the resource model, verify context model updated - annotation.setCascadeRefresh(true); - getJpaProject().synchronizeContextModel(); - assertTrue(annotation.isCascadeRefresh()); - assertTrue(cascade.isRefresh()); - - //set refresh to false in the resource model - annotation.setCascadeRefresh(false); - getJpaProject().synchronizeContextModel(); - assertFalse(annotation.isCascadeRefresh()); - assertFalse(cascade.isRefresh()); - } - - public void testModifyCascadeRefresh() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRefresh()); - assertFalse(annotation.isCascadeRefresh()); - - //set refresh in the context model, verify resource model updated - cascade.setRefresh(true); - assertTrue(annotation.isCascadeRefresh()); - assertTrue(cascade.isRefresh()); - - //set refresh to false in the context model - cascade.setRefresh(false); - assertFalse(annotation.isCascadeRefresh()); - assertFalse(cascade.isRefresh()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java deleted file mode 100644 index 7ac5f2294f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java +++ /dev/null @@ -1,843 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.ReadOnlyBaseColumn; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaColumnTests extends ContextModelTestCase -{ - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String TABLE_NAME = "MY_TABLE"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithDefaultBasicColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name=\"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicColumnTableSet() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Column(table=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicColumnColumnDefinitionSet() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Column(columnDefinition=\"" + COLUMN_DEFINITION + "\")"); - } - }); - } - - public JavaColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(basicMapping.getPersistentAttribute().getName(), basicMapping.getColumn().getDefaultName()); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - - basicMapping.getColumn().setSpecifiedName("foo"); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals("id", basicMapping.getColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName(null); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetNameUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - columnAnnotation.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - assertEquals("foo", basicMapping.getColumn().getName()); - - columnAnnotation.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - - - - - - - - - - - - - public void testGetSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetSpecifiedTable() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetDefaultTableSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(((Entity) basicMapping.getTypeMapping()).getName(), basicMapping.getColumn().getDefaultTable()); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - } - - public void testGetDefaultTable() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - - basicMapping.getColumn().setSpecifiedTable("foo"); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - } - - public void testGetTable() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getTable()); - } - - public void testSetSpecifiedTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getTable()); - } - - public void testSetSpecifiedTableNull() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable(null); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetTableUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setTable("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - assertEquals("foo", basicMapping.getColumn().getTable()); - - column.setTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_DEFINITION, basicMapping.getColumn().getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - basicMapping.getColumn().setColumnDefinition(null); - assertNull(column.getColumnDefinition()); - } - - public void testGetColumnDefinitionUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setColumnDefinition("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getColumnDefinition()); - - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, basicMapping.getColumn().getLength()); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength()); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55)); - - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength()); - } - - public void testGetSpecifiedLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - columnAnnotation.setLength(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedLength()); - assertEquals(66, basicMapping.getColumn().getLength()); - - columnAnnotation.setLength(null); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), columnAnnotation.getLength()); - - basicMapping.getColumn().setColumnDefinition(null); - basicMapping.getColumn().setSpecifiedLength(null); - - assertNull(columnAnnotation.getLength()); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetPrecision() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, basicMapping.getColumn().getPrecision()); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getPrecision()); - } - - public void testGetDefaultPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision()); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55)); - - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision()); - } - - public void testGetSpecifiedPrecision() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - columnAnnotation.setPrecision(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedPrecision()); - assertEquals(66, basicMapping.getColumn().getPrecision()); - - columnAnnotation.setPrecision(null); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - } - - public void testSetSpecifiedPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), columnAnnotation.getPrecision()); - - basicMapping.getColumn().setColumnDefinition(null); - basicMapping.getColumn().setSpecifiedPrecision(null); - - assertNull(columnAnnotation.getPrecision()); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetScale() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, basicMapping.getColumn().getScale()); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getScale()); - } - - public void testGetDefaultScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale()); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55)); - - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale()); - } - - public void testGetSpecifiedScale() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - columnAnnotation.setScale(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedScale()); - assertEquals(66, basicMapping.getColumn().getScale()); - - columnAnnotation.setScale(null); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - } - - public void testSetSpecifiedScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), columnAnnotation.getScale()); - - basicMapping.getColumn().setColumnDefinition(null); - basicMapping.getColumn().setSpecifiedScale(null); - - assertNull(columnAnnotation.getScale()); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetUnique() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isUnique()); - } - - public void testGetDefaultUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique()); - } - - public void testGetSpecifiedUnique() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - columnAnnotation.setUnique(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUnique()); - assertEquals(true, basicMapping.getColumn().isUnique()); - - columnAnnotation.setUnique(null); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - } - - public void testSetSpecifiedUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - basicMapping.getColumn().setSpecifiedUnique(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, columnAnnotation.getUnique()); - - basicMapping.getColumn().setColumnDefinition(null); - basicMapping.getColumn().setSpecifiedUnique(null); - - assertNull(columnAnnotation.getUnique()); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetInsertable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isInsertable()); - } - - public void testGetDefaultInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable()); - } - - public void testGetSpecifiedInsertable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - columnAnnotation.setInsertable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedInsertable()); - assertEquals(true, basicMapping.getColumn().isInsertable()); - - columnAnnotation.setInsertable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - } - - public void testSetSpecifiedInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - basicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, columnAnnotation.getInsertable()); - - basicMapping.getColumn().setColumnDefinition(null); - basicMapping.getColumn().setSpecifiedInsertable(null); - - assertNull(columnAnnotation.getInsertable()); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetNullable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isNullable()); - } - - public void testGetDefaultNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable()); - } - - public void testGetSpecifiedNullable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - columnAnnotation.setNullable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedNullable()); - assertEquals(true, basicMapping.getColumn().isNullable()); - - columnAnnotation.setNullable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - } - - public void testSetSpecifiedNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - basicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, columnAnnotation.getNullable()); - - basicMapping.getColumn().setColumnDefinition(null); - basicMapping.getColumn().setSpecifiedNullable(null); - - assertNull(columnAnnotation.getNullable()); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetUpdatable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isUpdatable()); - } - - public void testGetDefaultUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - - assertEquals(ReadOnlyBaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable()); - } - - public void testGetSpecifiedUpdatable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - columnAnnotation.setUpdatable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUpdatable()); - assertEquals(true, basicMapping.getColumn().isUpdatable()); - - columnAnnotation.setUpdatable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - } - - public void testSetSpecifiedUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation columnAnnotation = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, columnAnnotation.getUpdatable()); - - basicMapping.getColumn().setColumnDefinition(null); - basicMapping.getColumn().setSpecifiedUpdatable(null); - - assertNull(columnAnnotation.getUpdatable()); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java deleted file mode 100644 index 37f8d20d9e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java +++ /dev/null @@ -1,458 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaDiscriminatorColumnTests extends ContextModelTestCase -{ - private static final String DISCRIMINATOR_COLUMN_NAME = "MY_DISCRIMINATOR_COLUMN"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithDiscriminatorColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@DiscriminatorColumn(name=\"" + DISCRIMINATOR_COLUMN_NAME + "\")"); - } - }); - } - - private void createTestAbstractEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - public JavaDiscriminatorColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals("foo", discriminatorColumn.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNull(discriminatorColumn); - } - - public void testGetDefaultDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType()); - } - - public void testGetDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR); - getJpaProject().synchronizeContextModel(); - - assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - } - - public void testSetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR, discriminatorColumn.getDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetDiscriminatorTypeUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.INTEGER); - getJpaProject().synchronizeContextModel(); - assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - column.setDiscriminatorType(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength()); - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(55, getJavaEntity().getDiscriminatorColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - } - - public void testGetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setLength(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(66, getJavaEntity().getDiscriminatorColumn().getLength()); - discriminatorColumn.setName(null); - discriminatorColumn.setLength(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(Integer.valueOf(100), discriminatorColumn.getLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetLengthUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setLength(Integer.valueOf(78)); - getJpaProject().synchronizeContextModel(); - assertEquals(Integer.valueOf(78), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(78, getJavaEntity().getDiscriminatorColumn().getLength()); - - column.setLength(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength()); - } - - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setColumnDefinition(COLUMN_DEFINITION); - getJpaProject().synchronizeContextModel(); - - assertEquals(COLUMN_DEFINITION, getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - getJavaEntity().getDiscriminatorColumn().setColumnDefinition(null); - column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNull(column.getColumnDefinition()); - } - - public void testDefaults() throws Exception { - createTestAbstractEntity(); - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + "." + "AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - JavaEntity childEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - - //test defaults with single-table inheritance, no specified discriminator column set - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - - //test defaults with single-table inheritance, specified discriminator column set on root - abstractEntity.getDiscriminatorColumn().setSpecifiedName("DTYPE2"); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(5)); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals("DTYPE2", abstractEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(Integer.valueOf(5), abstractEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(DiscriminatorType.CHAR, abstractEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals("DTYPE2", childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(5, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorType.CHAR, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - //test defaults with table-per-class inheritance, discriminator column does not apply - abstractEntity.getDiscriminatorColumn().setSpecifiedName(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - abstractEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getInheritanceStrategy()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java deleted file mode 100644 index 9df010051b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaEmbeddableTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEmbeddable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable"); - } - }); - } - - - public JavaEmbeddableTests(String name) { - super(name); - } - - public void testMorphToEntity() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Entity); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testEmbeddable() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator overridableAttributeNames = embeddable.overridableAttributeNames(); - assertEquals(overridableAttributeNames.next(), "id"); - assertEquals(overridableAttributeNames.next(), "name"); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator overridableAssociationNames = embeddable.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.tableNameIsInvalid(FULLY_QUALIFIED_TYPE_NAME)); - assertFalse(embeddable.tableNameIsInvalid("FOO")); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - - public void testAssociatedTables() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTables().hasNext()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.allAssociatedTables().hasNext()); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.allAssociatedTableNames().hasNext()); - } - - //TODO need to create a subclass mappedSuperclass and test this - public void testAllOverridableAssociationNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator overridableAssociationNames = embeddable.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java deleted file mode 100644 index d537e47a64..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java +++ /dev/null @@ -1,659 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaEmbeddedIdMappingTests extends ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDED_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@EmbeddedId").append(CR); - sb.append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME +" myEmbeddedId;").append(CR); - sb.append(CR); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - - public JavaEmbeddedIdMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((JavaEmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().overrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("myEmbeddedId", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbeddedId", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualOverrides().next().getName()); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java deleted file mode 100644 index b025276103..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java +++ /dev/null @@ -1,863 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaEmbeddedMappingTests extends ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDED); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded").append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR); - sb.append(CR); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - - public JavaEmbeddedMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().overrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testDefaultEmbeddedMappingGenericEmbeddable() throws Exception { - createTestEntityWithDefaultEmbeddedMapping(); - createTestGenericEmbeddable(); - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Embeddable1"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertNotNull(persistentAttribute.getMapping()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - private void createTestEntityWithDefaultEmbeddedMapping() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 { ").append(CR); - sb.append("private Embeddable1 myEmbeddable;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericEmbeddable() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class Embeddable1 {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Embeddable1.java", sourceWriter); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualOverrides().next().getName()); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = (Iterator) attributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - //1.0 projects do not support dot-notation, this tests to make sure that support does not exist - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - ReadOnlyAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - assertEquals(false, virtualAttributeOverrides.hasNext()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = (ListIterator) nestedAttributeOverrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify there is no attribute override named zipCode.plusfour - virtualAttributeOverride = ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java deleted file mode 100644 index 5adc0dbe05..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java +++ /dev/null @@ -1,3417 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.ReadOnlyJoinColumn; -import org.eclipse.jpt.core.context.ReadOnlyJoinColumnRelationship; -import org.eclipse.jpt.core.context.ReadOnlyJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.ReadOnlyTable; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaEntityTests extends ContextModelTestCase -{ - private static final String ENTITY_NAME = "entityName"; - private static final String TABLE_NAME = "MY_TABLE"; - private static final String DISCRIMINATOR_VALUE = "MY_DISCRIMINATOR_VALUE"; - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public JavaEntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityInvalidNamedQueries() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.NAMED_QUERIES, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@NamedQueries(value={@NamedQuery(query=\"asdf\", name=\"foo\"), @NamedQuer})"); - } - }); - } - - private void createTestAbstractEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - private ICompilationUnit createTestEntityAnnotationOnProperty() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator( - JPA.MAPPED_SUPERCLASS, - JPA.BASIC, - JPA.VERSION, - JPA.TRANSIENT, - JPA.EMBEDDED, - JPA.EMBEDDED_ID, - JPA.ONE_TO_ONE, - JPA.ONE_TO_MANY, - JPA.MANY_TO_ONE, - JPA.MANY_TO_MANY, - JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @Basic"); - sb.append(CR); - sb.append(" private int basic;").append(CR); - sb.append(CR); - sb.append(" @Version"); - sb.append(CR); - sb.append(" private int version;").append(CR); - sb.append(CR); - sb.append(" @Transient"); - sb.append(CR); - sb.append(" private int transient;").append(CR); - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" private int embedded;").append(CR); - sb.append(CR); - sb.append(" @EmbeddedId"); - sb.append(CR); - sb.append(" private int embeddedId;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private " + SUB_TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int oneToMany;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int manyToOne;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int manyToMany;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestEntityWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity(name=\"" + ENTITY_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Table(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithInheritance() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithDiscriminatorValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.DISCRIMINATOR_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@DiscriminatorValue(value=\"" + DISCRIMINATOR_VALUE + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTable(name=\"foo\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name=\"foo\"), @SecondaryTable(name=\"bar\")})"); - } - }); - } - - private ICompilationUnit createAbstractTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - sb.append("abstract"); - } - }); - } - - private void createTestIdClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append("TestTypeId").append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testAccessNoAnnotations() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessAnnotationsOnSuper() throws Exception { - createTestEntityAnnotationOnProperty(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME_ + "AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - JavaPersistentType childPersistentType = getJavaPersistentType(); - PersistentType superPersistentType = childPersistentType.getSuperPersistentType(); - - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((IdMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - resourceType.persistableProperties().next().removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((BasicMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - assertEquals(AccessType.FIELD, superPersistentType.getAccess()); - assertEquals(AccessType.FIELD, childPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //only parent specified in orm.xml, i think this outcome is right?? - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.FIELD, childPersistentType.getAccess()); - - OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - removeXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - //both parent and child specified in orm.xml - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.FIELD, childOrmPersistentType.getJavaPersistentType().getAccess()); - } - - public void testAccessWithXmlSettings() throws Exception { - createTestEntityAnnotationOnProperty(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - typeResource.persistableProperties().next().removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - ((BasicMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //now class is specified in orm.xml, so entityMappings access setting wins over persistence-unit-defaults - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - - //accessType should be PROPERTY now, java gets the access from xml entity if it is specified - assertEquals(AccessType.PROPERTY, ormPersistentType.getJavaPersistentType().getAccess()); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, getJavaEntity().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, getJavaEntity().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals("foo", ((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().setSpecifiedName(null); - - assertNull(getJavaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName()); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME); - entity.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getSpecifiedName()); - } - - public void testGetTableName() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithName(); - - assertEquals(ENTITY_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testGetTableName2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testGetTableName3() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testSetTableNameWithNullTable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - assertEquals(TYPE_NAME, table.getName()); - assertSourceDoesNotContain("@Table", cu); - - table.setSpecifiedName(TABLE_NAME); - assertSourceContains("@Table(name = \"" + TABLE_NAME + "\")", cu); - - assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName()); - assertEquals(TABLE_NAME, table.getName()); - - table.setSpecifiedCatalog(TABLE_NAME); - } - - public void testGetInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getInheritanceStrategy()); - } - - public void testGetDefaultInheritanceStrategy() throws Exception { - createTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertNotSame(childEntity, rootEntity); - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - - //change root inheritance strategy, verify default is changed for child entity - rootEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.SINGLE_TABLE, rootEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getInheritanceStrategy()); - assertNull(childEntity.getSpecifiedInheritanceStrategy()); - } - - public void testGetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - - inheritance.setStrategy(org.eclipse.jpt.core.resource.java.InheritanceType.JOINED); - getJpaProject().synchronizeContextModel(); - - assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy()); - - inheritance.setStrategy(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getSpecifiedInheritanceStrategy()); - } - - public void testSetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy()); - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.core.resource.java.InheritanceType.JOINED, inheritance.getStrategy()); - - } - - public void testGetDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getDiscriminatorValue()); - } - - public void testGetDefaultDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDefaultDiscriminatorValue()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - assertEquals(getJavaEntity().getName(), getJavaEntity().getDefaultDiscriminatorValue()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.INTEGER); - assertNull(getJavaEntity().getDefaultDiscriminatorValue()); - } - - public void testGetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - - discriminatorValue.setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue()); - - discriminatorValue.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getSpecifiedDiscriminatorValue()); - } - - public void testSetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue()); - - getJavaEntity().setSpecifiedDiscriminatorValue("foo"); - - assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - assertEquals("foo", discriminatorValue.getValue()); - } - - public void testSecondaryTables() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator secondaryTables = getJavaEntity().secondaryTables(); - - assertTrue(secondaryTables.hasNext()); - assertEquals("foo", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testSecondaryTablesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.secondaryTablesSize()); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.secondaryTablesSize()); - } - - public void testSpecifiedSecondaryTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedSecondaryTables = getJavaEntity().specifiedSecondaryTables(); - - assertTrue(specifiedSecondaryTables.hasNext()); - assertEquals("foo", specifiedSecondaryTables.next().getName()); - assertEquals("bar", specifiedSecondaryTables.next().getName()); - assertFalse(specifiedSecondaryTables.hasNext()); - } - - public void testSpecifiedSecondaryTablesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.specifiedSecondaryTablesSize()); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.specifiedSecondaryTablesSize()); - } - - public void testAddSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testAddSpecifiedSecondaryTable2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testAddSpecifiedSecondaryTablePreservePkJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable specifiedSecondaryTable = getJavaEntity().addSpecifiedSecondaryTable(0); - specifiedSecondaryTable.setSpecifiedName("FOO"); - specifiedSecondaryTable.setSpecifiedCatalog("CATALOG"); - specifiedSecondaryTable.setSpecifiedSchema("SCHEMA"); - specifiedSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("PK_NAME"); - - //add another specified secondary table, pkJoinColumns from first should be saved. - SecondaryTable specifiedSecondaryTable2 = getJavaEntity().addSpecifiedSecondaryTable(1); - specifiedSecondaryTable2.setSpecifiedName("BAR"); - - - Iterator secondaryTables = getJavaEntity().secondaryTables(); - SecondaryTable secondaryTable = secondaryTables.next(); - assertEquals(secondaryTable, specifiedSecondaryTable); - assertEquals("FOO", secondaryTable.getName()); - assertEquals("CATALOG", secondaryTable.getCatalog()); - assertEquals("SCHEMA", secondaryTable.getSchema()); - assertEquals(1, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - PrimaryKeyJoinColumn pkJoinColumn = secondaryTable.specifiedPrimaryKeyJoinColumns().next(); - assertEquals("PK_NAME", pkJoinColumn.getName()); - - secondaryTable = secondaryTables.next(); - assertEquals(secondaryTable, specifiedSecondaryTable2); - assertEquals("BAR", secondaryTable.getName()); - assertEquals(0, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - - } - - public void testRemoveSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME))); - - getJavaEntity().removeSpecifiedSecondaryTable(1); - - Iterator secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertFalse(secondaryTableResources.hasNext()); - - Iterator secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - getJavaEntity().removeSpecifiedSecondaryTable(1); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertFalse(secondaryTableResources.hasNext()); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - getJavaEntity().removeSpecifiedSecondaryTable(0); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertFalse(secondaryTableResources.hasNext()); - secondaryTables = getJavaEntity().secondaryTables(); - assertFalse(secondaryTables.hasNext()); - - assertNull(typeResource.getAnnotation(SecondaryTablesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - entity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - Iterator javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaSecondaryTables)); - - - entity.moveSpecifiedSecondaryTable(2, 0); - ListIterator secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - - javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - - - entity.moveSpecifiedSecondaryTable(0, 1); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - - javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - } - - public void testUpdateSpecifiedSecondaryTables() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.moveAnnotation(2, 0, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.moveAnnotation(0, 1, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertFalse(secondaryTables.hasNext()); - } - - public void testAssociatedTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(getJavaEntity().associatedTables())); - Iterator associatedTables = getJavaEntity().associatedTables(); - ReadOnlyTable table1 = associatedTables.next(); - SecondaryTable table2 = (SecondaryTable) associatedTables.next(); - SecondaryTable table3 = (SecondaryTable) associatedTables.next(); - assertEquals(TYPE_NAME, table1.getName()); - assertEquals("foo", table2.getName()); - assertEquals("bar", table3.getName()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestEntityWithSecondaryTables(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertEquals(3, CollectionTools.size(rootEntity.allAssociatedTables())); - Iterator associatedTables = rootEntity.allAssociatedTables(); - ReadOnlyTable table1 = associatedTables.next(); - SecondaryTable table2 = (SecondaryTable) associatedTables.next(); - SecondaryTable table3 = (SecondaryTable) associatedTables.next(); - assertEquals(TYPE_NAME, table1.getName()); - assertEquals("foo", table2.getName()); - assertEquals("bar", table3.getName()); - - //TODO probably want this to be 3, since in this case the child descriptor really uses the - //parent table because it is single table inheritance strategy. Not sure yet how to deal with this. - assertEquals(4, CollectionTools.size(childEntity.allAssociatedTables())); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestEntityWithSecondaryTables(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertEquals(3, CollectionTools.size(rootEntity.allAssociatedTableNames())); - Iterator associatedTables = rootEntity.allAssociatedTableNames(); - String table1 = associatedTables.next(); - String table2 = associatedTables.next(); - String table3 = associatedTables.next(); - assertEquals(TYPE_NAME, table1); - assertEquals("foo", table2); - assertEquals("bar", table3); - - //TODO probably want this to be 3, since in this case the child descriptor really uses the - //parent table because it is single table inheritance strategy. Not sure yet how to deal with this. - assertEquals(4, CollectionTools.size(childEntity.allAssociatedTableNames())); - } - - public void testAddSecondaryTableToResourceModel() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, getJavaEntity().secondaryTablesSize()); - assertEquals("FOO", getJavaEntity().secondaryTables().next().getSpecifiedName()); - assertEquals("FOO", getJavaEntity().secondaryTables().next().getName()); - - SecondaryTableAnnotation secondaryTable2 = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable2.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, getJavaEntity().secondaryTablesSize()); - ListIterator secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - - SecondaryTableAnnotation secondaryTable3 = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable3.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, getJavaEntity().secondaryTablesSize()); - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - } - - public void testRemoveSecondaryTableFromResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("baz"); - ListIterator secondaryTables = getJavaEntity().secondaryTables(); - - assertEquals(3, getJavaEntity().secondaryTablesSize()); - assertEquals("foo", secondaryTables.next().getSpecifiedName()); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, getJavaEntity().secondaryTablesSize()); - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - getJpaProject().synchronizeContextModel(); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(1, getJavaEntity().secondaryTablesSize()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - getJpaProject().synchronizeContextModel(); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(0, getJavaEntity().secondaryTablesSize()); - assertFalse(secondaryTables.hasNext()); - } - - public void testGetSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertEquals(2, typeResource.annotationsSize()); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - - getJavaEntity().getGeneratorContainer().getSequenceGenerator().setName("foo"); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - - getJavaEntity().getGeneratorContainer().addSequenceGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - getJavaEntity().getGeneratorContainer().removeSequenceGenerator(); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertEquals(2, typeResource.annotationsSize()); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - - getJavaEntity().getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - - getJavaEntity().getGeneratorContainer().addTableGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - getJavaEntity().getGeneratorContainer().removeTableGenerator(); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetDiscriminatorColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(getJavaEntity().getDiscriminatorColumn()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - column.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getDiscriminatorColumn()); - } - - public void testSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - - assertFalse(specifiedPkJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(specifiedPkJoinColumns.hasNext()); - } - - public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertEquals(3, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - //just the default pkJoinColumn, so 1 - assertEquals(1, getJavaEntity().primaryKeyJoinColumnsSize()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - //only the specified pkJoinColumns, 3 - assertEquals(3, getJavaEntity().primaryKeyJoinColumnsSize()); - } - - public void testGetDefaultPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertFalse(pkJoinColumns.hasNext()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertFalse(pkJoinColumns.hasNext()); - } - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME))); - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - - Iterator pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - Iterator pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(pkJoinColumnResources.hasNext()); - pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(pkJoinColumns.hasNext()); - - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - entity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - entity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaPrimaryKeyJoinColumns)); - - - entity.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - - - entity.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.moveAnnotation(2, 0, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.moveAnnotation(0, 1, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertFalse(primaryKeyJoinColumns.hasNext()); - } - - public void testPrimaryKeyJoinColumnIsVirtual() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaEntity().getDefaultPrimaryKeyJoinColumn().isDefault()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isDefault()); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertFalse(getJavaEntity().tableNameIsInvalid(TYPE_NAME)); - assertTrue(getJavaEntity().tableNameIsInvalid("FOO")); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - - assertFalse(getJavaEntity().tableNameIsInvalid("BAR")); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) getJavaPersistentType().getMapping(); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributes.next()); - assertEquals("basic", overridableAttributes.next()); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAssociations = abstractEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributes.next()); - assertEquals("basic", overridableAttributes.next()); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributeNames = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributeNames.next()); - assertEquals("basic", overridableAttributeNames.next()); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - ListIterator specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrideDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("foo", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - BasicMapping fooMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("foo").getMapping(); - fooMapping.getColumn().setSpecifiedName("FOO"); - fooMapping.getColumn().setSpecifiedTable("BAR"); - fooMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - fooMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - fooMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - fooMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - fooMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - fooMapping.getColumn().setSpecifiedName(null); - fooMapping.getColumn().setSpecifiedTable(null); - fooMapping.getColumn().setColumnDefinition(null); - fooMapping.getColumn().setSpecifiedInsertable(null); - fooMapping.getColumn().setSpecifiedUpdatable(null); - fooMapping.getColumn().setSpecifiedUnique(null); - fooMapping.getColumn().setSpecifiedNullable(null); - fooMapping.getColumn().setSpecifiedLength(null); - fooMapping.getColumn().setSpecifiedPrecision(null); - fooMapping.getColumn().setSpecifiedScale(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("foo", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - } - - public void testVirtualAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - JavaEntity superclass = (JavaEntity) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, overrideContainer.overridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(3, CollectionTools.size(typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - Iterator attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - Iterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("id", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrideResources.hasNext()); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaAttributeOverrides)); - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("id", attributeOverrides.next().getName()); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AttributeOverrideAnnotation) typeResource.addAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(2, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociationNames = getJavaEntity().overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociationNames = getJavaEntity().allOverridableAssociationNames(); - assertEquals("oneToOne", overridableAssociationNames.next()); - assertEquals("manyToOne", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociations() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("oneToOne", overridableAssociations.next()); - assertEquals("manyToOne", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } -// -// public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception { -// createTestMappedSuperclass(); -// createTestSubType(); -// addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); -// getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// Iterator overridableAssociations = getJavaEntity().allOverridableAssociations(); -// assertEquals("oneToOne", overridableAssociations.next().getName()); -// assertEquals("manyToOne", overridableAssociations.next().getName()); -// assertFalse(overridableAssociations.hasNext()); -// } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AssociationOverrideContainer overrideContainer = javaEntity.getAssociationOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - ReadOnlyJoinColumnRelationshipStrategy joiningStrategy = ((ReadOnlyJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - ReadOnlyJoinColumn virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("oneToOne_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(SUB_TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - - OneToOneMapping oneToOneMapping = (OneToOneMapping) getJavaPersistentType().getAttributeNamed("oneToOne").getMapping(); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - joiningStrategy = ((ReadOnlyJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals("MY_JOIN_COLUMN", joiningStrategy.joinColumns().next().getName()); - - - - - - - //idMapping.getColumn().setSpecifiedName(null); - //idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.overridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, overrideContainer.overridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(2, CollectionTools.size(typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - Iterator associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("manyToOne", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("manyToOne", associationOverrides.next().getName()); - assertEquals("oneToOne", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("oneToOne", associationOverrides.next().getName()); - assertEquals("manyToOne", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AssociationOverrideAnnotation) typeResource.addAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(2, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - JavaVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("manyToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("manyToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testAddNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - NamedQuery namedQuery1 = entity.getQueryContainer().addNamedQuery(0); - namedQuery1.setName("FOO"); - - Iterator javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedQuery namedQuery2 = entity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedQuery namedQuery3 = entity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - ListIterator namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery1, namedQueries.next()); - - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("foo"); - } - - public void testInvalidNamedQueries() throws Exception { - createTestEntityInvalidNamedQueries(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - assertEquals(1, entity.getQueryContainer().namedQueriesSize()); - } - - public void testRemoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testAddNamedNativeQueryWithNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - - - NamedNativeQueryAnnotation nativeQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - nativeQuery.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, entity.getQueryContainer().namedNativeQueriesSize()); - ListIterator namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - } - - public void testAddNamedQueryWithNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, entity.getQueryContainer().namedQueriesSize()); - ListIterator namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - } - - public void testMoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - - entity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - - ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - ListIterator namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().queriesSize()); - - typeResource.moveAnnotation(2, 0, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.moveAnnotation(0, 1, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - } - - public void testNamedQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getQueryContainer().namedQueriesSize()); - - ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().namedQueriesSize()); - } - - public void testAddNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - Iterator javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedNativeQuery namedNativeQuery2 = entity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedNativeQuery namedNativeQuery3 = entity.getQueryContainer().addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - ListIterator namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals(namedNativeQuery2, namedQueries.next()); - assertEquals(namedNativeQuery3, namedQueries.next()); - assertEquals(namedNativeQuery, namedQueries.next()); - - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - Iterator javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testMoveNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - Iterator javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().moveNamedNativeQuery(2, 0); - ListIterator namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedNativeQuery(0, 1); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - ListIterator namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().queriesSize()); - - typeResource.moveAnnotation(2, 0, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.moveAnnotation(0, 1, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - } - - public void testNamedNativeQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getQueryContainer().namedNativeQueriesSize()); - - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().namedNativeQueriesSize()); - } - - public void testUpdateIdClass() throws Exception { - createTestEntity(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - IdClassAnnotation idClassAnnotation = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - // test setting id class name to nonexistent class. test class name is set, but class is null - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClassAnnotation.setValue(nonExistentIdClassName); - getJpaProject().synchronizeContextModel(); - assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - // test setting id class name to existent class. test class name is set and class is not null - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClassAnnotation.setValue(existentIdClassName); - getJpaProject().synchronizeContextModel(); - assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertNotNull(getJavaEntity().getIdClassReference().getIdClass()); - - //test setting @IdClass value to null - idClassAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - //reset @IdClass value and then remove @IdClass - idClassAnnotation = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - idClassAnnotation.setValue(existentIdClassName); - typeResource.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - } - - public void testModifyIdClass() throws Exception { - createTestEntity(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME_ + "Foo"; - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - String existentIdClassName = PACKAGE_NAME_ + "TestTypeId"; - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(existentIdClassName); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNotNull(getJavaEntity().getIdClassReference().getIdClass()); - - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(null); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - } - - public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType entityPersistentType = classRefs.next().getJavaPersistentType(); - JavaEntity javaEntity = (JavaEntity) entityPersistentType.getMapping(); - JavaPersistentType mappedSuperclassPersistentType = classRefs.next().getJavaPersistentType(); - - assertEquals("id", javaEntity.getPrimaryKeyColumnName()); - - ((JavaIdMapping) mappedSuperclassPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("MY_ID", javaEntity.getPrimaryKeyColumnName()); - - ListIterator virtualAttributeOverrides = javaEntity.getAttributeOverrideContainer().virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next(); - JavaVirtualAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - - virtualOverride.convertToSpecified().getColumn().setSpecifiedName("ID"); - assertEquals("ID", javaEntity.getPrimaryKeyColumnName()); - } - - public void testDiscriminatorValueIsUndefinedConcreteClass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertFalse(getJavaEntity().discriminatorValueIsUndefined()); - } - - public void testDiscriminatorValueIsUndefinedAbstractClass() throws Exception { - createTestAbstractEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - } - - public void testSpecifiedDiscriminatorColumnIsAllowed() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - //table-per-class, no discriminator column allowed - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertFalse(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - - - //single-table, discriminator column allowed on root entity - abstractEntity.setSpecifiedInheritanceStrategy(null); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertTrue(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - } - - public void testAbstractEntityGetDefaultDiscriminatorColumnNameTablePerClassInheritance() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getSpecifiedInheritanceStrategy()); - assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy()); - - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(null, concreteEntity.getDiscriminatorColumn().getDefaultName()); - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertEquals(null, abstractEntity.getDefaultDiscriminatorValue()); - assertTrue(concreteEntity.discriminatorValueIsUndefined()); - assertEquals(null, concreteEntity.getDefaultDiscriminatorValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java deleted file mode 100644 index f2c63a3a47..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaGeneratedValueTests extends ContextModelTestCase -{ - private static final String GENERATOR = "MY_GENERATOR"; - - private ICompilationUnit createTestEntityWithGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.GENERATED_VALUE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@GeneratedValue(generator=\"" + GENERATOR + "\")"); - } - }); - } - - public JavaGeneratedValueTests(String name) { - super(name); - } - - public void testGetGenerator() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setGenerator("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - } - - public void testSetSpecifiedGenerator() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator("foo"); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertEquals("foo", generatedValue.getGenerator()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator(null); - - assertNotNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertNotNull(generatedValue); - } - - public void testGetStrategy() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setStrategy(org.eclipse.jpt.core.resource.java.GenerationType.IDENTITY); - getJpaProject().synchronizeContextModel(); - - assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy()); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getDefaultStrategy()); - } - - public void testSetSpecifiedStrategy() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - idMapping.getGeneratedValue().setSpecifiedStrategy(GenerationType.IDENTITY); - - assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertEquals(org.eclipse.jpt.core.resource.java.GenerationType.IDENTITY, generatedValue.getStrategy()); - - idMapping.getGeneratedValue().setSpecifiedStrategy(null); - - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertNotNull(generatedValue); - assertNull(generatedValue.getStrategy()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java deleted file mode 100644 index 58ea064fad..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java +++ /dev/null @@ -1,715 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaIdMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithIdMappingGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.GENERATED_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@GeneratedValue").append(CR); - } - }); - } - - public JavaIdMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporal() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) idMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertNull(idMapping.getConverter().getType()); - - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - idMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertNull(idMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.DATE, ((TemporalConverter) idMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(idMapping.getConverter().getType()); - assertFalse(idMapping.isDefault()); - assertSame(idMapping, persistentAttribute.getMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertNull(idMapping.getColumn().getSpecifiedName()); - assertEquals("id", idMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getColumn().getSpecifiedName()); - assertEquals("foo", idMapping.getColumn().getName()); - assertEquals("id", idMapping.getColumn().getDefaultName()); - } - - public void testGetSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertEquals(0, idMapping.getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - resourceAttribute.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertEquals(2, resourceAttribute.annotationsSize()); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - - idMapping.getGeneratorContainer().addSequenceGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - - idMapping.getGeneratorContainer().removeSequenceGenerator(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertEquals(0, idMapping.getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - assertNotNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertEquals(2, attributeResource.annotationsSize()); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - - idMapping.getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - - idMapping.getGeneratorContainer().addTableGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(idMapping.getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - - idMapping.getGeneratorContainer().removeTableGenerator(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - getJpaProject().synchronizeContextModel(); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(2, attributeResource.annotationsSize()); - } - - public void testGetGeneratedValue2() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithIdMappingGeneratedValue(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(2, attributeResource.annotationsSize()); - } - - public void testAddGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertNull(idMapping.getGeneratedValue()); - - idMapping.addGeneratedValue(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE)); - assertNotNull(idMapping.getGeneratedValue()); - - //try adding another generated value, should get an IllegalStateException - try { - idMapping.addGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - getJpaProject().synchronizeContextModel(); - - idMapping.removeGeneratedValue(); - - assertNull(idMapping.getGeneratedValue()); - assertNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE)); - - //try removing the generatedValue again, should get an IllegalStateException - try { - idMapping.removeGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java deleted file mode 100644 index 66d24bfdae..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java +++ /dev/null @@ -1,549 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaJoinColumnTests extends ContextModelTestCase -{ - public JavaJoinColumnTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - sb.append(" private Project project;").append(CR); - } - }); - } - - private void createTargetEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - - JoinColumnAnnotation joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(joinColumnAnnotation); - - - //set name in the resource model, verify context model updated - joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - joinColumnAnnotation.setName("FOO"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", joinColumnAnnotation.getName()); - - //set name to null, annotation is NOT removed - joinColumn.setSpecifiedName(null); - assertEquals(1, joinColumns.specifiedJoinColumnsSize()); - joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertNull(joinColumnAnnotation.getName()); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - JoinColumnAnnotation joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinColumn.getSpecifiedName()); - assertEquals("foo", joinColumnAnnotation.getName()); - - //set name to null in the context model - joinColumn.setSpecifiedName(null); - assertNull(joinColumn.getSpecifiedName()); - joinColumnAnnotation = (JoinColumnAnnotation) resourceAttribute.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertNull(joinColumnAnnotation.getName()); - } - - // _ - // or - // _ - public void testDefaultName() throws Exception { - createTestEntityWithValidOneToOne(); - createTargetEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - -// JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); -// JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnJoiningStrategy(); -// JavaJoinColumn defaultJavaJoinColumn = joinColumns.getDefaultJoinColumn(); -// -// assertNull(defaultJavaJoinColumn.getDefaultName()); -//TODO test default join column name -// //add target entity to the persistence unit, now join table name is [table name]_[target table name] -// addXmlClassRef(PACKAGE_NAME + ".Project"); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// -// JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); -// JavaPersistentAttributeResource attributeResource = typeResource.attributes().next(); -// assertNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME)); -// -// //target entity does not resolve, default name is null -// manyToManyMapping.setSpecifiedTargetEntity("Foo"); -// assertNull(joinTable.getDefaultName()); -// -// //default target entity does resolve, so default name is again [table name]_[target table name] -// manyToManyMapping.setSpecifiedTargetEntity(null); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// -// //add the join table annotation, verify default join table name is the same -// attributeResource.addAnnotation(JoinTable.ANNOTATION_NAME); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// assertNotNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME)); -// -// //set a table on the target entity, very default join table name updates -// manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName()); -// -// //set a table on the owning entity, very default join table name updates -// javaEntity().getTable().setSpecifiedName("BAR"); -// assertEquals("BAR_FOO", joinTable.getDefaultName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set referenced column name in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setReferencedColumnName("BAR"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", javaJoinColumn.getReferencedColumnName()); - - //set referenced column name to null in the resource model, - javaJoinColumn.setReferencedColumnName(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull("BAR", javaJoinColumn.getReferencedColumnName()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set referenced column name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedReferencedColumnName("BAR"); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", javaJoinColumn.getReferencedColumnName()); - - //set referenced column name to null in the context model - joinColumn.setSpecifiedReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(javaJoinColumn.getReferencedColumnName()); - } - - public void testDefaultReferencedColumnName() throws Exception { - //TODO test default join column referenced column name - - } - - public void testUpdateTable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set table in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setTable("BAR"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedTable()); - assertEquals("BAR", javaJoinColumn.getTable()); - - //set table to null in the resource model, - javaJoinColumn.setTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedTable()); - assertNull("BAR", javaJoinColumn.getTable()); - } - - public void testModifyTable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set table in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedTable("BAR"); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("BAR", joinColumn.getSpecifiedTable()); - assertEquals("BAR", javaJoinColumn.getTable()); - - //set table to null in the context model - joinColumn.setSpecifiedTable(null); - assertNull(joinColumn.getSpecifiedTable()); - assertNull(javaJoinColumn.getTable()); - } - - public void testDefaultTable() throws Exception { - //TODO test default join column table - - } - - public void testUpdateUnique() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set unique in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setUnique(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, javaJoinColumn.getUnique()); - - //set unique to null in the resource model, - javaJoinColumn.setUnique(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedUnique()); - assertNull(javaJoinColumn.getUnique()); - } - - public void testModifyUnique() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set unique in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, javaJoinColumn.getUnique()); - - //set unique to null in the context model - joinColumn.setSpecifiedUnique(null); - assertNull(joinColumn.getSpecifiedUnique()); - assertNull(javaJoinColumn.getUnique()); - } - - public void testUpdateNullable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set nullable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setNullable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getNullable()); - - //set nullable to null in the resource model, - javaJoinColumn.setNullable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedNullable()); - assertNull(javaJoinColumn.getNullable()); - } - - public void testModifyNullable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set nullable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getNullable()); - - //set nullable to null in the context model - joinColumn.setSpecifiedNullable(null); - assertNull(joinColumn.getSpecifiedNullable()); - assertNull(javaJoinColumn.getNullable()); - } - - public void testUpdateInsertable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set insertable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setInsertable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable()); - - //set insertable to null in the resource model, - javaJoinColumn.setInsertable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedInsertable()); - assertNull(javaJoinColumn.getInsertable()); - } - - public void testModifyInsertable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set insertable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable()); - - //set insertable to null in the context model - joinColumn.setSpecifiedInsertable(null); - assertNull(joinColumn.getSpecifiedInsertable()); - assertNull(javaJoinColumn.getInsertable()); - } - - public void testUpdateUpdatable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set updatable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setUpdatable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable()); - - //set updatable to null in the resource model, - javaJoinColumn.setUpdatable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedUpdatable()); - assertNull(javaJoinColumn.getUpdatable()); - } - - public void testModifyUpdatable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set updatable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable()); - - //set updatable to null in the context model - joinColumn.setSpecifiedUpdatable(null); - assertNull(joinColumn.getSpecifiedUpdatable()); - assertNull(javaJoinColumn.getUpdatable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java deleted file mode 100644 index 597189ef7e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java +++ /dev/null @@ -1,1177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaJoinTableTests extends ContextModelTestCase -{ - public JavaJoinTableTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - sb.append(" private Collection projects;").append(CR); - } - }); - } - - private void createTargetEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - private void createTargetEntityWithBackPointer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(" @ManyToMany(mappedBy=\"projects\"").append(CR); - sb.append(" private java.util.Collection<" + TYPE_NAME + "> employees;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable); - - - //set name in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - //set name to null in the resource model - javaJoinTable.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable.getName()); - - javaJoinTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedName()); - assertNull(joinTableAnnotation); - - //set name in the context model, verify resource model modified - joinTable.setSpecifiedName("foo"); - joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedName()); - assertEquals("foo", joinTableAnnotation.getName()); - - //set name to null in the context model - joinTable.setSpecifiedName(null); - assertNull(joinTable.getSpecifiedName()); - joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertNull(joinTableAnnotation.getName()); - } - - public void testDefaultName() throws Exception { - createTestEntityWithValidManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinTable.getDefaultName()); - - //add target entity to the persistence unit, now join table name is [table name]_[target table name] - createTargetEntity(); - addXmlClassRef(PACKAGE_NAME + ".Project"); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //target entity does not resolve, default name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertNull(joinTable.getDefaultName()); - - //default target entity does resolve, so default name is again [table name]_[target table name] - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - - //add the join table annotation, verify default join table name is the same - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //set a table on the target entity, very default join table name updates - manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName()); - - //set a table on the owning entity, very default join table name updates - getJavaEntity().getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", joinTable.getDefaultName()); - } - - public void testDefaultJoinColumns() throws Exception { - createTestEntityWithValidManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - JoinColumn joinColumn = joinTable.joinColumns().next(); - JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key - createTargetEntity(); - addXmlClassRef(PACKAGE_NAME + ".Project"); - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //create primary key in owning entity - getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(TYPE_NAME + "_id", joinColumn.getDefaultName()); - assertEquals("id", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //set specified column name on primary key in owning entity - ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //target entity does not resolve, inverse join column name and referenced column name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //default target entity does resolve, so defaults for join column are back - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //add the join table annotation, verify default join table name is the same - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultJoinColumnsBidirectionalRelationship() throws Exception { - createTestEntityWithValidManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - JoinColumn joinColumn = joinTable.joinColumns().next(); - JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key - createTargetEntityWithBackPointer(); - addXmlClassRef(PACKAGE_NAME + ".Project"); - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //create primary key in owning entity - getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("employees_id", joinColumn.getDefaultName()); - assertEquals("id", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //set specified column name on primary key in owning entity - ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //target entity does not resolve, inverse join column name and referenced column name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //default target entity does resolve, so defaults for join column are back - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //add the join table annotation, verify default join table name is the same - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedSchema() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable); - - - //set schema in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedSchema()); - assertEquals("FOO", javaJoinTable.getSchema()); - - //set schema to null in the resource model - javaJoinTable.setSchema(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable.getSchema()); - - javaJoinTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedSchema()); - assertEquals("FOO", javaJoinTable.getSchema()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedSchema() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedSchema()); - assertNull(joinTableAnnotation); - - //set schema in the context model, verify resource model modified - joinTable.setSpecifiedSchema("foo"); - joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedSchema()); - assertEquals("foo", joinTableAnnotation.getSchema()); - - //set schema to null in the context model - joinTable.setSpecifiedSchema(null); - assertNull(joinTable.getSpecifiedSchema()); - joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertNull(joinTableAnnotation.getSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable); - - - //set catalog in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedCatalog()); - assertEquals("FOO", javaJoinTable.getCatalog()); - - //set catalog to null in the resource model - javaJoinTable.setCatalog(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable.getCatalog()); - - javaJoinTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedCatalog()); - assertEquals("FOO", javaJoinTable.getCatalog()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedCatalog() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(joinTableAnnotation); - - //set catalog in the context model, verify resource model modified - joinTable.setSpecifiedCatalog("foo"); - joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedCatalog()); - assertEquals("foo", joinTableAnnotation.getCatalog()); - - //set catalog to null in the context model - joinTable.setSpecifiedCatalog(null); - assertNull(joinTable.getSpecifiedCatalog()); - joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertNull(joinTableAnnotation.getCatalog()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = joinTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = joinTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - ListIterator joinColumns = joinTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - - joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) resourceAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableAnnotation.joinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableAnnotation.joinColumnsSize()); - assertEquals("BAR", joinTableAnnotation.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableAnnotation.joinColumnAt(1).getName()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableAnnotation.joinColumnsSize()); - assertEquals("BAZ", joinTableAnnotation.joinColumnAt(0).getName()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableAnnotation.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - - joinTable.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - - joinTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableResource.addJoinColumn(0); - joinTableResource.addJoinColumn(1); - joinTableResource.addJoinColumn(2); - - joinTableResource.joinColumnAt(0).setName("FOO"); - joinTableResource.joinColumnAt(1).setName("BAR"); - joinTableResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joinTable.specifiedJoinColumns().hasNext()); - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertEquals(0, joinTable.specifiedJoinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(1, joinTable.specifiedJoinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTable.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertEquals(1, joinTable.joinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(1, joinTable.joinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(2, joinTable.joinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTable.joinColumnsSize()); - - // default columns - assertNotNull(manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable()); - JavaResourcePersistentAttribute resAttribute = this.getJavaPersistentType().attributes().next().getResourcePersistentAttribute(); - assertNotNull(resAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - manyToManyMapping.getRelationship().getJoinTableStrategy().removeStrategy(); - // default join table - assertNotNull(manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable()); - assertNull(resAttribute.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //if non-owning side of the relationship then no default join table - manyToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("foo"); - assertNull(manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable()); - } - - public void testAddSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JoinColumn inverseJoinColumn = joinTable.addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("FOO"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(0).getName()); - - JoinColumn inverseJoinColumn2 = joinTable.addSpecifiedInverseJoinColumn(0); - inverseJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(1).getName()); - - JoinColumn inverseJoinColumn3 = joinTable.addSpecifiedInverseJoinColumn(1); - inverseJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - - ListIterator inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals(inverseJoinColumn2, inverseJoinColumns.next()); - assertEquals(inverseJoinColumn3, inverseJoinColumns.next()); - assertEquals(inverseJoinColumn, inverseJoinColumns.next()); - - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - joinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.inverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTableResource.inverseJoinColumnsSize()); - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTableResource.inverseJoinColumnsSize()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(0).getName()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTableResource.inverseJoinColumnsSize()); - } - - public void testMoveSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - joinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.inverseJoinColumnsSize()); - - - joinTable.moveSpecifiedInverseJoinColumn(2, 0); - ListIterator inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - - - joinTable.moveSpecifiedInverseJoinColumn(0, 1); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - } - - public void testUpdateInverseJoinColumns() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableResource.addInverseJoinColumn(0); - joinTableResource.addInverseJoinColumn(1); - joinTableResource.addInverseJoinColumn(2); - - joinTableResource.inverseJoinColumnAt(0).setName("FOO"); - joinTableResource.inverseJoinColumnAt(1).setName("BAR"); - joinTableResource.inverseJoinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.moveInverseJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.moveInverseJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(1); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(1); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joinTable.specifiedInverseJoinColumns().hasNext()); - } - - public void testGetDefaultInverseJoinColumn() { - //TODO - } - - public void testSpecifiedInverseJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertEquals(0, joinTable.specifiedInverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.specifiedInverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTable.specifiedInverseJoinColumnsSize()); - } - - public void testInverseJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTable.inverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - //if non-owning side of the relationship then no default join table - manyToManyMapping.getRelationship().setStrategyToMappedBy(); - assertNull(manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable()); - } - - public void testUniqueConstraints() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - ListIterator uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = joinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertEquals(0, joinTable.uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, joinTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - ListIterator uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - ListIterator uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - joinTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - joinTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - joinTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - - joinTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - joinTable.moveUniqueConstraint(0, 1); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - joinTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java deleted file mode 100644 index bdc61c6309..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java +++ /dev/null @@ -1,1180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToManyRelationship; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaManyToManyMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithCollectionManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonCollectionManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Address addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("import java.util.Map;"); - sb.append(CR); - sb.append("import ").append(JPA.MANY_TO_MANY).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Map employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - public JavaManyToManyMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToManyAnnotation = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToManyAnnotation.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToManyAnnotation.setTargetEntity("newTargetEntity"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("newTargetEntity", manyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToManyAnnotation.getTargetEntity()); - - //set target entity to null in the resource model - manyToManyAnnotation.setTargetEntity(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToManyAnnotation.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - manyToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the context model - manyToManyMapping.setSpecifiedTargetEntity(null); - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, manyToMany.getFetch()); - - - //set fetch to null in the resource model - manyToMany.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - - //set fetch in the context model, verify resource model updated - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, manyToMany.getFetch()); - - manyToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, manyToMany.getFetch()); - - //set fetch to null in the context model - manyToManyMapping.setSpecifiedFetch(null); - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - - //set mappedByJoiningStrategy in the resource model, verify context model updated - manyToMany.setMappedBy("newMappedBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newMappedBy", manyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //set mappedByJoiningStrategy to null in the resource model - manyToMany.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - manyToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertEquals("newTargetEntity", manyToMany.getMappedBy()); - - //set mappedBy to null in the context model - manyToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute(null); - assertNull(manyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - ManyToManyAnnotation annotation = (ManyToManyAnnotation) resourceAttribute.getAnnotation(JPA.MANY_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping mapping = (ManyToManyMapping) contextAttribute.getMapping(); - ManyToManyRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - ManyToManyAnnotation annotation = (ManyToManyAnnotation) resourceAttribute.getAnnotation(JPA.MANY_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping mapping = (ManyToManyMapping) contextAttribute.getMapping(); - ManyToManyRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityNonCollectionType() throws Exception { - createTestEntityWithNonCollectionManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getTargetEntity()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", manyToManyMapping.getTargetEntity()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(manyToManyMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertNull(manyToManyMapping.getResolvedTargetEntity()); - - - manyToManyMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - - - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - } - - - public void testUpdateMapKey() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKeyAnnotation.getName()); - - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKey(null); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKeyAnnotation.getName()); - manyToManyMapping.setNoMapKey(true); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = - javaManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = javaManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = javaManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - public void testUpdateOrderBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newOrderBy", manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", orderBy.getValue()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyOrderBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set mappedBy in the context model, verify resource model updated - manyToManyMapping.getOrderable().setSpecifiedOrderBy("newOrderBy"); - assertEquals("newOrderBy", manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertEquals("newOrderBy", orderBy.getValue()); - - //set mappedBy to null in the context model - manyToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateNoOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertTrue(manyToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isNoOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isNoOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(manyToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyNoOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertTrue(manyToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - -// manyToManyMapping.setNoOrdering(false); //this does nothing -// //set mappedBy in the context model, verify resource model updated -// manyToManyMapping.setOrderBy("newOrderBy"); -// assertEquals("newOrderBy", manyToManyMapping.getOrderBy()); -// OrderBy orderBy = (OrderBy) attributeResource.annotation(OrderBy.ANNOTATION_NAME); -// assertEquals("newOrderBy", orderBy.getValue()); -// -// //set mappedBy to null in the context model -// manyToManyMapping.setOrderBy(null); -// assertNull(manyToManyMapping.getOrderBy()); -// assertNull(attributeResource.annotation(OrderBy.ANNOTATION_NAME)); - } - - public void testUpdatePkOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(manyToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(manyToManyMapping.getOrderable().isPkOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isPkOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateCustomOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(manyToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.getOrderable().isCustomOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertTrue(manyToManyMapping.getOrderable().isCustomOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultTargetEntityForMap() throws Exception { - createTestEmployee(); - createTestDepartment(); - addXmlClassRef(PACKAGE_NAME + ".Department"); - addXmlClassRef(PACKAGE_NAME + ".Employee"); - - JavaPersistentType departmentPersistentType = getJavaPersistentType(); - ManyToManyMapping employeesMapping = (ManyToManyMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - assertEquals(PACKAGE_NAME + ".Employee", employeesMapping.getTargetEntity()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java deleted file mode 100644 index c1b38d53a8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java +++ /dev/null @@ -1,960 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.ManyToOneRelationship; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaManyToOneMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericizedCollectionManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - public JavaManyToOneMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToOne.setTargetEntity("newTargetEntity"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("newTargetEntity", manyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the resource model - manyToOne.setTargetEntity(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - manyToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the context model - manyToOneMapping.setSpecifiedTargetEntity(null); - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - - //set optional in the resource model, verify context model updated - manyToOne.setOptional(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - //set optional to null in the resource model - manyToOne.setOptional(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - - //set optional in the context model, verify resource model updated - manyToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - - //set optional to null in the context model - manyToOneMapping.setSpecifiedOptional(null); - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - } - - - public void testSpecifiedJoinColumns() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - ListIterator specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - - assertFalse(specifiedJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertFalse(specifiedJoinColumns.hasNext()); - } - - public void testGetDefaultJoin() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(2, joinColumns.joinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator joinColumnsIterator = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testAddSpecifiedJoinColumn2() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator joinColumnsIterator = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME))); - - joinColumns.removeSpecifiedJoinColumn(1); - - Iterator joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(1); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - - assertNull(attributeResource.getAnnotation(JoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - Iterator javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - joinColumns.moveSpecifiedJoinColumn(2, 0); - ListIterator primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - - - joinColumns.moveSpecifiedJoinColumn(0, 1); - primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedJoinColumns() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - ((JoinColumnAnnotation) attributeResource.addAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(2, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(2, 0, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(0, 1, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - } - public void testJoinColumnIsVirtual() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = manyToOneMapping.getRelationship().getJoinColumnStrategy(); - - assertTrue(joinColumns.getDefaultJoinColumn().isDefault()); - - joinColumns.addSpecifiedJoinColumn(0); - JoinColumn specifiedJoinColumn = joinColumns.specifiedJoinColumns().next(); - assertFalse(specifiedJoinColumn.isDefault()); - - assertNull(joinColumns.getDefaultJoinColumn()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping mapping = (ManyToOneMapping) contextAttribute.getMapping(); - ManyToOneRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(rel.strategyIsJoinColumn()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(rel.strategyIsJoinColumn()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping mapping = (ManyToOneMapping) contextAttribute.getMapping(); - ManyToOneRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(rel.strategyIsJoinColumn()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(rel.strategyIsJoinColumn()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(rel.strategyIsJoinColumn()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertNull(manyToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityGenericizedCollectionType() throws Exception { - createTestEntityWithGenericizedCollectionManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertNull(manyToOneMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getTargetEntity()); - - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", manyToOneMapping.getTargetEntity()); - - manyToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(manyToOneMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertNull(manyToOneMapping.getResolvedTargetEntity()); - - - manyToOneMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - - - manyToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java deleted file mode 100644 index 2ad8cf21bb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java +++ /dev/null @@ -1,288 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.IdClassReference; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaMappedSuperclassTests extends ContextModelTestCase -{ - public JavaMappedSuperclassTests(String name) { - super(name); - } - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - }); - } - - private void createTestIdClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append("TestTypeId").append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter); - } - - public void testMorphToEntity() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - mappedSuperclass.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Entity); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddable() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - mappedSuperclass.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - mappedSuperclass.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMappedSuperclass() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - } - - public void testOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator overridableAttributeNames = mappedSuperclass.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator overridableAssociationNames = mappedSuperclass.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.tableNameIsInvalid(FULLY_QUALIFIED_TYPE_NAME)); - assertFalse(mappedSuperclass.tableNameIsInvalid("FOO")); - } - - public void testAssociatedTables() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.associatedTables().hasNext()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.allAssociatedTables().hasNext()); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.allAssociatedTableNames().hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator overridableAttributeNames = mappedSuperclass.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - //TODO need to create a subclass mappedSuperclass and test this - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator overridableAssociationNames = mappedSuperclass.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testUpdateIdClass() throws Exception { - createTestMappedSuperclass(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - IdClassReference idClassRef = mappedSuperclass.getIdClassReference(); - - assertNull(resourceType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - IdClassAnnotation idClassAnnotation = (IdClassAnnotation) resourceType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - this.getJpaProject().synchronizeContextModel(); - assertNotNull(resourceType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - // test setting id class name to nonexistent class. test class name is set, but class is null - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClassAnnotation.setValue(nonExistentIdClassName); - this.getJpaProject().synchronizeContextModel(); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) resourceType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - // test setting id class name to existent class. test class name is set and class is not null - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClassAnnotation.setValue(existentIdClassName); - this.getJpaProject().synchronizeContextModel(); - assertEquals(existentIdClassName, ((IdClassAnnotation) resourceType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - //test setting @IdClass value to null, IdClass annotation is removed - idClassRef.setSpecifiedIdClassName(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(resourceType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - //reset @IdClass value and then remove @IdClass - idClassAnnotation = (IdClassAnnotation) resourceType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - idClassAnnotation.setValue(existentIdClassName); - resourceType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(resourceType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - createTestMappedSuperclass(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - IdClassReference idClassRef = mappedSuperclass.getIdClassReference(); - - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClassRef.setSpecifiedIdClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClassRef.setSpecifiedIdClassName(existentIdClassName); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - idClassRef.setSpecifiedIdClassName(null); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java deleted file mode 100644 index e3f57529d8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java +++ /dev/null @@ -1,432 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaNamedNativeQueryTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - private static final String QUERY_QUERY = "MY_QUERY"; - - private ICompilationUnit createTestEntityWithNamedNativeQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedNativeQuery(name=\"" + QUERY_NAME + "\", query=\"" + QUERY_QUERY + "\")"); - } - }); - } - - - - public JavaNamedNativeQueryTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedNativeQuery.getName()); - assertEquals(QUERY_NAME, namedNativeQuery.getName()); - - //set name to null in the resource model - javaNamedNativeQuery.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedNativeQuery.getName()); - assertNull(namedNativeQuery.getName()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedNativeQuery.getName()); - assertEquals("foo", namedNativeQuery.getName()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedNativeQuery.getName()); - assertEquals(QUERY_NAME, namedNativeQuery.getName()); - - //set name to null in the context model - namedNativeQuery.setName(null); - assertNull(javaNamedNativeQuery.getName()); - assertNull(namedNativeQuery.getName()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setName("foo"); - assertEquals("foo", javaNamedNativeQuery.getName()); - assertEquals("foo", namedNativeQuery.getName()); - } - - public void testUpdateQuery() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedNativeQuery.getQuery()); - assertEquals(QUERY_QUERY, namedNativeQuery.getQuery()); - - //set name to null in the resource model - javaNamedNativeQuery.setQuery(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedNativeQuery.getQuery()); - assertNull(namedNativeQuery.getQuery()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setQuery("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedNativeQuery.getQuery()); - assertEquals("foo", namedNativeQuery.getQuery()); - } - - public void testModifyQuery() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedNativeQuery.getQuery()); - assertEquals(QUERY_QUERY, namedNativeQuery.getQuery()); - - //set name to null in the context model - namedNativeQuery.setQuery(null); - assertNull(javaNamedNativeQuery.getQuery()); - assertNull(namedNativeQuery.getQuery()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setQuery("foo"); - assertEquals("foo", javaNamedNativeQuery.getQuery()); - assertEquals("foo", namedNativeQuery.getQuery()); - } - - - public void testAddHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - - QueryHint queryHint = namedNativeQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", javaNamedNativeQuery.hintAt(0).getName()); - - QueryHint queryHint2 = namedNativeQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(1).getName()); - - QueryHint queryHint3 = namedNativeQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - - ListIterator hints = namedNativeQuery.getHints().iterator(); - assertEquals(queryHint2, hints.next()); - assertEquals(queryHint3, hints.next()); - assertEquals(queryHint, hints.next()); - - hints = namedNativeQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - } - - public void testRemoveHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - namedNativeQuery.addHint(0).setName("FOO"); - namedNativeQuery.addHint(1).setName("BAR"); - namedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedNativeQuery.hintsSize()); - - namedNativeQuery.removeHint(0); - assertEquals(2, javaNamedNativeQuery.hintsSize()); - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - - namedNativeQuery.removeHint(0); - assertEquals(1, javaNamedNativeQuery.hintsSize()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(0).getName()); - - namedNativeQuery.removeHint(0); - assertEquals(0, javaNamedNativeQuery.hintsSize()); - } - - public void testMoveHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - namedNativeQuery.addHint(0).setName("FOO"); - namedNativeQuery.addHint(1).setName("BAR"); - namedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedNativeQuery.hintsSize()); - - - namedNativeQuery.moveHint(2, 0); - ListIterator hints = namedNativeQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - - - namedNativeQuery.moveHint(0, 1); - hints = namedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAR", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - } - - public void testUpdateHints() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation queryAnnotation = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - queryAnnotation.addHint(0).setName("FOO"); - queryAnnotation.addHint(1).setName("BAR"); - queryAnnotation.addHint(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator hints = namedNativeQuery.getHints().iterator(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - queryAnnotation.moveHint(2, 0); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - queryAnnotation.moveHint(0, 1); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - queryAnnotation.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - queryAnnotation.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - queryAnnotation.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertFalse(namedNativeQuery.getHints().iterator().hasNext()); - } - - public void testHintsSize() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - assertEquals(0, namedNativeQuery.getHintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - - javaNamedNativeQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(1, namedNativeQuery.getHintsSize()); - - javaNamedNativeQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(2, namedNativeQuery.getHintsSize()); - - javaNamedNativeQuery.removeHint(0); - javaNamedNativeQuery.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(0, namedNativeQuery.getHintsSize()); - } - - public void testUpdateResultClass() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation queryAnnotation = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, queryAnnotation.getResultClass()); - assertEquals(null, namedNativeQuery.getResultClass()); - - //set name in the resource model, verify context model updated - queryAnnotation.setResultClass("foo"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("foo", queryAnnotation.getResultClass()); - assertEquals("foo", namedNativeQuery.getResultClass()); - - //set name to null in the resource model - queryAnnotation.setResultClass(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(queryAnnotation.getResultClass()); - assertNull(namedNativeQuery.getResultClass()); - } - - public void testModifyResultClass() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultClass()); - assertEquals(null, namedNativeQuery.getResultClass()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setResultClass("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultClass()); - assertEquals("foo", namedNativeQuery.getResultClass()); - - //set name to null in the context model - namedNativeQuery.setResultClass(null); - assertNull(javaNamedNativeQuery.getResultClass()); - assertNull(namedNativeQuery.getResultClass()); - } - - public void testUpdateResultSetMapping() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultSetMapping()); - assertEquals(null, namedNativeQuery.getResultSetMapping()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setResultSetMapping("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedNativeQuery.getResultSetMapping()); - assertEquals("foo", namedNativeQuery.getResultSetMapping()); - - //set name to null in the resource model - javaNamedNativeQuery.setResultSetMapping(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedNativeQuery.getResultSetMapping()); - assertNull(namedNativeQuery.getResultSetMapping()); - } - - public void testModifyResultSetMapping() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultSetMapping()); - assertEquals(null, namedNativeQuery.getResultSetMapping()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setResultSetMapping("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultSetMapping()); - assertEquals("foo", namedNativeQuery.getResultSetMapping()); - - //set name to null in the context model - namedNativeQuery.setResultSetMapping(null); - assertNull(javaNamedNativeQuery.getResultSetMapping()); - assertNull(namedNativeQuery.getResultSetMapping()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java deleted file mode 100644 index d3ad196db5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java +++ /dev/null @@ -1,333 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaNamedQueryTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - private static final String QUERY_QUERY = "MY_QUERY"; - - private ICompilationUnit createTestEntityWithNamedQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedQuery(name=\"" + QUERY_NAME + "\", query=\"" + QUERY_QUERY + "\")"); - } - }); - } - - - - public JavaNamedQueryTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedQuery.getName()); - assertEquals(QUERY_NAME, namedQuery.getName()); - - //set name to null in the resource model - javaNamedQuery.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedQuery.getName()); - assertNull(namedQuery.getName()); - - //set name in the resource model, verify context model updated - javaNamedQuery.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedQuery.getName()); - assertEquals("foo", namedQuery.getName()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedQuery.getName()); - assertEquals(QUERY_NAME, namedQuery.getName()); - - //set name to null in the context model - namedQuery.setName(null); - assertNull(javaNamedQuery.getName()); - assertNull(namedQuery.getName()); - - //set name in the context model, verify resource model updated - namedQuery.setName("foo"); - assertEquals("foo", javaNamedQuery.getName()); - assertEquals("foo", namedQuery.getName()); - } - - public void testUpdateQuery() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedQuery.getQuery()); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - //set name to null in the resource model - javaNamedQuery.setQuery(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedQuery.getQuery()); - assertNull(namedQuery.getQuery()); - - //set name in the resource model, verify context model updated - javaNamedQuery.setQuery("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedQuery.getQuery()); - assertEquals("foo", namedQuery.getQuery()); - } - - public void testModifyQuery() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedQuery.getQuery()); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - //set name to null in the context model - namedQuery.setQuery(null); - assertNull(javaNamedQuery.getQuery()); - assertNull(namedQuery.getQuery()); - - //set name in the context model, verify resource model updated - namedQuery.setQuery("foo"); - assertEquals("foo", javaNamedQuery.getQuery()); - assertEquals("foo", namedQuery.getQuery()); - } - - - public void testAddHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - - QueryHint queryHint = namedQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", javaNamedQuery.hintAt(0).getName()); - - QueryHint queryHint2 = namedQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(1).getName()); - - QueryHint queryHint3 = namedQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - - ListIterator hints = namedQuery.getHints().iterator(); - assertEquals(queryHint2, hints.next()); - assertEquals(queryHint3, hints.next()); - assertEquals(queryHint, hints.next()); - - hints = namedQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - } - - public void testRemoveHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1).setName("BAR"); - namedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedQuery.hintsSize()); - - namedQuery.removeHint(0); - assertEquals(2, javaNamedQuery.hintsSize()); - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - - namedQuery.removeHint(0); - assertEquals(1, javaNamedQuery.hintsSize()); - assertEquals("BAZ", javaNamedQuery.hintAt(0).getName()); - - namedQuery.removeHint(0); - assertEquals(0, javaNamedQuery.hintsSize()); - } - - public void testMoveHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1).setName("BAR"); - namedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedQuery.hintsSize()); - - - namedQuery.moveHint(2, 0); - ListIterator hints = namedQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - - - namedQuery.moveHint(0, 1); - hints = namedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAR", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - } - - public void testUpdateHints() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation namedQueryAnnotation = (NamedQueryAnnotation) resourceType.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - namedQueryAnnotation.addHint(0).setName("FOO"); - namedQueryAnnotation.addHint(1).setName("BAR"); - namedQueryAnnotation.addHint(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator hints = namedQuery.getHints().iterator(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryAnnotation.moveHint(2, 0); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryAnnotation.moveHint(0, 1); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryAnnotation.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryAnnotation.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryAnnotation.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertFalse(namedQuery.getHints().iterator().hasNext()); - } - - public void testHintsSize() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - assertEquals(0, namedQuery.getHintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - - javaNamedQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(1, namedQuery.getHintsSize()); - - javaNamedQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(2, namedQuery.getHintsSize()); - - javaNamedQuery.removeHint(0); - javaNamedQuery.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(0, namedQuery.getHintsSize()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java deleted file mode 100644 index bf74fa08c6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java +++ /dev/null @@ -1,1160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToManyRelationship; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaOneToManyMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonCollectionOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Address addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("import java.util.Map;"); - sb.append(CR); - sb.append("import ").append(JPA.ONE_TO_MANY).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Map employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - public JavaOneToManyMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToManyAnnotation = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToManyAnnotation.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToManyAnnotation.setTargetEntity("newTargetEntity"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("newTargetEntity", oneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToManyAnnotation.getTargetEntity()); - - //set target entity to null in the resource model - oneToManyAnnotation.setTargetEntity(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToManyAnnotation.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - oneToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the context model - oneToManyMapping.setSpecifiedTargetEntity(null); - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToMany.getFetch()); - - - //set fetch to null in the resource model - oneToMany.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - - //set fetch in the context model, verify resource model updated - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToMany.getFetch()); - - oneToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToMany.getFetch()); - - //set fetch to null in the context model - oneToManyMapping.setSpecifiedFetch(null); - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToMany.setMappedBy("newMappedBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newMappedBy", oneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //set mappedBy to null in the resource model - oneToMany.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertEquals("newTargetEntity", oneToMany.getMappedBy()); - - //set mappedBy to null in the context model - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute(null); - assertNull(oneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - } - - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - //TODO this needs to return null for 1.0 mappings. we want the validation error for dot-notation since this is only supported in 2.0 - //TODO need to copy this to all the other mapped by tests. - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping mapping = (OneToManyMapping) contextAttribute.getMapping(); - OneToManyRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping mapping = (OneToManyMapping) contextAttribute.getMapping(); - OneToManyRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityNonCollectionType() throws Exception { - createTestEntityWithNonCollectionOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getTargetEntity()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", oneToManyMapping.getTargetEntity()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(oneToManyMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertNull(oneToManyMapping.getResolvedTargetEntity()); - - - oneToManyMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - - - oneToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - } - - - public void testUpdateMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKeyAnnotation.getName()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKey(null); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKeyAnnotation.getName()); - oneToManyMapping.setNoMapKey(true); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = - javaOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = javaOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = javaOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testUpdateOrderBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newOrderBy", oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", orderBy.getValue()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyOrderBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set mappedBy in the context model, verify resource model updated - oneToManyMapping.getOrderable().setSpecifiedOrderBy("newOrderBy"); - assertEquals("newOrderBy", oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertEquals("newOrderBy", orderBy.getValue()); - - //set mappedBy to null in the context model - oneToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateNoOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertTrue(oneToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isNoOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isNoOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(oneToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdatePkOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(oneToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(oneToManyMapping.getOrderable().isPkOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isPkOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateCustomOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(oneToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.getOrderable().isCustomOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertTrue(oneToManyMapping.getOrderable().isCustomOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultTargetEntityForMap() throws Exception { - createTestEmployee(); - createTestDepartment(); - addXmlClassRef(PACKAGE_NAME + ".Department"); - addXmlClassRef(PACKAGE_NAME + ".Employee"); - - JavaPersistentType departmentPersistentType = getJavaPersistentType(); - OneToManyMapping employeesMapping = (OneToManyMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - assertEquals(PACKAGE_NAME + ".Employee", employeesMapping.getTargetEntity()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java deleted file mode 100644 index 70d0e3183a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java +++ /dev/null @@ -1,1511 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.MappedByRelationshipStrategy; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.OneToOneRelationship; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaOneToOneMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericizedCollectionOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - public JavaOneToOneMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOneAnnotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOneAnnotation.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToOneAnnotation.setTargetEntity("newTargetEntity"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("newTargetEntity", oneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOneAnnotation.getTargetEntity()); - - //set target entity to null in the resource model - oneToOneAnnotation.setTargetEntity(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOneAnnotation.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - oneToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the context model - oneToOneMapping.setSpecifiedTargetEntity(null); - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - MappedByRelationshipStrategy mappedBy = oneToOneMapping.getRelationship().getMappedByStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToOne.setMappedBy("newMappedBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newMappedBy", mappedBy.getMappedByAttribute()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the resource model - oneToOne.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - MappedByRelationshipStrategy mappedBy = oneToOneMapping.getRelationship().getMappedByStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - - //set mappedByJoiningStrategy in the context model, verify resource model updated - mappedBy.setMappedByAttribute("newTargetEntity"); - assertEquals("newTargetEntity", mappedBy.getMappedByAttribute()); - assertEquals("newTargetEntity", oneToOne.getMappedBy()); - - //set mappedByJoiningStrategy to null in the context model - mappedBy.setMappedByAttribute(null); - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - - //set optional in the resource model, verify context model updated - oneToOne.setOptional(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - - //set optional to null in the resource model - oneToOne.setOptional(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - - //set optional in the context model, verify resource model updated - oneToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - - //set optional to null in the context model - oneToOneMapping.setSpecifiedOptional(null); - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToOne.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToOne.getFetch()); - - //set fetch to null in the resource model - oneToOne.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - - //set fetch in the context model, verify resource model updated - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToOne.getFetch()); - - oneToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToOne.getFetch()); - - //set fetch to null in the context model - oneToOneMapping.setSpecifiedFetch(null); - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - } - - public void testSpecifiedJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - ListIterator specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - - assertFalse(specifiedJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertFalse(specifiedJoinColumns.hasNext()); - } - - public void testGetDefaultJoin() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(2, joinColumns.joinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - - //if non-owning side of the relationship then no default join column - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("foo"); - assertEquals(0, joinColumns.joinColumnsSize()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator joinColumnsIterator = - attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testAddSpecifiedJoinColumn2() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator joinColumnsIterator = - attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME))); - - joinColumns.removeSpecifiedJoinColumn(1); - - Iterator joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(1); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - - assertNull(attributeResource.getAnnotation(JoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - Iterator javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - joinColumns.moveSpecifiedJoinColumn(2, 0); - ListIterator primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - - - joinColumns.moveSpecifiedJoinColumn(0, 1); - primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - ((JoinColumnAnnotation) attributeResource.addAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(2, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(2, 0, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(0, 1, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testJoinColumnIsVirtual() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnRelationshipStrategy joinColumns = oneToOneMapping.getRelationship().getJoinColumnStrategy(); - - assertTrue(joinColumns.getDefaultJoinColumn().isDefault()); - - joinColumns.addSpecifiedJoinColumn(0); - JoinColumn specifiedJoinColumn = joinColumns.specifiedJoinColumns().next(); - assertFalse(specifiedJoinColumn.isDefault()); - - assertNull(joinColumns.getDefaultJoinColumn()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertNull(oneToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityGenericizedCollectionType() throws Exception { - createTestEntityWithGenericizedCollectionOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertNull(oneToOneMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getTargetEntity()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", oneToOneMapping.getTargetEntity()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(oneToOneMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertNull(oneToOneMapping.getResolvedTargetEntity()); - - - oneToOneMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - - - oneToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - } - - public void testPrimaryKeyJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnRelationshipStrategy strategy = - oneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - Iterator primaryKeyJoinColumns = CollectionTools.iterable(strategy.primaryKeyJoinColumns()).iterator(); - - assertFalse(primaryKeyJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertFalse(primaryKeyJoinColumns.hasNext()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnRelationshipStrategy strategy = - oneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - - assertEquals(0, strategy.primaryKeyJoinColumnsSize()); - - strategy.addPrimaryKeyJoinColumn(0); - assertEquals(1, strategy.primaryKeyJoinColumnsSize()); - - strategy.removePrimaryKeyJoinColumn(0); - assertEquals(0, strategy.primaryKeyJoinColumnsSize()); - } - - public void testAddPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnRelationshipStrategy strategy = - oneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator joinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testAddPrimaryKeyJoinColumn2() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnRelationshipStrategy strategy = - oneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator joinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testRemovePrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnRelationshipStrategy strategy = - oneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME))); - - strategy.removePrimaryKeyJoinColumn(1); - - Iterator joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator joinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - strategy.removePrimaryKeyJoinColumn(1); - joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - strategy.removePrimaryKeyJoinColumn(0); - joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumns = (Iterator) strategy.primaryKeyJoinColumns(); - assertFalse(joinColumns.hasNext()); - - assertNull(attributeResource.getAnnotation(PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMovePrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnRelationshipStrategy strategy = - oneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - Iterator javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - strategy.movePrimaryKeyJoinColumn(2, 0); - ListIterator primaryKeyJoinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - - - strategy.movePrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnRelationshipStrategy strategy = - oneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator joinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.moveAnnotation(2, 0, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.moveAnnotation(0, 1, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) strategy.primaryKeyJoinColumns(); - assertFalse(joinColumns.hasNext()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping mapping = (OneToOneMapping) contextAttribute.getMapping(); - OneToOneRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping mapping = (OneToOneMapping) contextAttribute.getMapping(); - OneToOneRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java deleted file mode 100644 index fc187a2ebe..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,303 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase -{ - private static final String PRIMARY_KEY_JOIN_COLUMN_NAME = "MY_PRIMARY_KEY_JOIN_COLUMN"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithPrimaryKeyJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@PrimaryKeyJoinColumn(name=\"" + PRIMARY_KEY_JOIN_COLUMN_NAME + "\")"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public JavaPrimaryKeyJoinColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getSpecifiedName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getName()); - } - - public void testGetDefaultNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn pkJoinColumn = getJavaEntity().getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", pkJoinColumn.getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("id", specifiedPkJoinColumn.getDefaultName()); - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(specifiedPkJoinColumn.getDefaultName()); - } - - public void testGetName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - - specifiedPkJoinColumn.setSpecifiedName("foo"); - assertEquals("foo", specifiedPkJoinColumn.getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation columnAnnotation = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", columnAnnotation.getName()); - - specifiedPkJoinColumn.setSpecifiedName(null); - assertNull(specifiedPkJoinColumn.getSpecifiedName()); - columnAnnotation = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(columnAnnotation.getName()); - } - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - column.setColumnDefinition(COLUMN_DEFINITION); - getJpaProject().synchronizeContextModel(); - - assertEquals(COLUMN_DEFINITION, specifiedPkJoinColumn.getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - - assertNull(specifiedPkJoinColumn.getColumnDefinition()); - - typeResource.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - - assertEquals(0, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - specifiedPkJoinColumn.setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - specifiedPkJoinColumn.setColumnDefinition(null); - column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(column.getColumnDefinition()); - } - - public void testGetSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setReferencedColumnName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testGetDefaultReferencedColumnNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn pkJoinColumn = getJavaEntity().getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", pkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testGetDefaultReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("id", specifiedPkJoinColumn.getDefaultReferencedColumnName()); - - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(specifiedPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testGetReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setReferencedColumnName("FOO"); - getJpaProject().synchronizeContextModel(); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getReferencedColumnName()); - } - - public void testSetSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation columnAnnotation = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", columnAnnotation.getReferencedColumnName()); - - specifiedPkJoinColumn.setSpecifiedName(null); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName(null); - assertNull(specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - columnAnnotation = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(columnAnnotation.getReferencedColumnName()); - } - - public void testIsVirtual() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isDefault()); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(0); - assertTrue(getJavaEntity().getDefaultPrimaryKeyJoinColumn().isDefault()); - } - - public void testIsReferencedColumnResolved() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(((Boolean) ReflectionTools.executeMethod(specifiedPkJoinColumn, "referencedColumnIsResolved")).booleanValue()); - } - - public void testDbColumn() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isResolved()); - } - - public void testDbReferencedColumn() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(((Boolean) ReflectionTools.executeMethod(specifiedPkJoinColumn, "referencedColumnIsResolved")).booleanValue()); - } - - public void testDbTable() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getDbTable()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java deleted file mode 100644 index d215f3fbd5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaQueryHintTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - - private ICompilationUnit createTestEntityWithNamedQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedQuery(name=\"" + QUERY_NAME + "\", hints=@QueryHint())"); - } - }); - } - - - - public JavaQueryHintTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().getHints().iterator().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation queryHintAnnotation = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(queryHintAnnotation.getName()); - assertNull(queryHint.getName()); - - //set name in the resource model, verify context model updated - queryHintAnnotation.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", queryHintAnnotation.getName()); - assertEquals("foo", queryHint.getName()); - - //set name to null in the resource model - queryHintAnnotation.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(queryHint.getName()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().getHints().iterator().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getName()); - assertNull(queryHint.getName()); - - //set name in the context model, verify resource model updated - queryHint.setName("foo"); - assertEquals("foo", javaQueryhint.getName()); - assertEquals("foo", queryHint.getName()); - - //set name to null in the context model - queryHint.setName(null); - assertNull(javaQueryhint.getName()); - assertNull(queryHint.getName()); - } - - public void testUpdateValue() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().getHints().iterator().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation queryHintAnnotation = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(queryHintAnnotation.getValue()); - assertNull(queryHint.getValue()); - - //set name in the resource model, verify context model updated - queryHintAnnotation.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", queryHintAnnotation.getValue()); - assertEquals("foo", queryHint.getValue()); - - //set name to null in the resource model - queryHintAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNull(queryHint.getValue()); - } - - public void testModifyValue() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().getHints().iterator().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - - //set name in the context model, verify resource model updated - queryHint.setValue("foo"); - assertEquals("foo", javaQueryhint.getValue()); - assertEquals("foo", queryHint.getValue()); - - //set name to null in the context model - queryHint.setValue(null); - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java deleted file mode 100644 index f599411a71..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java +++ /dev/null @@ -1,730 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaSecondaryTableTests extends ContextModelTestCase -{ - private static final String TABLE_NAME = "MY_TABLE"; - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTable(name=\"" + TABLE_NAME + "\")"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name=\"foo\"), @SecondaryTable(name=\"bar\")})"); - } - }); - } - - - - - public JavaSecondaryTableTests(String name) { - super(name); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - assertEquals(TABLE_NAME, secondaryTable.getSpecifiedName()); - } - - public void testGetDefaultNameNull() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - assertNull(secondaryTable.getDefaultName()); - } - - public void testGetName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - assertEquals(TABLE_NAME, secondaryTable.getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - secondaryTable.setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().secondaryTables().next().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("foo", table.getName()); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - table.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().secondaryTables().next().getSpecifiedName()); - } - - public void testUpdateFromSpecifiedCatalogChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator secondaryTableResources = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setCatalog("foo"); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setCatalog("bar"); - getJpaProject().synchronizeContextModel(); - - ListIterator secondaryTsbles = getJavaEntity().secondaryTables(); - assertEquals("foo", secondaryTsbles.next().getSpecifiedCatalog()); - assertEquals("bar", secondaryTsbles.next().getSpecifiedCatalog()); - } - - public void testUpdateFromSpecifiedSchemaChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator secondaryTableResources = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setSchema("foo"); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setSchema("bar"); - getJpaProject().synchronizeContextModel(); - - ListIterator secondaryTsbles = getJavaEntity().secondaryTables(); - assertEquals("foo", secondaryTsbles.next().getSpecifiedSchema()); - assertEquals("bar", secondaryTsbles.next().getSpecifiedSchema()); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.setCatalog("myCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myCatalog", getJavaEntity().secondaryTables().next().getSpecifiedCatalog()); - assertEquals("myCatalog", getJavaEntity().secondaryTables().next().getCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultCatalog()); - - getJavaEntity().secondaryTables().next().setSpecifiedCatalog("myCatalog"); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable table = getJavaEntity().secondaryTables().next(); - table.setSpecifiedCatalog("myCatalog"); - table.setSpecifiedName(null); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableAnnotation = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals("myCatalog", tableAnnotation.getCatalog()); - } - - public void testGetSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - tableResource.setSchema("mySchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySchema", getJavaEntity().secondaryTables().next().getSpecifiedSchema()); - assertEquals("mySchema", getJavaEntity().secondaryTables().next().getSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultSchema()); - - getJavaEntity().secondaryTables().next().setSpecifiedSchema("mySchema"); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable table = getJavaEntity().secondaryTables().next(); - table.setSpecifiedSchema("mySchema"); - table.setSpecifiedName(null); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableAnnotation = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals("mySchema", tableAnnotation.getSchema()); - } - - public void testSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - ListIterator specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - - assertFalse(specifiedPkJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation pkJoinColumn = tableResource.addPkJoinColumn(0); - pkJoinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - pkJoinColumn = tableResource.addPkJoinColumn(0); - pkJoinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - //move an annotation to the resource model and verify the context model is updated - tableResource.movePkJoinColumn(1, 0); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - tableResource.removePkJoinColumn(0); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - tableResource.removePkJoinColumn(0); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertFalse(specifiedPkJoinColumns.hasNext()); - } - - public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - assertEquals(0, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - //just the default pkJoinColumn, so 1 - assertEquals(1, secondaryTable.primaryKeyJoinColumnsSize()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - //only the specified pkJoinColumns, 3 - assertEquals(3, secondaryTable.primaryKeyJoinColumnsSize()); - } - - public void testGetDefaultPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - assertNotNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - } - - public void testPrimaryKeyJoinColumnDefaults() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertNotNull(defaultPkJoinColumn); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - - IdMapping idMapping = (IdMapping) getJavaEntity().getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - assertEquals("FOO", defaultPkJoinColumn.getDefaultName()); - assertEquals("FOO", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - idMapping.getColumn().setSpecifiedName(null); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - Iterator specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn2() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - } - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, tableResource.pkJoinColumnsSize()); - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(1); - - Iterator pkJoinColumnResources = tableResource.pkJoinColumns(); - assertEquals("FOO", pkJoinColumnResources.next().getName()); - assertEquals("BAZ", pkJoinColumnResources.next().getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - Iterator pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(1); - pkJoinColumnResources = tableResource.pkJoinColumns(); - assertEquals("FOO", pkJoinColumnResources.next().getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumnResources = tableResource.pkJoinColumns(); - assertFalse(pkJoinColumnResources.hasNext()); - pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertFalse(pkJoinColumns.hasNext()); - - assertEquals(0, tableResource.pkJoinColumnsSize()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - - - secondaryTable.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertEquals("FOO", pkJoinColumns.next().getName()); - } - - public void testPrimaryKeyJoinColumnGetDefaultName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(defaultPkJoinColumn.getDefaultName()); - } - public void testPrimaryKeyJoinColumnGetDefaultReferencedColumnName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(defaultPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testPrimaryKeyJoinColumnIsVirtual() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - assertTrue(secondaryTable.getDefaultPrimaryKeyJoinColumn().isDefault()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumn specifiedPkJoinColumn = secondaryTable.specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isDefault()); - - assertNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - } - - - public void testUniqueConstraints() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - ListIterator uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - assertEquals(0, secondaryTable.uniqueConstraintsSize()); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - secondaryTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, secondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - ListIterator uniqueConstraints = secondaryTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - ListIterator uniqueConstraints = secondaryTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, secondaryTableAnnotation.uniqueConstraintsSize()); - - secondaryTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - secondaryTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - secondaryTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, secondaryTableAnnotation.uniqueConstraintsSize()); - - - secondaryTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - secondaryTable.moveUniqueConstraint(0, 1); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaSecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - secondaryTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - secondaryTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - - ListIterator uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java deleted file mode 100644 index 2efcd902e6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaSequenceGeneratorTests extends ContextModelTestCase -{ - private static final String SEQUENCE_GENERATOR_NAME = "MY_SEQUENCE_GENERATOR"; - - - protected ICompilationUnit createTestEntityWithSequenceGenerator() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SEQUENCE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@SequenceGenerator(name=\"" + SEQUENCE_GENERATOR_NAME + "\")"); - } - }); - } - - public JavaSequenceGeneratorTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName("foo"); - - assertEquals("foo", idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals("foo", sequenceGenerator.getName()); - } - - public void testGetInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getSequenceGenerator().getInitialValue()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setInitialValue(Integer.valueOf(82)); - getJpaProject().synchronizeContextModel(); - - assertEquals(82, idMapping.getGeneratorContainer().getSequenceGenerator().getInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedInitialValue()); - } - - public void testGetDefaultInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultInitialValue()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedInitialValue(Integer.valueOf(82)); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedInitialValue()); - } - - public void testSetSpecifiedInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedInitialValue(Integer.valueOf(20)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation generatorAnnotation = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals(Integer.valueOf(20), generatorAnnotation.getInitialValue()); - } - - public void testGetAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getSequenceGenerator().getAllocationSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setAllocationSize(Integer.valueOf(20)); - getJpaProject().synchronizeContextModel(); - - assertEquals(20, idMapping.getGeneratorContainer().getSequenceGenerator().getAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedAllocationSize()); - } - - public void testGetDefaultAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultAllocationSize()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedAllocationSize(Integer.valueOf(20)); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedAllocationSize()); - } - - public void testSetSpecifiedAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedAllocationSize(Integer.valueOf(25)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation generatorAnnotation = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals(Integer.valueOf(25), generatorAnnotation.getAllocationSize()); - } - - - - public void testGetSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator().getSequenceName()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setSequenceName("mySequenceName"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySequenceName", idMapping.getGeneratorContainer().getSequenceGenerator().getSequenceName()); - assertEquals("mySequenceName", idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedSequenceName()); - } - - public void testGetDefaultSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultSequenceName()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedSequenceName("mySequenceName"); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultSequenceName()); - assertEquals("mySequenceName", idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedSequenceName()); - } - - public void testSetSpecifiedSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedSequenceName("mySequenceName"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation generatorAnnotation = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals("mySequenceName", generatorAnnotation.getSequenceName()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName(null); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedSequenceName(null); - generatorAnnotation = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertNull(generatorAnnotation.getName()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java deleted file mode 100644 index 6d5c632354..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java +++ /dev/null @@ -1,671 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaTableGeneratorTests extends ContextModelTestCase -{ - private static final String TABLE_GENERATOR_NAME = "MY_TABLE_GENERATOR"; - - private ICompilationUnit createTestEntityWithTableGenerator() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TABLE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@TableGenerator(name=\"" + TABLE_GENERATOR_NAME + "\")"); - } - }); - } - - public JavaTableGeneratorTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getGeneratorContainer().getTableGenerator().getName()); - - //change resource model tableGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getGeneratorContainer().getTableGenerator().getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getGeneratorContainer().getTableGenerator().getName()); - - idMapping.getGeneratorContainer().getTableGenerator().setName("foo"); - - assertEquals("foo", idMapping.getGeneratorContainer().getTableGenerator().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("foo", tableGenerator.getName()); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getCatalog()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setCatalog("myCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myCatalog", idMapping.getGeneratorContainer().getTableGenerator().getCatalog()); - assertEquals("myCatalog", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultCatalog()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedCatalog("myCatalog"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultCatalog()); - assertEquals("myCatalog", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedCatalog("myCatalog"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation generatorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myCatalog", generatorAnnotation.getCatalog()); - } - - public void testGetSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getSchema()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setSchema("mySchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySchema", idMapping.getGeneratorContainer().getTableGenerator().getSchema()); - assertEquals("mySchema", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedSchema("mySchema"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - assertEquals("mySchema", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntityWithTableGenerator(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - IdMapping idMapping = (IdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - getEntityMappings().removePersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedSchema("mySchema"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation generatorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("mySchema", generatorAnnotation.getSchema()); - } - - public void testGetPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getPkColumnName()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setPkColumnName("myPkColumnName"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myPkColumnName", idMapping.getGeneratorContainer().getTableGenerator().getPkColumnName()); - assertEquals("myPkColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnName()); - } - - public void testGetDefaultPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnName()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnName("myPkColumnName"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnName()); - assertEquals("myPkColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnName()); - } - - public void testSetSpecifiedPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnName("myPkColumnName"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation generatorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myPkColumnName", generatorAnnotation.getPkColumnName()); - } - - public void testGetValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getValueColumnName()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setValueColumnName("myValueColumnName"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myValueColumnName", idMapping.getGeneratorContainer().getTableGenerator().getValueColumnName()); - assertEquals("myValueColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedValueColumnName()); - } - - public void testGetDefaultValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultValueColumnName()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedValueColumnName("myValueColumnName"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultValueColumnName()); - assertEquals("myValueColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedValueColumnName()); - } - - public void testSetSpecifiedValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedValueColumnName("myValueColumnName"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation generatorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myValueColumnName", generatorAnnotation.getValueColumnName()); - } - - public void testGetPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getPkColumnValue()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setPkColumnValue("myPkColumnValue"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myPkColumnValue", idMapping.getGeneratorContainer().getTableGenerator().getPkColumnValue()); - assertEquals("myPkColumnValue", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnValue()); - } - - public void testGetDefaultPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnValue()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnValue("myPkColumnValue"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnValue()); - assertEquals("myPkColumnValue", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnValue()); - } - - public void testSetSpecifiedPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnValue("myPkColumnValue"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation generatorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myPkColumnValue", generatorAnnotation.getPkColumnValue()); - } - - public void testGetInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getTableGenerator().getInitialValue()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setInitialValue(Integer.valueOf(82)); - getJpaProject().synchronizeContextModel(); - - assertEquals(82, idMapping.getGeneratorContainer().getTableGenerator().getInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedInitialValue()); - } - - public void testGetDefaultInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultInitialValue()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedInitialValue(Integer.valueOf(82)); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedInitialValue()); - } - - public void testSetSpecifiedInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedInitialValue(Integer.valueOf(20)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation generatorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(Integer.valueOf(20), generatorAnnotation.getInitialValue()); - } - - public void testGetAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getTableGenerator().getAllocationSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setAllocationSize(Integer.valueOf(20)); - getJpaProject().synchronizeContextModel(); - - assertEquals(20, idMapping.getGeneratorContainer().getTableGenerator().getAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedAllocationSize()); - } - - public void testGetDefaultAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultAllocationSize()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedAllocationSize(Integer.valueOf(20)); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedAllocationSize()); - } - - public void testSetSpecifiedAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedAllocationSize(Integer.valueOf(25)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation generatorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(Integer.valueOf(25), generatorAnnotation.getAllocationSize()); - } - - - public void testUniqueConstraints() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaTableGenerator tableGenerator =(JavaTableGenerator) ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - - assertEquals(0, tableGenerator.getUniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableGeneratorAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, tableGenerator.getUniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - ListIterator uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - ListIterator uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGeneratorAnnotation.uniqueConstraintsSize()); - - tableGenerator.removeUniqueConstraint(1); - - ListIterator uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(1); - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(0); - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGeneratorAnnotation.uniqueConstraintsSize()); - - - tableGenerator.moveUniqueConstraint(2, 0); - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - tableGenerator.moveUniqueConstraint(0, 1); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - tableGeneratorAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - tableGeneratorAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java deleted file mode 100644 index 29eb4f28d3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java +++ /dev/null @@ -1,610 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaTableTests extends ContextModelTestCase -{ - private static final String TABLE_NAME = "MY_TABLE"; - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Table(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestSubType() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createAbstractTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - sb.append("abstract"); - } - }); - } - - - public JavaTableTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getTable().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, getJavaEntity().getTable().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getTable().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getTable().getDefaultName()); - - //test that setting the java entity name will change the table default name - getJavaEntity().setSpecifiedName("foo"); - assertEquals("foo", getJavaEntity().getTable().getDefaultName()); - } - - public void testGetDefaultNameSingleTableInheritance() throws Exception { - createTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertNotSame(getJavaEntity(), rootEntity); - assertEquals(TYPE_NAME, childEntity.getTable().getDefaultName()); - assertEquals(TYPE_NAME, rootEntity.getTable().getDefaultName()); - - //test that setting the root java entity name will change the table default name of the child - rootEntity.setSpecifiedName("foo"); - assertEquals("foo", childEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - JavaEntity javaEntity = ormEntity.getJavaTypeMapping(); - - assertNull(javaEntity.getTable().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", javaEntity.getTable().getDefaultSchema()); - - getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", javaEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", javaEntity.getTable().getDefaultSchema()); - - getEntityMappings().removePersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", getJavaEntity().getTable().getDefaultSchema()); - - IFile file = getOrmXmlResource().getFile(); - //remove the mapping file reference from the persistence.xml. default schema - //should still come from persistence-unit-defaults because of implied mapped-file-ref - getXmlPersistenceUnit().getMappingFiles().remove(mappingFileRef); - assertEquals("FOO", getJavaEntity().getTable().getDefaultSchema()); - - file.delete(true, null); - assertNull(getJavaEntity().getTable().getDefaultSchema()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getTable().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, getJavaEntity().getTable().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getTable().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getTable().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("foo", table.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getTable().setSpecifiedName(null); - - assertNull(getJavaEntity().getTable().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertNull(table); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - table.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getTable().getSpecifiedName()); - - typeResource.removeAnnotation(JPA.TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getTable().getSpecifiedName()); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.setCatalog("myCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myCatalog", getJavaEntity().getTable().getSpecifiedCatalog()); - assertEquals("myCatalog", getJavaEntity().getTable().getCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getTable().getDefaultCatalog()); - - getJavaEntity().getTable().setSpecifiedCatalog("myCatalog"); - - assertNull(getJavaEntity().getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - JavaEntity javaEntity = ormEntity.getJavaTypeMapping(); - - assertNull(javaEntity.getTable().getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", javaEntity.getTable().getDefaultCatalog()); - - getEntityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", javaEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedCatalog("XML_CATALOG"); - assertEquals("BAR", javaEntity.getTable().getDefaultCatalog()); - - getEntityMappings().removePersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default catalog taken from persistence-unite-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", getJavaEntity().getTable().getDefaultCatalog()); - - IFile file = getOrmXmlResource().getFile(); - //remove the mapping file reference from the persistence.xml. default schema - //should still come from persistence-unit-defaults because of implied mapped-file-ref - getXmlPersistenceUnit().getMappingFiles().remove(mappingFileRef); - assertEquals("FOO", getJavaEntity().getTable().getDefaultCatalog()); - - file.delete(true, null); - assertNull(getJavaEntity().getTable().getDefaultCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Table table = getJavaEntity().getTable(); - table.setSpecifiedCatalog("myCatalog"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("myCatalog", tableResource.getCatalog()); - - table.setSpecifiedCatalog(null); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testGetSchema() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.setSchema("mySchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySchema", getJavaEntity().getTable().getSpecifiedSchema()); - assertEquals("mySchema", getJavaEntity().getTable().getSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getTable().getDefaultSchema()); - - getJavaEntity().getTable().setSpecifiedSchema("mySchema"); - - assertNull(getJavaEntity().getTable().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Table table = getJavaEntity().getTable(); - table.setSpecifiedSchema("mySchema"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("mySchema", tableResource.getSchema()); - - table.setSpecifiedSchema(null); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testUniqueConstraints() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator uniqueConstraints = getJavaEntity().getTable().uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = getJavaEntity().getTable().uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getTable().uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, getJavaEntity().getTable().uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(0).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - ListIterator uniqueConstraints = tableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - ListIterator uniqueConstraints = tableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaTable table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, tableAnnotation.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - - ListIterator uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(1); - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(0); - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaTable table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, tableAnnotation.uniqueConstraintsSize()); - - - table.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - table.moveUniqueConstraint(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaTable table = getJavaEntity().getTable(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - tableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - tableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - tableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAbstractEntityGetDefaultNameTablePerClassInheritance() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getSpecifiedInheritanceStrategy()); - assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy()); - - - assertEquals(null, abstractEntity.getTable().getDefaultName()); - assertEquals(null, abstractEntity.getTable().getDefaultCatalog()); - assertEquals(null, abstractEntity.getTable().getDefaultSchema()); - - - assertEquals("AnnotationTestTypeChild", concreteEntity.getTable().getDefaultName()); - assertEquals(null, concreteEntity.getTable().getDefaultCatalog()); - assertEquals(null, concreteEntity.getTable().getDefaultSchema()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java deleted file mode 100644 index 859554b87c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java +++ /dev/null @@ -1,249 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaTransientMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithTransientMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TRANSIENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient").append(CR); - } - }); - } - - public JavaTransientMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - } - - public void testTransientMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - - assertNotNull(transientMapping); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java deleted file mode 100644 index 44a68cb305..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java +++ /dev/null @@ -1,400 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class JavaVersionMappingTests extends ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithVersionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - public JavaVersionMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - - public void testGetTemporal() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) versionMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertNull(versionMapping.getConverter().getType()); - - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - versionMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - - assertNull(versionMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.DATE, ((TemporalConverter) versionMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(versionMapping.getConverter().getType()); - assertFalse(versionMapping.isDefault()); - assertSame(versionMapping, persistentAttribute.getMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - - assertNull(versionMapping.getColumn().getSpecifiedName()); - assertEquals("id", versionMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", versionMapping.getColumn().getSpecifiedName()); - assertEquals("foo", versionMapping.getColumn().getName()); - assertEquals("id", versionMapping.getColumn().getDefaultName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java deleted file mode 100644 index bac6704da3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCoreContextJavaModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreContextJavaModelTests.class.getPackage().getName()); - suite.addTestSuite(JavaAssociationOverrideTests.class); - suite.addTestSuite(JavaAttributeOverrideTests.class); - suite.addTestSuite(JavaBasicMappingTests.class); - suite.addTestSuite(JavaCascadeTests.class); - suite.addTestSuite(JavaColumnTests.class); - suite.addTestSuite(JavaDiscriminatorColumnTests.class); - suite.addTestSuite(JavaEmbeddableTests.class); - suite.addTestSuite(JavaEmbeddedIdMappingTests.class); - suite.addTestSuite(JavaEmbeddedMappingTests.class); - suite.addTestSuite(JavaEntityTests.class); - suite.addTestSuite(JavaGeneratedValueTests.class); - suite.addTestSuite(JavaIdMappingTests.class); - suite.addTestSuite(JavaJoinColumnTests.class); - suite.addTestSuite(JavaJoinTableTests.class); - suite.addTestSuite(JavaMappedSuperclassTests.class); - suite.addTestSuite(JavaManyToManyMappingTests.class); - suite.addTestSuite(JavaManyToOneMappingTests.class); - suite.addTestSuite(JavaNamedQueryTests.class); - suite.addTestSuite(JavaNamedNativeQueryTests.class); - suite.addTestSuite(JavaQueryHintTests.class); - suite.addTestSuite(JavaOneToManyMappingTests.class); - suite.addTestSuite(JavaOneToOneMappingTests.class); - suite.addTestSuite(GenericJavaPersistentTypeTests.class); - suite.addTestSuite(GenericJavaPersistentAttributeTests.class); - suite.addTestSuite(JavaPrimaryKeyJoinColumnTests.class); - suite.addTestSuite(JavaSecondaryTableTests.class); - suite.addTestSuite(JavaSequenceGeneratorTests.class); - suite.addTestSuite(JavaTableGeneratorTests.class); - suite.addTestSuite(JavaTableTests.class); - suite.addTestSuite(JavaTransientMappingTests.class); - suite.addTestSuite(JavaVersionMappingTests.class); - return suite; - } - - private JptCoreContextJavaModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java deleted file mode 100644 index 2f80b0a2f1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java +++ /dev/null @@ -1,1066 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class EntityMappingsTests extends ContextModelTestCase -{ - public EntityMappingsTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testGetVersion() throws Exception { - assertEquals("1.0", getEntityMappings().getVersion()); - } - - public void testUpdateDescription() throws Exception { - assertNull(getEntityMappings().getDescription()); - assertNull(getXmlEntityMappings().getDescription()); - - //set description in the resource model, verify context model updated - getXmlEntityMappings().setDescription("newDescription"); - assertEquals("newDescription", getEntityMappings().getDescription()); - assertEquals("newDescription", getXmlEntityMappings().getDescription()); - - //set description to null in the resource model - getXmlEntityMappings().setDescription(null); - assertNull(getEntityMappings().getDescription()); - assertNull(getXmlEntityMappings().getDescription()); - } - - public void testModifyDescription() throws Exception { - assertNull(getEntityMappings().getDescription()); - assertNull(getXmlEntityMappings().getDescription()); - - //set description in the context model, verify resource model modified - getEntityMappings().setDescription("newDescription"); - assertEquals("newDescription", getEntityMappings().getDescription()); - assertEquals("newDescription", getXmlEntityMappings().getDescription()); - - //set description to null in the context model - getEntityMappings().setDescription(null); - assertNull(getEntityMappings().getDescription()); - assertNull(getXmlEntityMappings().getDescription()); - } - - public void testUpdatePackage() throws Exception { - assertNull(getEntityMappings().getPackage()); - assertNull(getXmlEntityMappings().getPackage()); - - //set package in the resource model, verify context model updated - getXmlEntityMappings().setPackage("foo.model"); - assertEquals("foo.model", getEntityMappings().getPackage()); - assertEquals("foo.model", getXmlEntityMappings().getPackage()); - - //set package to null in the resource model - getXmlEntityMappings().setPackage(null); - assertNull(getEntityMappings().getPackage()); - assertNull(getXmlEntityMappings().getPackage()); - } - - public void testModifyPackage() throws Exception { - assertNull(getEntityMappings().getPackage()); - assertNull(getXmlEntityMappings().getPackage()); - - //set package in the context model, verify resource model modified - getEntityMappings().setPackage("foo.model"); - assertEquals("foo.model", getEntityMappings().getPackage()); - assertEquals("foo.model", getXmlEntityMappings().getPackage()); - - //set package to null in the context model - getEntityMappings().setPackage(null); - assertNull(getEntityMappings().getPackage()); - assertNull(getXmlEntityMappings().getPackage()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - - //set schema in the resource model, verify context model updated - getXmlEntityMappings().setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", getEntityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getSchema()); - - //set schema to null in the resource model - getXmlEntityMappings().setSchema(null); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - - //set schema in the context model, verify resource model modified - getEntityMappings().setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", getEntityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getSchema()); - - //set schema to null in the context model - getEntityMappings().setSpecifiedSchema(null); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - - //set catalog in the resource model, verify context model updated - getXmlEntityMappings().setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", getEntityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getCatalog()); - - //set catalog to null in the resource model - getXmlEntityMappings().setCatalog(null); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - } - - public void testUpdateDefaultSchema() throws Exception { - assertNull(getEntityMappings().getDefaultSchema()); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", getEntityMappings().getDefaultSchema()); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - persistenceUnitDefaults.setSchema(null); - assertNull(getEntityMappings().getDefaultSchema()); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testUpdateSchema() throws Exception { - assertNull(getEntityMappings().getDefaultSchema()); - assertNull(getEntityMappings().getSchema()); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - - getXmlEntityMappings().setSchema("MY_SCHEMA"); - assertNull(getEntityMappings().getDefaultSchema()); - assertEquals("MY_SCHEMA", getEntityMappings().getSchema()); - assertEquals("MY_SCHEMA", getEntityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getSchema()); - - getXmlEntityMappings().setSchema(null); - assertNull(getEntityMappings().getDefaultSchema()); - assertNull(getEntityMappings().getSchema()); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("DEFAULT_SCHEMA"); - assertEquals("DEFAULT_SCHEMA", getEntityMappings().getDefaultSchema()); - assertEquals("DEFAULT_SCHEMA", getEntityMappings().getSchema()); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(getEntityMappings().getDefaultSchema()); - assertNull(getEntityMappings().getSchema()); - assertNull(getEntityMappings().getSpecifiedSchema()); - assertNull(getXmlEntityMappings().getSchema()); - } - - public void testModifySpecifiedCatalog() throws Exception { - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - - //set catalog in the context model, verify resource model modified - getEntityMappings().setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", getEntityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getCatalog()); - - //set catalog to null in the context model - getEntityMappings().setSpecifiedCatalog(null); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - } - - public void testUpdateDefaultCatalog() throws Exception { - assertNull(getEntityMappings().getDefaultCatalog()); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", getEntityMappings().getDefaultCatalog()); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - persistenceUnitDefaults.setCatalog(null); - assertNull(getEntityMappings().getDefaultCatalog()); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testUpdateCatalog() throws Exception { - assertNull(getEntityMappings().getDefaultCatalog()); - assertNull(getEntityMappings().getCatalog()); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - - getXmlEntityMappings().setCatalog("MY_CATALOG"); - assertNull(getEntityMappings().getDefaultCatalog()); - assertEquals("MY_CATALOG", getEntityMappings().getCatalog()); - assertEquals("MY_CATALOG", getEntityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getCatalog()); - - getXmlEntityMappings().setCatalog(null); - assertNull(getEntityMappings().getDefaultCatalog()); - assertNull(getEntityMappings().getCatalog()); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("DEFAULT_CATALOG"); - assertEquals("DEFAULT_CATALOG", getEntityMappings().getDefaultCatalog()); - assertEquals("DEFAULT_CATALOG", getEntityMappings().getCatalog()); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(getEntityMappings().getDefaultCatalog()); - assertNull(getEntityMappings().getCatalog()); - assertNull(getEntityMappings().getSpecifiedCatalog()); - assertNull(getXmlEntityMappings().getCatalog()); - } - - public void testUpdateSpecifiedAccess() throws Exception { - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - //set access in the resource model, verify context model updated - getXmlEntityMappings().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, getEntityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, getXmlEntityMappings().getAccess()); - - //set access to null in the resource model - getXmlEntityMappings().setAccess(null); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - //set access in the context model, verify resource model modified - getEntityMappings().setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, getEntityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, getXmlEntityMappings().getAccess()); - - //set access to null in the context model - getEntityMappings().setSpecifiedAccess(null); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - } - - public void testUpdateDefaultAccess() throws Exception { - assertNull(getEntityMappings().getDefaultAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, getEntityMappings().getDefaultAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - persistenceUnitDefaults.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, getEntityMappings().getDefaultAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - persistenceUnitDefaults.setAccess(null); - assertNull(getEntityMappings().getDefaultAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - } - - public void testUpdateAccess() throws Exception { - assertNull(getEntityMappings().getAccess()); - assertNull(getEntityMappings().getDefaultAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - getXmlEntityMappings().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertNull(getEntityMappings().getDefaultAccess()); - assertEquals(AccessType.FIELD, getEntityMappings().getAccess()); - assertEquals(AccessType.FIELD, getEntityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, getXmlEntityMappings().getAccess()); - - getXmlEntityMappings().setAccess(null); - assertNull(getEntityMappings().getAccess()); - assertNull(getEntityMappings().getDefaultAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, getEntityMappings().getDefaultAccess()); - assertEquals(AccessType.FIELD, getEntityMappings().getAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(getEntityMappings().getDefaultAccess()); - assertNull(getEntityMappings().getAccess()); - assertNull(getEntityMappings().getSpecifiedAccess()); - assertNull(getXmlEntityMappings().getAccess()); - } - - - public void testUpdateOrmPersistentTypes() throws Exception { - assertFalse(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertTrue(getXmlEntityMappings().getEmbeddables().isEmpty()); - - //add embeddable in the resource model, verify context model updated - XmlEmbeddable embeddable = OrmFactory.eINSTANCE.createXmlEmbeddable(); - getXmlEntityMappings().getEmbeddables().add(embeddable); - embeddable.setClassName("model.Foo"); - assertTrue(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertEquals("model.Foo", getEntityMappings().getPersistentTypes().iterator().next().getMapping().getClass_()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertFalse(getXmlEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo", getXmlEntityMappings().getEmbeddables().get(0).getClassName()); - - //add entity in the resource model, verify context model updated - XmlEntity entity = OrmFactory.eINSTANCE.createXmlEntity(); - getXmlEntityMappings().getEntities().add(entity); - entity.setClassName("model.Foo2"); - assertTrue(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertEquals("model.Foo2", getEntityMappings().getPersistentTypes().iterator().next().getMapping().getClass_()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(getXmlEntityMappings().getEntities().isEmpty()); - assertFalse(getXmlEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo2", getXmlEntityMappings().getEntities().get(0).getClassName()); - - //add mapped-superclass in the resource model, verify context model updated - XmlMappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createXmlMappedSuperclass(); - getXmlEntityMappings().getMappedSuperclasses().add(mappedSuperclass); - mappedSuperclass.setClassName("model.Foo3"); - assertTrue(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertEquals("model.Foo3", getEntityMappings().getPersistentTypes().iterator().next().getMapping().getClass_()); - assertFalse(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(getXmlEntityMappings().getEntities().isEmpty()); - assertFalse(getXmlEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo3", getXmlEntityMappings().getMappedSuperclasses().get(0).getClassName()); - } - - - public void testAddOrmPersistentType() throws Exception { - assertFalse(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertTrue(getXmlEntityMappings().getEmbeddables().isEmpty()); - - //add embeddable in the context model, verify resource model modified - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - assertTrue(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertEquals("model.Foo", getEntityMappings().getPersistentTypes().iterator().next().getMapping().getClass_()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getEntityMappings().getPersistentTypes().iterator().next().getMapping().getKey()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertFalse(getXmlEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo", getXmlEntityMappings().getEmbeddables().get(0).getClassName()); - - //add entity in the context model, verify resource model modified - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - assertTrue(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertEquals("model.Foo2", getEntityMappings().getPersistentTypes().iterator().next().getMapping().getClass_()); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getEntityMappings().getPersistentTypes().iterator().next().getMapping().getKey()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(getXmlEntityMappings().getEntities().isEmpty()); - assertFalse(getXmlEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo2", getXmlEntityMappings().getEntities().get(0).getClassName()); - - //add mapped-superclass in the context model, verify resource model modified - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - assertTrue(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertEquals("model.Foo3", getEntityMappings().getPersistentTypes().iterator().next().getMapping().getClass_()); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, getEntityMappings().getPersistentTypes().iterator().next().getMapping().getKey()); - assertFalse(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(getXmlEntityMappings().getEntities().isEmpty()); - assertFalse(getXmlEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo3", getXmlEntityMappings().getMappedSuperclasses().get(0).getClassName()); - } - - public void testRemoveOrmPersistentType() throws Exception { - assertFalse(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertTrue(getXmlEntityMappings().getEmbeddables().isEmpty()); - - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - - //remove ormPersistentType from the context model, verify resource model modified - getEntityMappings().removePersistentType(1); - assertFalse(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertFalse(getXmlEntityMappings().getEmbeddables().isEmpty()); - - getEntityMappings().removePersistentType(1); - assertFalse(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertTrue(getXmlEntityMappings().getEmbeddables().isEmpty()); - - getEntityMappings().removePersistentType(0); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertTrue(getXmlEntityMappings().getEmbeddables().isEmpty()); - } - - public void testUpdateTableGenerators() throws Exception { - assertEquals(0, getEntityMappings().getTableGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getTableGenerators().size()); - assertEquals(0, getEntityMappings().getPersistenceUnit().generatorsSize()); - - XmlTableGenerator tableGeneratorResource = OrmFactory.eINSTANCE.createXmlTableGenerator(); - getXmlEntityMappings().getTableGenerators().add(tableGeneratorResource); - tableGeneratorResource.setName("FOO"); - - TableGenerator tableGenerator = getEntityMappings().getTableGenerators().iterator().next(); - assertEquals("FOO", tableGenerator.getName()); - assertEquals(1, getEntityMappings().getPersistenceUnit().generatorsSize()); - - XmlTableGenerator tableGeneratorResource2 = OrmFactory.eINSTANCE.createXmlTableGenerator(); - getXmlEntityMappings().getTableGenerators().add(0, tableGeneratorResource2); - tableGeneratorResource2.setName("BAR"); - - ListIterator tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(2, getEntityMappings().getPersistenceUnit().generatorsSize()); - - XmlTableGenerator tableGeneratorResource3 = OrmFactory.eINSTANCE.createXmlTableGenerator(); - getXmlEntityMappings().getTableGenerators().add(1, tableGeneratorResource3); - tableGeneratorResource3.setName("BAZ"); - - tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("BAZ", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(3, getEntityMappings().getPersistenceUnit().generatorsSize()); - - getXmlEntityMappings().getTableGenerators().move(2, 0); - tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertEquals("BAZ", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertEquals("BAR", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(3, getEntityMappings().getPersistenceUnit().generatorsSize()); - - getXmlEntityMappings().getTableGenerators().remove(0); - tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertEquals("FOO", tableGenerators.next().getName()); - assertEquals("BAR", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(2, getEntityMappings().getPersistenceUnit().generatorsSize()); - - getXmlEntityMappings().getTableGenerators().remove(1); - tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(1, getEntityMappings().getPersistenceUnit().generatorsSize()); - - getXmlEntityMappings().getTableGenerators().clear(); - tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertFalse(tableGenerators.hasNext()); - assertEquals(0, getEntityMappings().getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - assertEquals(0, getEntityMappings().getTableGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getTableGenerators().size()); - getEntityMappings().addTableGenerator(0).setName("FOO"); - - assertEquals("FOO", getXmlEntityMappings().getTableGenerators().get(0).getName()); - - getEntityMappings().addTableGenerator(0).setName("BAR"); - assertEquals("BAR", getXmlEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("FOO", getXmlEntityMappings().getTableGenerators().get(1).getName()); - assertEquals(2, getXmlEntityMappings().getTableGenerators().size()); - - ListIterator tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - } - - public void testRemoveTableGenerator() throws Exception { - assertEquals(0, getEntityMappings().getTableGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getTableGenerators().size()); - - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = getEntityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = getEntityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - assertEquals("FOO", getXmlEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", getXmlEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getTableGenerators().size()); - - getEntityMappings().removeTableGenerator(0); - assertEquals("BAR", getXmlEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getTableGenerators().get(1).getName()); - - ListIterator tableGenerators = getEntityMappings().getTableGenerators().iterator(); - OrmTableGenerator xmlTableGenerator = tableGenerators.next(); - assertEquals("BAR", xmlTableGenerator.getName()); - assertEquals(tableGenerator2, xmlTableGenerator); - xmlTableGenerator = tableGenerators.next(); - assertEquals("BAZ", xmlTableGenerator.getName()); - assertEquals(tableGenerator3, xmlTableGenerator); - assertFalse(tableGenerators.hasNext()); - - - getEntityMappings().removeTableGenerator(1); - assertEquals("BAR", getXmlEntityMappings().getTableGenerators().get(0).getName()); - tableGenerators = getEntityMappings().getTableGenerators().iterator(); - xmlTableGenerator = tableGenerators.next(); - assertEquals("BAR", xmlTableGenerator.getName()); - assertEquals(tableGenerator2, xmlTableGenerator); - assertFalse(tableGenerators.hasNext()); - - - getEntityMappings().removeTableGenerator(0); - assertEquals(0, getXmlEntityMappings().getTableGenerators().size()); - tableGenerators = getEntityMappings().getTableGenerators().iterator(); - assertFalse(tableGenerators.hasNext()); - } - - public void testMoveTableGenerator() throws Exception { - assertEquals(0, getEntityMappings().getTableGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getTableGenerators().size()); - - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = getEntityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = getEntityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - assertEquals("FOO", getXmlEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", getXmlEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getTableGenerators().size()); - - getEntityMappings().moveTableGenerator(2, 0); - assertEquals("BAR", getXmlEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getTableGenerators().size()); - - getEntityMappings().moveTableGenerator(0, 2); - assertEquals("FOO", getXmlEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", getXmlEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getTableGenerators().size()); - } - - public void testTableGeneratorsSize() throws Exception { - assertEquals(0, getEntityMappings().getTableGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getTableGenerators().size()); - - - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = getEntityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = getEntityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - - assertEquals(3, getEntityMappings().getTableGeneratorsSize()); - - getXmlEntityMappings().getTableGenerators().remove(0); - assertEquals(2, getEntityMappings().getTableGeneratorsSize()); - } - - public void testUpdateSequenceGenerators() throws Exception { - assertEquals(0, getEntityMappings().getSequenceGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getSequenceGenerators().size()); - assertEquals(0, getEntityMappings().getPersistenceUnit().generatorsSize()); - - XmlSequenceGenerator sequenceGeneratorResource = OrmFactory.eINSTANCE.createXmlSequenceGenerator(); - getXmlEntityMappings().getSequenceGenerators().add(sequenceGeneratorResource); - sequenceGeneratorResource.setName("FOO"); - - SequenceGenerator sequenceGenerator = getEntityMappings().getSequenceGenerators().iterator().next(); - assertEquals("FOO", sequenceGenerator.getName()); - assertEquals(1, getEntityMappings().getPersistenceUnit().generatorsSize()); - - XmlSequenceGenerator sequenceGeneratorResource2 = OrmFactory.eINSTANCE.createXmlSequenceGenerator(); - getXmlEntityMappings().getSequenceGenerators().add(0, sequenceGeneratorResource2); - sequenceGeneratorResource2.setName("BAR"); - - ListIterator sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(2, getEntityMappings().getPersistenceUnit().generatorsSize()); - - XmlSequenceGenerator sequenceGeneratorResource3 = OrmFactory.eINSTANCE.createXmlSequenceGenerator(); - getXmlEntityMappings().getSequenceGenerators().add(1, sequenceGeneratorResource3); - sequenceGeneratorResource3.setName("BAZ"); - - sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("BAZ", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(3, getEntityMappings().getPersistenceUnit().generatorsSize()); - - getXmlEntityMappings().getSequenceGenerators().move(2, 0); - sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertEquals("BAZ", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - - getXmlEntityMappings().getSequenceGenerators().remove(0); - sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(2, getEntityMappings().getPersistenceUnit().generatorsSize()); - - getXmlEntityMappings().getSequenceGenerators().remove(1); - sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(1, getEntityMappings().getPersistenceUnit().generatorsSize()); - - getXmlEntityMappings().getSequenceGenerators().clear(); - sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(0, getEntityMappings().getPersistenceUnit().generatorsSize()); - } - - public void testAddSequenceGenerator() throws Exception { - assertEquals(0, getEntityMappings().getSequenceGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getSequenceGenerators().size()); - - getEntityMappings().addSequenceGenerator(0).setName("FOO"); - - assertEquals("FOO", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - - getEntityMappings().addSequenceGenerator(0).setName("BAR"); - assertEquals("BAR", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("FOO", getXmlEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals(2, getXmlEntityMappings().getSequenceGenerators().size()); - - ListIterator sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - } - - public void testRemoveSequenceGenerator() throws Exception { - assertEquals(0, getEntityMappings().getSequenceGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getSequenceGenerators().size()); - - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = getEntityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = getEntityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - assertEquals("FOO", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", getXmlEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getSequenceGenerators().size()); - - getEntityMappings().removeSequenceGenerator(0); - assertEquals("BAR", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getSequenceGenerators().get(1).getName()); - - ListIterator sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - SequenceGenerator xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAR", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator2, xmlSequenceGenerator); - xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAZ", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator3, xmlSequenceGenerator); - assertFalse(sequenceGenerators.hasNext()); - - - getEntityMappings().removeSequenceGenerator(1); - assertEquals("BAR", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAR", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator2, xmlSequenceGenerator); - assertFalse(sequenceGenerators.hasNext()); - - - getEntityMappings().removeSequenceGenerator(0); - assertEquals(0, getXmlEntityMappings().getSequenceGenerators().size()); - sequenceGenerators = getEntityMappings().getSequenceGenerators().iterator(); - assertFalse(sequenceGenerators.hasNext()); - } - - public void testMoveSequenceGenerator() throws Exception { - assertEquals(0, getEntityMappings().getSequenceGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getSequenceGenerators().size()); - - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = getEntityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = getEntityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - assertEquals("FOO", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", getXmlEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getSequenceGenerators().size()); - - getEntityMappings().moveSequenceGenerator(2, 0); - assertEquals("BAR", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getSequenceGenerators().size()); - - getEntityMappings().moveSequenceGenerator(0, 2); - assertEquals("FOO", getXmlEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", getXmlEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, getXmlEntityMappings().getSequenceGenerators().size()); - - } - - public void testSequenceGeneratorsSize() throws Exception { - assertEquals(0, getEntityMappings().getSequenceGeneratorsSize()); - assertEquals(0, getXmlEntityMappings().getSequenceGenerators().size()); - - - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = getEntityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = getEntityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - - assertEquals(3, getEntityMappings().getSequenceGeneratorsSize()); - - getXmlEntityMappings().getSequenceGenerators().remove(0); - assertEquals(2, getEntityMappings().getSequenceGeneratorsSize()); - } - - - public void testAddNamedQuery() throws Exception { - OrmNamedQuery namedQuery = getEntityMappings().getQueryContainer().addNamedQuery(0); - namedQuery.setName("FOO"); - - assertEquals("FOO", getXmlEntityMappings().getNamedQueries().get(0).getName()); - - OrmNamedQuery namedQuery2 = getEntityMappings().getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - - assertEquals("BAR", getXmlEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedQueries().get(1).getName()); - - OrmNamedQuery namedQuery3 = getEntityMappings().getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - - assertEquals("BAR", getXmlEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedQueries().get(2).getName()); - - ListIterator namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - getEntityMappings().getQueryContainer().addNamedQuery(0).setName("FOO"); - getEntityMappings().getQueryContainer().addNamedQuery(1).setName("BAR"); - getEntityMappings().getQueryContainer().addNamedQuery(2).setName("BAZ"); - - assertEquals(3, getXmlEntityMappings().getNamedQueries().size()); - - getEntityMappings().getQueryContainer().removeNamedQuery(0); - assertEquals(2, getXmlEntityMappings().getNamedQueries().size()); - assertEquals("BAR", getXmlEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getNamedQueries().get(1).getName()); - - getEntityMappings().getQueryContainer().removeNamedQuery(0); - assertEquals(1, getXmlEntityMappings().getNamedQueries().size()); - assertEquals("BAZ", getXmlEntityMappings().getNamedQueries().get(0).getName()); - - getEntityMappings().getQueryContainer().removeNamedQuery(0); - assertEquals(0, getXmlEntityMappings().getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - getEntityMappings().getQueryContainer().addNamedQuery(0).setName("FOO"); - getEntityMappings().getQueryContainer().addNamedQuery(1).setName("BAR"); - getEntityMappings().getQueryContainer().addNamedQuery(2).setName("BAZ"); - - assertEquals(3, getXmlEntityMappings().getNamedQueries().size()); - - - getEntityMappings().getQueryContainer().moveNamedQuery(2, 0); - ListIterator namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAR", getXmlEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedQueries().get(2).getName()); - - - getEntityMappings().getQueryContainer().moveNamedQuery(0, 1); - namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", getXmlEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - assertEquals(0, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - getXmlEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - getXmlEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - - getXmlEntityMappings().getNamedQueries().get(0).setName("FOO"); - getXmlEntityMappings().getNamedQueries().get(1).setName("BAR"); - getXmlEntityMappings().getNamedQueries().get(2).setName("BAZ"); - - ListIterator namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedQueries().move(2, 0); - namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - getXmlEntityMappings().getNamedQueries().move(0, 1); - namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - getXmlEntityMappings().getNamedQueries().remove(1); - namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedQueries().remove(1); - namedQueries = getEntityMappings().getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedQueries().remove(0); - assertFalse(getEntityMappings().getQueryContainer().namedQueries().hasNext()); - assertEquals(0, getEntityMappings().getPersistenceUnit().queriesSize()); - } - - public void testAddNamedNativeQuery() throws Exception { - OrmNamedNativeQuery namedNativeQuery = getEntityMappings().getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - assertEquals("FOO", getXmlEntityMappings().getNamedNativeQueries().get(0).getName()); - - OrmNamedNativeQuery namedNativeQuery2 = getEntityMappings().getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - assertEquals("BAR", getXmlEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedNativeQueries().get(1).getName()); - - OrmNamedNativeQuery namedNativeQuery3 = getEntityMappings().getQueryContainer().addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - assertEquals("BAR", getXmlEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedNativeQueries().get(2).getName()); - - ListIterator namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals(namedNativeQuery2, namedNativeQueries.next()); - assertEquals(namedNativeQuery3, namedNativeQueries.next()); - assertEquals(namedNativeQuery, namedNativeQueries.next()); - - namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - getEntityMappings().getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - getEntityMappings().getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - getEntityMappings().getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - assertEquals(3, getXmlEntityMappings().getNamedNativeQueries().size()); - - getEntityMappings().getQueryContainer().removeNamedNativeQuery(0); - assertEquals(2, getXmlEntityMappings().getNamedNativeQueries().size()); - assertEquals("BAR", getXmlEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getNamedNativeQueries().get(1).getName()); - - getEntityMappings().getQueryContainer().removeNamedNativeQuery(0); - assertEquals(1, getXmlEntityMappings().getNamedNativeQueries().size()); - assertEquals("BAZ", getXmlEntityMappings().getNamedNativeQueries().get(0).getName()); - - getEntityMappings().getQueryContainer().removeNamedNativeQuery(0); - assertEquals(0, getXmlEntityMappings().getNamedNativeQueries().size()); - } - - public void testMoveNamedNativeQuery() throws Exception { - getEntityMappings().getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - getEntityMappings().getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - getEntityMappings().getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - assertEquals(3, getXmlEntityMappings().getNamedNativeQueries().size()); - - - getEntityMappings().getQueryContainer().moveNamedNativeQuery(2, 0); - ListIterator namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAR", getXmlEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", getXmlEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedNativeQueries().get(2).getName()); - - - getEntityMappings().getQueryContainer().moveNamedNativeQuery(0, 1); - namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAZ", getXmlEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAR", getXmlEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", getXmlEntityMappings().getNamedNativeQueries().get(2).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - assertEquals(0, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - getXmlEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - getXmlEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - - getXmlEntityMappings().getNamedNativeQueries().get(0).setName("FOO"); - getXmlEntityMappings().getNamedNativeQueries().get(1).setName("BAR"); - getXmlEntityMappings().getNamedNativeQueries().get(2).setName("BAZ"); - - ListIterator namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(3, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedNativeQueries().move(2, 0); - namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - getXmlEntityMappings().getNamedNativeQueries().move(0, 1); - namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - getXmlEntityMappings().getNamedNativeQueries().remove(1); - namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(2, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedNativeQueries().remove(1); - namedNativeQueries = getEntityMappings().getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(1, getEntityMappings().getPersistenceUnit().queriesSize()); - - getXmlEntityMappings().getNamedNativeQueries().remove(0); - assertFalse(getEntityMappings().getQueryContainer().namedNativeQueries().hasNext()); - assertEquals(0, getEntityMappings().getPersistenceUnit().queriesSize()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentAttributeTests.java deleted file mode 100644 index 04ea52da6d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentAttributeTests.java +++ /dev/null @@ -1,314 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmIdMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmPersistentAttributeTests extends ContextModelTestCase -{ - public GenericOrmPersistentAttributeTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestTypeNullAttributeMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(" private Address address;"); - } - }); - } - - public void testMakeSpecified() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeSpecifiedMappingKey() throws Exception { - createTestTypeNullAttributeMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - //take a virtual mapping with a mapping type and make it specified - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertNull(ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof GenericOrmOneToOneMapping); - - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof GenericOrmIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(0, ormPersistentType.specifiedAttributesSize()); - - Iterator virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - - ormPersistentType.specifiedAttributes().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - assertEquals("id", ormPersistentType.virtualAttributes().next().getName()); - assertEquals("name", ormPersistentType.specifiedAttributes().next().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("id", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete2() throws Exception { - createTestEntityOneToOneMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } - - public void testGetJavaPersistentAttribute() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - //virtual orm attribute, access type matches java : FIELD, name matches java - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - JavaResourcePersistentAttribute javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isField()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableFields().next(), javaResourcePersistentAttribute); - - - //specified orm attribute, access type matches java : FIELD, name matches java - //javaPersistentAttribute should be == to java context model object - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - - - //virtual orm attribute, java access type FIELD, orm access type PROPERTY, name matches java - //verify the property java resource persistent attribute is used in orm. - ((OrmPersistentAttribute) ormPersistentAttribute).convertToVirtual(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertNotSame(ormPersistentAttribute, ormPersistentType.getAttributeNamed("id")); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isProperty()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableProperties().next(), javaResourcePersistentAttribute); - - - ormPersistentType.setSpecifiedAccess(null);//default access will be field - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - OrmPersistentAttribute ormPersistentAttribute2 = ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute2.getMapping().setName("id2"); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName(null); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName("id"); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java deleted file mode 100644 index bcf02a0ad4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/GenericOrmPersistentTypeTests.java +++ /dev/null @@ -1,574 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmPersistentTypeTests extends ContextModelTestCase -{ - public static final String MODEL_TYPE_NAME = "Model"; - public static final String FULLY_QUALIFIED_MODEL_TYPE_NAME = PACKAGE_NAME + "." + MODEL_TYPE_NAME; - - public static final String EMPLOYEE_TYPE_NAME = "Employee"; - public static final String FULLY_QUALIFIED_EMPLOYEE_TYPE_NAME = PACKAGE_NAME + "." + EMPLOYEE_TYPE_NAME; - - - public GenericOrmPersistentTypeTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private void createModelType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public abstract class ").append(MODEL_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, MODEL_TYPE_NAME + ".java", sourceWriter); - } - - private void createEmployeeType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append(EMPLOYEE_TYPE_NAME).append(" extends ").append(MODEL_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String department;").append(CR); - sb.append(CR); - sb.append(" private java.util.Date startDate;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMPLOYEE_TYPE_NAME + ".java", sourceWriter); - } - -// public void testUpdateXmlTypeMapping() throws Exception { -// assertFalse(entityMappings().ormPersistentTypes().hasNext()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// -// //add embeddable in the resource model, verify context model updated -// Embeddable embeddable = OrmFactory.eINSTANCE.createEmbeddable(); -// ormResource().getEntityMappings().getEmbeddables().add(embeddable); -// embeddable.setClassName("model.Foo"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); -// -// //add entity in the resource model, verify context model updated -// Entity entity = OrmFactory.eINSTANCE.createEntity(); -// ormResource().getEntityMappings().getEntities().add(entity); -// entity.setClassName("model.Foo2"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo2", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo2", ormResource().getEntityMappings().getEntities().get(0).getClassName()); -// -// //add mapped-superclass in the resource model, verify context model updated -// MappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createMappedSuperclass(); -// ormResource().getEntityMappings().getMappedSuperclasses().add(mappedSuperclass); -// mappedSuperclass.setClassName("model.Foo3"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo3", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo3", ormResource().getEntityMappings().getMappedSuperclasses().get(0).getClassName()); -// } -// - - public void testMorphXmlTypeMapping() throws Exception { - assertFalse(getEntityMappings().getPersistentTypes().iterator().hasNext()); - assertTrue(getXmlEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(getXmlEntityMappings().getEntities().isEmpty()); - assertTrue(getXmlEntityMappings().getEmbeddables().isEmpty()); - - OrmPersistentType embeddablePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType mappedSuperclassPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - - OrmPersistentType ormPersistentType = getEntityMappings().getPersistentTypes().iterator().next(); - assertEquals(mappedSuperclassPersistentType, ormPersistentType); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, ormPersistentType.getMapping().getKey()); - - ormPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertEquals(0, getXmlEntityMappings().getMappedSuperclasses().size()); - assertEquals(1, getXmlEntityMappings().getEntities().size()); - assertEquals(2, getXmlEntityMappings().getEmbeddables().size()); - - Iterator ormPersistentTypes = getEntityMappings().getPersistentTypes().iterator(); - //the same OrmPersistentTypes should still be in the context model - assertEquals(ormPersistentTypes.next(), entityPersistentType); - assertEquals(ormPersistentTypes.next(), embeddablePersistentType); - assertEquals(ormPersistentTypes.next(), mappedSuperclassPersistentType); - - assertEquals("model.Foo", getXmlEntityMappings().getEmbeddables().get(0).getClassName()); - assertEquals("model.Foo3", getXmlEntityMappings().getEmbeddables().get(1).getClassName()); - } - - public void testAddSpecifiedPersistentAttribute() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entity.getAttributes().getBasics().get(0); - assertEquals("basicAttribute", basic.getName()); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - - XmlEmbedded embedded = entity.getAttributes().getEmbeddeds().get(0); - assertEquals("embeddedAttribute", embedded.getName()); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - - XmlTransient transientResource = entity.getAttributes().getTransients().get(0); - assertEquals("transientAttribute", transientResource.getName()); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - - XmlVersion version = entity.getAttributes().getVersions().get(0); - assertEquals("versionAttribute", version.getName()); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - - XmlId id = entity.getAttributes().getIds().get(0); - assertEquals("idAttribute", id.getName()); - - - Iterator persistentAttributes = entityPersistentType.specifiedAttributes(); - assertEquals("idAttribute", persistentAttributes.next().getName()); - assertEquals("basicAttribute", persistentAttributes.next().getName()); - assertEquals("versionAttribute", persistentAttributes.next().getName()); - assertEquals("embeddedAttribute", persistentAttributes.next().getName()); - assertEquals("transientAttribute", persistentAttributes.next().getName()); - assertFalse(persistentAttributes.hasNext()); - } - - public void testRemoveSpecifiedPersistentAttribute() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - entityPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - entityPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - entityPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - entityPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - assertEquals("basicAttribute", entity.getAttributes().getBasics().get(0).getName()); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("basicAttribute")).convertToVirtual(); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("embeddedAttribute")).convertToVirtual(); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("versionAttribute")).convertToVirtual(); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("idAttribute")).convertToVirtual(); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("transientAttribute")).convertToVirtual(); - assertNull(entity.getAttributes()); - } - - public void testRemoveId() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("idAttribute")).convertToVirtual(); - assertNull(entity.getAttributes()); - } - - public void testRemoveBasic() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - assertEquals("basicAttribute", entity.getAttributes().getBasics().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("basicAttribute")).convertToVirtual(); - assertNull(entity.getAttributes()); - } - - public void testRemoveVersion() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("versionAttribute")).convertToVirtual(); - assertNull(entity.getAttributes()); - } - - public void testRemoveEmbedded() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("embeddedAttribute")).convertToVirtual(); - assertNull(entity.getAttributes()); - } - - public void testRemoveTransient() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - ((OrmPersistentAttribute) entityPersistentType.getAttributeNamed("transientAttribute")).convertToVirtual(); - assertNull(entity.getAttributes()); - } - - public void testUpdateSpecifiedPersistentAttributes() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - - entity.setAttributes(OrmFactory.eINSTANCE.createAttributes()); - XmlBasic basic = OrmFactory.eINSTANCE.createXmlBasic(); - entity.getAttributes().getBasics().add(basic); - basic.setName("basicAttribute"); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = entityPersistentType.attributes().next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - - XmlEmbedded embedded = OrmFactory.eINSTANCE.createXmlEmbedded(); - entity.getAttributes().getEmbeddeds().add(embedded); - embedded.setName("embeddedAttribute"); - - Iterator attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlVersion version = OrmFactory.eINSTANCE.createXmlVersion(); - entity.getAttributes().getVersions().add(version); - version.setName("versionAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlId id = OrmFactory.eINSTANCE.createXmlId(); - entity.getAttributes().getIds().add(id); - id.setName("idAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlTransient transientResource = OrmFactory.eINSTANCE.createXmlTransient(); - entity.getAttributes().getTransients().add(transientResource); - transientResource.setName("transientAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlManyToOne manyToOneResource = OrmFactory.eINSTANCE.createXmlManyToOne(); - entity.getAttributes().getManyToOnes().add(manyToOneResource); - manyToOneResource.setName("manyToOneAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlManyToMany manyToManyResource = OrmFactory.eINSTANCE.createXmlManyToMany(); - entity.getAttributes().getManyToManys().add(manyToManyResource); - manyToManyResource.setName("manyToManyAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlOneToMany oneToManyResource = OrmFactory.eINSTANCE.createXmlOneToMany(); - entity.getAttributes().getOneToManys().add(oneToManyResource); - oneToManyResource.setName("oneToManyAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlOneToOne oneToOneResource = OrmFactory.eINSTANCE.createXmlOneToOne(); - entity.getAttributes().getOneToOnes().add(oneToOneResource); - oneToOneResource.setName("oneToOneAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - - XmlEmbeddedId embeddedIdResource = OrmFactory.eINSTANCE.createXmlEmbeddedId(); - entity.getAttributes().getEmbeddedIds().add(embeddedIdResource); - embeddedIdResource.setName("embeddedIdAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedIdAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - entity.getAttributes().getBasics().remove(0); - entity.getAttributes().getEmbeddeds().remove(0); - entity.getAttributes().getTransients().remove(0); - entity.getAttributes().getIds().remove(0); - entity.getAttributes().getVersions().remove(0); - entity.getAttributes().getManyToOnes().remove(0); - entity.getAttributes().getManyToManys().remove(0); - entity.getAttributes().getOneToManys().remove(0); - entity.getAttributes().getOneToOnes().remove(0); - entity.getAttributes().getEmbeddedIds().remove(0); - assertFalse(entityPersistentType.attributes().hasNext()); - assertNotNull(entity.getAttributes()); - } - - - - public void testInheritedAttributesResolve() throws Exception { - createModelType(); - createEmployeeType(); - - OrmPersistentType employeePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_EMPLOYEE_TYPE_NAME); - - - employeePersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - employeePersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "name"); - OrmPersistentAttribute startDateAttribute = employeePersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "startDate"); - ((OrmBasicMapping) startDateAttribute.getMapping()).setConverter(TemporalConverter.class); - ((TemporalConverter) ((OrmBasicMapping) startDateAttribute.getMapping()).getConverter()).setTemporalType(TemporalType.DATE); - - OrmReadOnlyPersistentAttribute idAttribute = employeePersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = idAttribute.getJavaPersistentAttribute(); - assertNotNull(javaPersistentAttribute); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals("test.Employee", javaPersistentAttribute.getOwningPersistentType().getName()); - assertEquals("test.Model", javaPersistentAttribute.getResourcePersistentAttribute().getParent().getQualifiedName()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java deleted file mode 100644 index 412feb5278..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCoreOrmContextModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreOrmContextModelTests.class.getPackage().getName()); - suite.addTestSuite(OrmXmlTests.class); - suite.addTestSuite(EntityMappingsTests.class); - suite.addTestSuite(PersistenceUnitMetadataTests.class); - suite.addTestSuite(PersistenceUnitDefaultsTests.class); - suite.addTestSuite(GenericOrmPersistentAttributeTests.class); - suite.addTestSuite(GenericOrmPersistentTypeTests.class); - suite.addTestSuite(OrmAssociationOverrideTests.class); - suite.addTestSuite(OrmAttributeOverrideTests.class); - suite.addTestSuite(OrmBasicMappingTests.class); - suite.addTestSuite(OrmCascadeTests.class); - suite.addTestSuite(OrmColumnTests.class); - suite.addTestSuite(OrmDiscriminatorColumnTests.class); - suite.addTestSuite(OrmIdMappingTests.class); - suite.addTestSuite(OrmEmbeddableTests.class); - suite.addTestSuite(OrmEmbeddedMappingTests.class); - suite.addTestSuite(OrmEmbeddedIdMappingTests.class); - suite.addTestSuite(OrmEntityTests.class); - suite.addTestSuite(OrmGeneratedValueTests.class); - suite.addTestSuite(OrmJoinColumnTests.class); - suite.addTestSuite(OrmJoinTableTests.class); - suite.addTestSuite(OrmMappedSuperclassTests.class); - suite.addTestSuite(OrmManyToManyMappingTests.class); - suite.addTestSuite(OrmManyToOneMappingTests.class); - suite.addTestSuite(OrmNamedQueryTests.class); - suite.addTestSuite(OrmNamedNativeQueryTests.class); - suite.addTestSuite(OrmOneToManyMappingTests.class); - suite.addTestSuite(OrmOneToOneMappingTests.class); - suite.addTestSuite(OrmPrimaryKeyJoinColumnTests.class); - suite.addTestSuite(OrmQueryHintTests.class); - suite.addTestSuite(OrmSecondaryTableTests.class); - suite.addTestSuite(OrmSequenceGeneratorTests.class); - suite.addTestSuite(OrmTableGeneratorTests.class); - suite.addTestSuite(OrmTableTests.class); - suite.addTestSuite(OrmTransientMappingTests.class); - suite.addTestSuite(OrmVersionMappingTests.class); - return suite; - } - - private JptCoreOrmContextModelTests() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java deleted file mode 100644 index 2048347390..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmAssociationOverrideTests extends ContextModelTestCase -{ - public OrmAssociationOverrideTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = overrideContainer.specifiedOverrides().next(); - - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - assertFalse(entityResource.getAssociationOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - //set name to null in the resource model - xmlAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(overrideContainer.overrides().hasNext()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = overrideContainer.specifiedOverrides().next(); - - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - //set name in the context model, verify resource model modified - ormAssociationOverride.setName("foo"); - assertEquals("foo", ormAssociationOverride.getName()); - assertEquals("foo", xmlAssociationOverride.getName()); - - //set name to null in the context model - ormAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(entityResource.getAssociationOverrides().get(0).getName()); - } - - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - OrmAssociationOverride ormAssociationOverride = overrideContainer.specifiedOverrides().next(); - OrmJoinColumnRelationshipStrategy joiningStrategy = ormAssociationOverride.getRelationship().getJoinColumnStrategy(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - OrmJoinColumn joinColumn = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - OrmAssociationOverride ormAssociationOverride = overrideContainer.specifiedOverrides().next(); - OrmJoinColumnRelationshipStrategy joiningStrategy = ormAssociationOverride.getRelationship().getJoinColumnStrategy(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, xmlAssociationOverride.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - OrmAssociationOverride ormAssociationOverride = overrideContainer.specifiedOverrides().next(); - OrmJoinColumnRelationshipStrategy joiningStrategy = ormAssociationOverride.getRelationship().getJoinColumnStrategy(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - OrmAssociationOverride ormAssociationOverride = overrideContainer.specifiedOverrides().next(); - OrmJoinColumnRelationshipStrategy joiningStrategy = ormAssociationOverride.getRelationship().getJoinColumnStrategy(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - xmlAssociationOverride.getJoinColumns().get(0).setName("FOO"); - xmlAssociationOverride.getJoinColumns().get(1).setName("BAR"); - xmlAssociationOverride.getJoinColumns().get(2).setName("BAZ"); - - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(2, 0); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(0, 1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(0); - assertFalse(joiningStrategy.specifiedJoinColumns().hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java deleted file mode 100644 index e02a5f2968..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmAttributeOverrideTests extends ContextModelTestCase -{ - public OrmAttributeOverrideTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - XmlAttributeOverride attributeOverrideResource = entityResource.getAttributeOverrides().get(0); - OrmAttributeOverride ormAttributeOverride = overrideContainer.specifiedOverrides().next(); - - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - assertFalse(entityResource.getAttributeOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - attributeOverrideResource.setName("FOO"); - assertEquals("FOO", ormAttributeOverride.getName()); - assertEquals("FOO", attributeOverrideResource.getName()); - - //set name to null in the resource model - attributeOverrideResource.setName(null); - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - - attributeOverrideResource.setName("FOO"); - assertEquals("FOO", ormAttributeOverride.getName()); - assertEquals("FOO", attributeOverrideResource.getName()); - - entityResource.getAttributeOverrides().remove(0); - assertFalse(overrideContainer.overrides().hasNext()); - assertTrue(entityResource.getAttributeOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - XmlAttributeOverride attributeOverrideResource = entityResource.getAttributeOverrides().get(0); - OrmAttributeOverride ormAttributeOverride = overrideContainer.specifiedOverrides().next(); - - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - - //set name in the context model, verify resource model modified - ormAttributeOverride.setName("foo"); - assertEquals("foo", ormAttributeOverride.getName()); - assertEquals("foo", attributeOverrideResource.getName()); - - //set name to null in the context model - ormAttributeOverride.setName(null); - assertNull(ormAttributeOverride.getName()); - assertNull(entityResource.getAttributeOverrides().get(0).getName()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java deleted file mode 100644 index dd59fb8d26..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java +++ /dev/null @@ -1,711 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.LobConverter; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmBasicMappingTests extends ContextModelTestCase -{ - public OrmBasicMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.FETCH_TYPE, JPA.COLUMN, JPA.LOB, JPA.TEMPORAL, JPA.TEMPORAL_TYPE, JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch=FetchType.LAZY, optional=false)"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Lob"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - sb.append(CR); - sb.append(" @Enumerated(EnumType.STRING)"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertEquals("basicMapping", ormBasicMapping.getName()); - assertEquals("basicMapping", basicResource.getName()); - - //set name in the resource model, verify context model updated - basicResource.setName("newName"); - assertEquals("newName", ormBasicMapping.getName()); - assertEquals("newName", basicResource.getName()); - - //set name to null in the resource model - basicResource.setName(null); - assertNull(ormBasicMapping.getName()); - assertNull(basicResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertEquals("basicMapping", ormBasicMapping.getName()); - assertEquals("basicMapping", basicResource.getName()); - - //set name in the context model, verify resource model updated - ormBasicMapping.setName("newName"); - assertEquals("newName", ormBasicMapping.getName()); - assertEquals("newName", basicResource.getName()); - - //set name to null in the context model - ormBasicMapping.setName(null); - assertNull(ormBasicMapping.getName()); - assertNull(basicResource.getName()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - - //set fetch in the resource model, verify context model updated - basicResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, basicResource.getFetch()); - - basicResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, basicResource.getFetch()); - - //set fetch to null in the resource model - basicResource.setFetch(null); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormBasicMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, basicResource.getFetch()); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - - ormBasicMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, basicResource.getFetch()); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormBasicMapping.setSpecifiedFetch(null); - assertNull(basicResource.getFetch()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(basicResource.getEnumerated()); - - //set enumerated in the resource model, verify context model updated - basicResource.setEnumerated(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL, basicResource.getEnumerated()); - - basicResource.setEnumerated(org.eclipse.jpt.core.resource.orm.EnumType.STRING); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.STRING, basicResource.getEnumerated()); - - //set enumerated to null in the resource model - basicResource.setEnumerated(null); - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(basicResource.getEnumerated()); - } - - public void testModifySpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(basicResource.getEnumerated()); - - //set enumerated in the context model, verify resource model updated - ormBasicMapping.setConverter(EnumeratedConverter.class); - ((EnumeratedConverter) ormBasicMapping.getConverter()).setSpecifiedEnumType(EnumType.ORDINAL); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL, basicResource.getEnumerated()); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - - ((EnumeratedConverter) ormBasicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.STRING, basicResource.getEnumerated()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - - //set enumerated to null in the context model - ormBasicMapping.setConverter(null); - assertNull(basicResource.getEnumerated()); - assertNull(ormBasicMapping.getConverter().getType()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - - //set enumerated in the resource model, verify context model updated - basicResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, basicResource.getOptional()); - - basicResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, basicResource.getOptional()); - - //set enumerated to null in the resource model - basicResource.setOptional(null); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - - //set enumerated in the context model, verify resource model updated - ormBasicMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, basicResource.getOptional()); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - - ormBasicMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, basicResource.getOptional()); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - - //set enumerated to null in the context model - ormBasicMapping.setSpecifiedOptional(null); - assertNull(basicResource.getOptional()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - } - - public void testUpdateSpecifiedLob() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getConverter().getType()); - assertFalse(basicResource.isLob()); - - //set lob in the resource model, verify context model updated - basicResource.setLob(true); - assertEquals(LobConverter.class, ormBasicMapping.getConverter().getType()); - assertTrue(basicResource.isLob()); - - //set lob to null in the resource model - basicResource.setLob(false); - assertNull(ormBasicMapping.getConverter().getType()); - assertFalse(basicResource.isLob()); - } - - public void testModifySpecifiedLob() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getConverter().getType()); - assertFalse(basicResource.isLob()); - - //set lob in the context model, verify resource model updated - ormBasicMapping.setConverter(LobConverter.class); - assertTrue(basicResource.isLob()); - assertEquals(LobConverter.class, ormBasicMapping.getConverter().getType()); - - //set lob to false in the context model - ormBasicMapping.setConverter(null); - assertFalse(basicResource.isLob()); - assertNull(ormBasicMapping.getConverter().getType()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(basicResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, basicResource.getTemporal()); - - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, basicResource.getTemporal()); - - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, basicResource.getTemporal()); - - //set temporal to null in the resource model - basicResource.setTemporal(null); - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(basicResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(basicResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormBasicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) ormBasicMapping.getConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, basicResource.getTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - - ((TemporalConverter) ormBasicMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, basicResource.getTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - - ((TemporalConverter) ormBasicMapping.getConverter()).setTemporalType(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, basicResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - - //set temporal to null in the context model - ormBasicMapping.setConverter(null); - assertNull(basicResource.getTemporal()); - assertNull(ormBasicMapping.getConverter().getType()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - - public void testBasicMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormBasicMapping.getName()); - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertEquals(FetchType.EAGER, ormBasicMapping.getFetch()); - assertEquals(true, ormBasicMapping.isOptional()); - - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(255, ormColumn.getDefaultLength()); - assertEquals(0, ormColumn.getDefaultPrecision()); - assertEquals(0, ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", basicMapping.getName()); - assertEquals(EnumeratedConverter.class, basicMapping.getConverter().getType()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getEnumType()); - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - - Column column = basicMapping.getColumn(); - assertEquals("MY_COLUMN", column.getSpecifiedName()); - assertEquals(Boolean.TRUE, column.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, column.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, column.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, column.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", column.getColumnDefinition()); - assertEquals("MY_TABLE", column.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), column.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), column.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), column.getSpecifiedScale()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", basicMapping.getName()); - assertNull(basicMapping.getConverter().getType()); - assertEquals(FetchType.EAGER, basicMapping.getFetch()); - assertTrue(basicMapping.isOptional()); - - Column column = basicMapping.getColumn(); - assertEquals("id", column.getName()); - assertFalse(column.isUnique()); - assertTrue(column.isNullable()); - assertTrue(column.isInsertable()); - assertTrue(column.isUpdatable()); - assertNull(column.getColumnDefinition()); - assertEquals(TYPE_NAME, column.getTable()); - assertEquals(255, column.getLength()); - assertEquals(0, column.getPrecision()); - assertEquals(0, column.getScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormBasicMapping.getName()); - assertNull(ormBasicMapping.getConverter().getType()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertEquals(FetchType.EAGER, ormBasicMapping.getDefaultFetch()); - assertEquals(true, ormBasicMapping.isDefaultOptional()); - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(255, ormColumn.getDefaultLength()); - assertEquals(0, ormColumn.getDefaultPrecision()); - assertEquals(0, ormColumn.getDefaultScale()); - - } - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - - - public void testBasicMorphToIdMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testBasicMorphToVersionMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((VersionMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testBasicMorphToTransientMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToEmbeddedMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToEmbeddedIdMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToOneToOneMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToOneToManyMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToManyToOneMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToManyToManyMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java deleted file mode 100644 index 33d8060138..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java +++ /dev/null @@ -1,280 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmCascadeTests extends ContextModelTestCase -{ - public OrmCascadeTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateCascadeAll() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - assertEquals(false, cascade.isAll()); - assertNotNull(oneToOne.getCascade()); - - //set all in the resource model, verify context model updated - oneToOne.getCascade().setCascadeAll(true); - assertEquals(true, cascade.isAll()); - assertEquals(true, oneToOne.getCascade().isCascadeAll()); - - //set all to false in the resource model - oneToOne.getCascade().setCascadeAll(false); - assertEquals(false, cascade.isAll()); - assertEquals(false, oneToOne.getCascade().isCascadeAll()); - } - - public void testModifyCascadeAll() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - - //set all in the context model, verify resource model updated - cascade.setAll(true); - assertEquals(true, cascade.isAll()); - assertEquals(true, oneToOne.getCascade().isCascadeAll()); - - //set all to false in the context model - cascade.setAll(false); - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadePersist() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - assertEquals(false, cascade.isPersist()); - assertNotNull(oneToOne.getCascade()); - - //set Persist in the resource model, verify context model updated - oneToOne.getCascade().setCascadePersist(true); - assertEquals(true, cascade.isPersist()); - assertEquals(true, oneToOne.getCascade().isCascadePersist()); - - //set Persist to false in the resource model - oneToOne.getCascade().setCascadePersist(false); - assertEquals(false, cascade.isPersist()); - assertEquals(false, oneToOne.getCascade().isCascadePersist()); - } - - public void testModifyCascadePersist() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - - //set Persist in the context model, verify resource model updated - cascade.setPersist(true); - assertEquals(true, cascade.isPersist()); - assertEquals(true, oneToOne.getCascade().isCascadePersist()); - - //set Persist to false in the context model - cascade.setPersist(false); - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeMerge() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - assertEquals(false, cascade.isMerge()); - assertNotNull(oneToOne.getCascade()); - - //set Merge in the resource model, verify context model updated - oneToOne.getCascade().setCascadeMerge(true); - assertEquals(true, cascade.isMerge()); - assertEquals(true, oneToOne.getCascade().isCascadeMerge()); - - //set Merge to false in the resource model - oneToOne.getCascade().setCascadeMerge(false); - assertEquals(false, cascade.isMerge()); - assertEquals(false, oneToOne.getCascade().isCascadeMerge()); - } - - public void testModifyCascadeMerge() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - - //set Merge in the context model, verify resource model updated - cascade.setMerge(true); - assertEquals(true, cascade.isMerge()); - assertEquals(true, oneToOne.getCascade().isCascadeMerge()); - - //set Merge to false in the context model - cascade.setMerge(false); - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeRemove() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - assertEquals(false, cascade.isRemove()); - assertNotNull(oneToOne.getCascade()); - - //set Remove in the resource model, verify context model updated - oneToOne.getCascade().setCascadeRemove(true); - assertEquals(true, cascade.isRemove()); - assertEquals(true, oneToOne.getCascade().isCascadeRemove()); - - //set Remove to false in the resource model - oneToOne.getCascade().setCascadeRemove(false); - assertEquals(false, cascade.isRemove()); - assertEquals(false, oneToOne.getCascade().isCascadeRemove()); - } - - public void testModifyCascadeRemove() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - - //set Remove in the context model, verify resource model updated - cascade.setRemove(true); - assertEquals(true, cascade.isRemove()); - assertEquals(true, oneToOne.getCascade().isCascadeRemove()); - - //set Remove to false in the context model - cascade.setRemove(false); - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeRefresh() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - assertEquals(false, cascade.isRefresh()); - assertNotNull(oneToOne.getCascade()); - - //set Refresh in the resource model, verify context model updated - oneToOne.getCascade().setCascadeRefresh(true); - assertEquals(true, cascade.isRefresh()); - assertEquals(true, oneToOne.getCascade().isCascadeRefresh()); - - //set Refresh to false in the resource model - oneToOne.getCascade().setCascadeRefresh(false); - assertEquals(false, cascade.isRefresh()); - assertEquals(false, oneToOne.getCascade().isCascadeRefresh()); - } - - public void testModifyCascadeRefresh() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - - //set Refresh in the context model, verify resource model updated - cascade.setRefresh(true); - assertEquals(true, cascade.isRefresh()); - assertEquals(true, oneToOne.getCascade().isCascadeRefresh()); - - //set Refresh to false in the context model - cascade.setRefresh(false); - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java deleted file mode 100644 index a14f10d9f1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java +++ /dev/null @@ -1,835 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmColumnTests extends ContextModelTestCase -{ - public OrmColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", basic.getColumn().getName()); - - //set name to null in the resource model - basic.getColumn().setName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn().getName()); - - basic.getColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", basic.getColumn().getName()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedName("foo"); - assertEquals("foo", ormColumn.getSpecifiedName()); - assertEquals("foo", basic.getColumn().getName()); - - //set name to null in the context model - ormColumn.setSpecifiedName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - } - - public void testUpdateColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", basic.getColumn().getColumnDefinition()); - - //set name to null in the resource model - basic.getColumn().setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn().getColumnDefinition()); - - basic.getColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", basic.getColumn().getColumnDefinition()); - - basic.setColumn(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - } - - public void testModifyColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setColumnDefinition("foo"); - assertEquals("foo", ormColumn.getColumnDefinition()); - assertEquals("foo", basic.getColumn().getColumnDefinition()); - - //set name to null in the context model - ormColumn.setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setTable("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedTable()); - assertEquals("FOO", basic.getColumn().getTable()); - - //set name to null in the resource model - basic.getColumn().setTable(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn().getTable()); - - basic.getColumn().setTable("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedTable()); - assertEquals("FOO", basic.getColumn().getTable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedTable("foo"); - assertEquals("foo", ormColumn.getSpecifiedTable()); - assertEquals("foo", basic.getColumn().getTable()); - - //set name to null in the context model - ormColumn.setSpecifiedTable(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setNullable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, basic.getColumn().getNullable()); - - //set name to null in the resource model - basic.getColumn().setNullable(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn().getNullable()); - - basic.getColumn().setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, basic.getColumn().getNullable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, basic.getColumn().getNullable()); - - //set name to null in the context model - ormColumn.setSpecifiedNullable(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setUpdatable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, basic.getColumn().getUpdatable()); - - //set name to null in the resource model - basic.getColumn().setUpdatable(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn().getUpdatable()); - - basic.getColumn().setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, basic.getColumn().getUpdatable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, basic.getColumn().getUpdatable()); - - //set name to null in the context model - ormColumn.setSpecifiedUpdatable(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setInsertable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, basic.getColumn().getInsertable()); - - //set name to null in the resource model - basic.getColumn().setInsertable(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn().getInsertable()); - - basic.getColumn().setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, basic.getColumn().getInsertable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, basic.getColumn().getInsertable()); - - //set name to null in the context model - ormColumn.setSpecifiedInsertable(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setUnique(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, basic.getColumn().getUnique()); - - //set name to null in the resource model - basic.getColumn().setUnique(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn().getUnique()); - - basic.getColumn().setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, basic.getColumn().getUnique()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, basic.getColumn().getUnique()); - - //set name to null in the context model - ormColumn.setSpecifiedUnique(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setLength(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(8), basic.getColumn().getLength()); - - //set name to null in the resource model - basic.getColumn().setLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getLength()); - - basic.getColumn().setLength(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(11), basic.getColumn().getLength()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedLength(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(7), basic.getColumn().getLength()); - - //set name to null in the context model - ormColumn.setSpecifiedLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedPrecision() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setPrecision(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(8), basic.getColumn().getPrecision()); - - //set name to null in the resource model - basic.getColumn().setPrecision(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getPrecision()); - - basic.getColumn().setPrecision(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(11), basic.getColumn().getPrecision()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedPrecision() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedPrecision(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), basic.getColumn().getPrecision()); - - //set name to null in the context model - ormColumn.setSpecifiedPrecision(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedScale() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - basic.getColumn().setScale(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(8), basic.getColumn().getScale()); - - //set name to null in the resource model - basic.getColumn().setScale(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getScale()); - - basic.getColumn().setScale(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(11), basic.getColumn().getScale()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedScale() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedScale(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(7), basic.getColumn().getScale()); - - //set name to null in the context model - ormColumn.setSpecifiedScale(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testVirtualColumnDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - Iterator attributes = ormPersistentType.virtualAttributes(); - attributes.next(); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute namePersistentAttribute = attributes.next(); - BasicMapping nameVirtualMapping = (BasicMapping) namePersistentAttribute.getMapping(); - Column virtualColumn = nameVirtualMapping.getColumn(); - assertEquals("name", virtualColumn.getName()); - assertEquals(TYPE_NAME, virtualColumn.getTable()); - assertNull(virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(Column.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(Column.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(Column.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - JavaColumn javaColumn = javaBasicMapping.getColumn(); - javaColumn.setSpecifiedName("FOO"); - javaColumn.setSpecifiedTable("FOO_TABLE"); - javaColumn.setColumnDefinition("COLUMN_DEFINITION"); - javaColumn.setSpecifiedInsertable(Boolean.FALSE); - javaColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaColumn.setSpecifiedNullable(Boolean.FALSE); - javaColumn.setSpecifiedUnique(Boolean.TRUE); - javaColumn.setSpecifiedLength(Integer.valueOf(45)); - javaColumn.setSpecifiedPrecision(Integer.valueOf(46)); - javaColumn.setSpecifiedScale(Integer.valueOf(47)); - - this.getJpaProject().synchronizeContextModel(); - - nameVirtualMapping = (BasicMapping) namePersistentAttribute.getMapping(); - virtualColumn = nameVirtualMapping.getColumn(); - assertEquals("FOO", virtualColumn.getName()); - assertEquals("FOO_TABLE", virtualColumn.getTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertFalse(virtualColumn.isInsertable()); - assertFalse(virtualColumn.isUpdatable()); - assertFalse(virtualColumn.isNullable()); - assertTrue(virtualColumn.isUnique()); - assertEquals(45, virtualColumn.getLength()); - assertEquals(46, virtualColumn.getPrecision()); - assertEquals(47, virtualColumn.getScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - nameVirtualMapping = (BasicMapping) namePersistentAttribute.getMapping(); - virtualColumn = nameVirtualMapping.getColumn(); - assertEquals("name", virtualColumn.getName()); - assertEquals(TYPE_NAME, virtualColumn.getTable()); - assertNull(virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(Column.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(Column.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(Column.DEFAULT_SCALE, virtualColumn.getScale()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); - nameVirtualMapping = (BasicMapping) namePersistentAttribute.getMapping(); - virtualColumn = nameVirtualMapping.getColumn(); - assertEquals("name", virtualColumn.getName()); - assertEquals(TYPE_NAME, virtualColumn.getTable()); - assertNull(virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(Column.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(Column.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(Column.DEFAULT_SCALE, virtualColumn.getScale()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - nameVirtualMapping = (BasicMapping) namePersistentAttribute.getMapping(); - virtualColumn = nameVirtualMapping.getColumn(); - assertEquals("name", virtualColumn.getName()); - assertEquals(TYPE_NAME, virtualColumn.getTable()); - assertNull(virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(Column.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(Column.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(Column.DEFAULT_SCALE, virtualColumn.getScale()); - - //set metadata-complete false, orm.xml virtual column gets setting from java annotation - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - nameVirtualMapping = (BasicMapping) namePersistentAttribute.getMapping(); - virtualColumn = nameVirtualMapping.getColumn(); - assertEquals("FOO", virtualColumn.getName()); - assertEquals("FOO_TABLE", virtualColumn.getTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertFalse(virtualColumn.isInsertable()); - assertFalse(virtualColumn.isUpdatable()); - assertFalse(virtualColumn.isNullable()); - assertTrue(virtualColumn.isUnique()); - assertEquals(45, virtualColumn.getLength()); - assertEquals(46, virtualColumn.getPrecision()); - assertEquals(47, virtualColumn.getScale()); - } - - public void testNullColumnDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute namePersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "name"); - - OrmBasicMapping nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - OrmColumn ormColumn = nameVirtualMapping.getColumn(); - - //set Column annotation in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - JavaColumn javaColumn = javaBasicMapping.getColumn(); - javaColumn.setSpecifiedName("FOO"); - javaColumn.setSpecifiedTable("FOO_TABLE"); - javaColumn.setColumnDefinition("COLUMN_DEFINITION"); - javaColumn.setSpecifiedInsertable(Boolean.FALSE); - javaColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaColumn.setSpecifiedNullable(Boolean.FALSE); - javaColumn.setSpecifiedUnique(Boolean.TRUE); - javaColumn.setSpecifiedLength(Integer.valueOf(45)); - javaColumn.setSpecifiedPrecision(Integer.valueOf(46)); - javaColumn.setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("name", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualColumnTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute nameOrmAttribute = ormPersistentType.getAttributeNamed("name"); - BasicMapping nameVirtualMapping = (BasicMapping) nameOrmAttribute.getMapping(); - Column virtualColumn = nameVirtualMapping.getColumn(); - - assertEquals(TYPE_NAME, virtualColumn.getTable()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE", virtualColumn.getTable()); - - //set Column table element in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedTable("JAVA_TABLE"); - nameVirtualMapping = (BasicMapping) nameOrmAttribute.getMapping(); - virtualColumn = nameVirtualMapping.getColumn(); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - nameOrmAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "name"); - BasicMapping nameSpecifiedMapping = (OrmBasicMapping) nameOrmAttribute.getMapping(); - Column specifiedColumn = nameSpecifiedMapping.getColumn(); - assertNull(specifiedColumn.getSpecifiedTable()); - assertEquals("ORM_TABLE", specifiedColumn.getDefaultTable()); - assertEquals("ORM_TABLE", specifiedColumn.getTable()); - } - -//public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", xmlEntity.getTable().getDefaultName()); -//} -// -//public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -//} - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java deleted file mode 100644 index a2112eaeb1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java +++ /dev/null @@ -1,456 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmDiscriminatorColumnTests extends ContextModelTestCase -{ - public OrmDiscriminatorColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private void createTestAbstractEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn().getName()); - - entityResource.getDiscriminatorColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedName("foo"); - assertEquals("foo", ormColumn.getSpecifiedName()); - assertEquals("foo", entityResource.getDiscriminatorColumn().getName()); - - //set name to null in the context model - ormColumn.setSpecifiedName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - } - -// public void testUpdateDefaultNameFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.javaEntity().getTable().setSpecifiedName("Foo"); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(null); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.getTable().setSpecifiedName("Bar"); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -// } - - public void testUpdateSpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setLength(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(8), entityResource.getDiscriminatorColumn().getLength()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn().getLength()); - - entityResource.getDiscriminatorColumn().setLength(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(11), entityResource.getDiscriminatorColumn().getLength()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedLength(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(7), entityResource.getDiscriminatorColumn().getLength()); - - //set name to null in the context model - ormColumn.setSpecifiedLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn().getColumnDefinition()); - - entityResource.getDiscriminatorColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setColumnDefinition("foo"); - assertEquals("foo", ormColumn.getColumnDefinition()); - assertEquals("foo", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - //set name to null in the context model - ormColumn.setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testUpdateSpecifiedDiscriminatorType() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set discriminator type in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setDiscriminatorType(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING); - assertEquals(DiscriminatorType.STRING, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - //set discriminator type to null in the resource model - entityResource.getDiscriminatorColumn().setDiscriminatorType(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - entityResource.getDiscriminatorColumn().setDiscriminatorType(org.eclipse.jpt.core.resource.orm.DiscriminatorType.CHAR); - assertEquals(DiscriminatorType.CHAR, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.CHAR, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedDiscriminatorType() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set discriminator type in the context model, verify resource model modified - ormColumn.setSpecifiedDiscriminatorType(DiscriminatorType.STRING); - assertEquals(DiscriminatorType.STRING, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - //set discriminator type to null in the context model - ormColumn.setSpecifiedDiscriminatorType(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testDefaultsNoDiscriminatorColumnInJava() throws Exception { - createTestAbstractEntity(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity abstractEntity = (OrmEntity) persistentType.getMapping(); - - OrmPersistentType childPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + "." + "AnnotationTestTypeChild"); - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - //test defaults with single-table inheritance, no specified discriminator column set - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - - //test defaults with single-table inheritance, specified discriminator column set on root - abstractEntity.getDiscriminatorColumn().setSpecifiedName("DTYPE2"); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(5)); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals("DTYPE2", abstractEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(Integer.valueOf(5), abstractEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(DiscriminatorType.CHAR, abstractEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals("DTYPE2", childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(5, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorType.CHAR, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - //test defaults with table-per-class inheritance, discriminator column does not apply - abstractEntity.getDiscriminatorColumn().setSpecifiedName(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - abstractEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getInheritanceStrategy()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - } - - public void testDefaultsDiscriminatorColumnInJava() throws Exception { - createTestAbstractEntity(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity abstractEntity = (OrmEntity) persistentType.getMapping(); - - OrmPersistentType childPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + "." + "AnnotationTestTypeChild"); - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - ((Entity) persistentType.getJavaPersistentType().getMapping()).getDiscriminatorColumn().setSpecifiedName("FOO"); - ((Entity) persistentType.getJavaPersistentType().getMapping()).getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(5)); - ((Entity) persistentType.getJavaPersistentType().getMapping()).getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - //test defaults with single-table inheritance, specified discriminator column set in java - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals("FOO", abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(5, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorType.CHAR, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals("FOO", childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(5, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorType.CHAR, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - - //test defaults with single-table inheritance, specified discriminator column set in java, metadata-complete true - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - - //test defaults with single-table inheritance, specified discriminator column set in orm - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - abstractEntity.getDiscriminatorColumn().setSpecifiedName("BAR"); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(6)); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.INTEGER); - - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals("BAR", childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(6, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorType.INTEGER, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java deleted file mode 100644 index 225dd7c656..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java +++ /dev/null @@ -1,295 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmEmbeddableTests extends ContextModelTestCase -{ - public OrmEmbeddableTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals("model.Foo", embeddableResource.getClassName()); - - //set class in the resource model, verify context model updated - embeddableResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormEmbeddable.getClass_()); - assertEquals("com.Bar", embeddableResource.getClassName()); - - //set class to null in the resource model - embeddableResource.setClassName(null); - assertNull(ormEmbeddable.getClass_()); - assertNull(embeddableResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals("model.Foo", embeddableResource.getClassName()); - - //set class in the context model, verify resource model modified - ormEmbeddable.setClass("com.Bar"); - assertEquals("com.Bar", ormEmbeddable.getClass_()); - assertEquals("com.Bar", embeddableResource.getClassName()); - - //set class to null in the context model - ormEmbeddable.setClass(null); - assertNull(ormEmbeddable.getClass_()); - assertNull(embeddableResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - - //set access in the resource model, verify context model updated - embeddableResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormPersistentType.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, embeddableResource.getAccess()); - - //set access to null in the resource model - embeddableResource.setAccess(null); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - - //set access in the context model, verify resource model modified - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormPersistentType.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddableResource.getAccess()); - - //set access to null in the context model - ormPersistentType.setSpecifiedAccess(null); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - } - //TODO test default access from - //underlying java - //persistence-unit-defaults - //entity-mappings - //with xml-mapping-metadata-complete set - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertNull(embeddableResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - embeddableResource.setMetadataComplete(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(Boolean.TRUE, embeddableResource.getMetadataComplete()); - - //set access to false in the resource model - embeddableResource.setMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(Boolean.FALSE, embeddableResource.getMetadataComplete()); - - embeddableResource.setMetadataComplete(null); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertNull(embeddableResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormEmbeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(Boolean.TRUE, embeddableResource.getMetadataComplete()); - - //set access to null in the context model - ormEmbeddable.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(Boolean.FALSE, embeddableResource.getMetadataComplete()); - - ormEmbeddable.setSpecifiedMetadataComplete(null); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isOverrideMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEmbeddable.isOverrideMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isOverrideMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = getXmlEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEmbeddable.isMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormEmbeddable.isMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testMakeEmbeddableEntity() throws Exception { - OrmPersistentType embeddablePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddablePersistentType.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, embeddablePersistentType.getSpecifiedAccess()); - } - - //test with 2 Embeddables, make the second one an Entity so it has to move to the front of the list - public void testMakeEmbeddableEntity2() throws Exception { - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType embeddablePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddablePersistentType.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, embeddablePersistentType.getSpecifiedAccess()); - - ListIterator persistentTypes = getEntityMappings().getPersistentTypes().iterator(); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testMakeEmbeddableMappedSuperclass() throws Exception { - OrmPersistentType embeddablePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddablePersistentType.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, embeddablePersistentType.getSpecifiedAccess()); - } - - //test with 2 Embeddables, make the second one a MappedSuperclass so it has to move to the front of the list - public void testMakeEmbeddableMappedSuperclass2() throws Exception { - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType embeddablePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddablePersistentType.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, embeddablePersistentType.getSpecifiedAccess()); - - ListIterator persistentTypes = getEntityMappings().getPersistentTypes().iterator(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java deleted file mode 100644 index fa79308f0c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java +++ /dev/null @@ -1,923 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaVirtualColumn; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVirtualAttributeOverride; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmEmbeddedIdMappingTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public OrmEmbeddedIdMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityEmbeddedIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDED_ID, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @EmbeddedId"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Column(name=\"A_STATE\")").append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName()); -// assertEquals("embeddedIdMapping", embeddedIdResource.getName()); -// -// //set name in the resource model, verify context model updated -// embeddedIdResource.setName("newName"); -// assertEquals("newName", xmlEmbeddedIdMapping.getName()); -// assertEquals("newName", embeddedIdResource.getName()); -// -// //set name to null in the resource model -// embeddedIdResource.setName(null); -// assertNull(xmlEmbeddedIdMapping.getName()); -// assertNull(embeddedIdResource.getName()); -// } -// -// public void testModifyName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName()); -// assertEquals("embeddedIdMapping", embeddedIdResource.getName()); -// -// //set name in the context model, verify resource model updated -// xmlEmbeddedIdMapping.setName("newName"); -// assertEquals("newName", xmlEmbeddedIdMapping.getName()); -// assertEquals("newName", embeddedIdResource.getName()); -// -// //set name to null in the context model -// xmlEmbeddedIdMapping.setName(null); -// assertNull(xmlEmbeddedIdMapping.getName()); -// assertNull(embeddedIdResource.getName()); -// } -// -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// XmlAttributeOverride attributeOverride = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0); -// ormResource().save(null); -// attributeOverride.setName("FOO"); -// ormResource().save(null); -// -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// -// XmlAttributeOverride attributeOverride2 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0); -// ormResource().save(null); -// attributeOverride2.setName("BAR"); -// ormResource().save(null); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// -// XmlAttributeOverride attributeOverride3 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1); -// ormResource().save(null); -// attributeOverride3.setName("BAZ"); -// ormResource().save(null); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedIdResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedIdResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedIdResource.getAttributeOverrides().size()); -// } -// -// public void testMoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); -// -// -// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(2, 0); -// ListIterator attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// -// -// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(0, 1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// } -// -// public void testUpdateAttributeOverrides() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverride()); -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverride()); -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverride()); -// -// embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); -// embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); -// embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); -// -// ListIterator attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().move(2, 0); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().move(0, 1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(0); -// assertFalse(xmlEmbeddedIdMapping.specifiedAttributeOverrides().hasNext()); -// } - - public void testEmbeddedIdMorphToIdMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToEmbeddedMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedMapping) ormPersistentAttribute.getMapping()).getAttributeOverrideContainer().specifiedOverrides().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedIdMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedIdMapping.getAttributeOverrideContainer(); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); - - attributeOverrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); - - - attributeOverrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedIdMapping.getAttributeOverrideContainer(); - XmlEmbeddedId embeddedIdResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().move(2, 0); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().move(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(0); - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedIdMapping.getAttributeOverrideContainer(); - - assertEquals("foo", ormEmbeddedIdMapping.getName()); - - - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - assertFalse(attributeOverrideContainer.virtualOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType embeddableAddressType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME_ + "Address"); - - //embedded mapping is virtual, attribute overrides should exist - OrmReadOnlyPersistentAttribute ormPersistentAttribute = persistentType.getAttributeNamed("address"); - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - AttributeOverride specifiedAttributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", specifiedAttributeOverride.getName()); - - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - - JavaEmbeddedIdMapping javaEmbeddedIdMapping = (JavaEmbeddedIdMapping) ormPersistentAttribute.resolveJavaPersistentAttribute().getMapping(); - Column javaAttributeOverrideColumn = javaEmbeddedIdMapping.getAttributeOverrideContainer().specifiedOverrides().next().getColumn(); - - javaAttributeOverrideColumn.setSpecifiedName("FOO_COLUMN"); - javaAttributeOverrideColumn.setSpecifiedTable("FOO_TABLE"); - javaAttributeOverrideColumn.setColumnDefinition("COLUMN_DEF"); - javaAttributeOverrideColumn.setSpecifiedInsertable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUnique(Boolean.TRUE); - javaAttributeOverrideColumn.setSpecifiedNullable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedLength(Integer.valueOf(5)); - javaAttributeOverrideColumn.setSpecifiedPrecision(Integer.valueOf(6)); - javaAttributeOverrideColumn.setSpecifiedScale(Integer.valueOf(7)); - - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) embeddableAddressType.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - specifiedAttributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", specifiedAttributeOverride.getName()); - assertEquals("FOO_COLUMN", specifiedAttributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(false, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(5, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(6, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(7, specifiedAttributeOverride.getColumn().getScale()); - - virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", virtualAttributeOverride.getColumn().getSpecifiedName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").convertToSpecified(); - OrmEmbeddedIdMapping ormMapping = (OrmEmbeddedIdMapping) persistentType.getAttributeNamed("address").getMapping(); - OrmAttributeOverrideContainer ormOverrideContainer = ormMapping.getAttributeOverrideContainer(); - assertEquals(4, ormOverrideContainer.overridesSize()); - assertEquals(4, ormOverrideContainer.virtualOverridesSize()); - assertEquals(0, ormOverrideContainer.specifiedOverridesSize()); - ListIterator ormOverrides = ormOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride ormOverride = ormOverrides.next(); - assertEquals("id", ormOverride.getName()); - ormOverride = ormOverrides.next(); - assertEquals("city", ormOverride.getName()); - assertEquals("city", ormOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, ormOverride.getColumn().getDefaultTable()); - assertEquals(null, ormOverride.getColumn().getColumnDefinition()); - assertEquals(true, ormOverride.getColumn().isInsertable()); - assertEquals(true, ormOverride.getColumn().isUpdatable()); - assertEquals(false, ormOverride.getColumn().isUnique()); - assertEquals(true, ormOverride.getColumn().isNullable()); - assertEquals(255, ormOverride.getColumn().getLength()); - assertEquals(0, ormOverride.getColumn().getPrecision()); - assertEquals(0, ormOverride.getColumn().getScale()); - ormOverride = ormOverrides.next(); - assertEquals("state", ormOverride.getName()); - assertEquals("MY_STATE_COLUMN", ormOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, ormOverride.getColumn().getDefaultTable()); - ormOverride = ormOverrides.next(); - assertEquals("zip", ormOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - ormOverrideContainer.virtualOverrides().next().convertToSpecified(); - - assertEquals(4, ormOverrideContainer.overridesSize()); - assertEquals(1, ormOverrideContainer.specifiedOverridesSize()); - assertEquals(3, ormOverrideContainer.virtualOverridesSize()); - assertEquals("id", ormOverrideContainer.specifiedOverrides().next().getName()); - ormOverrides = ormOverrideContainer.virtualOverrides(); - ormOverride = ormOverrides.next(); - assertEquals("city", ormOverride.getName()); - ormOverride = ormOverrides.next(); - assertEquals("state", ormOverride.getName()); - ormOverride = ormOverrides.next(); - assertEquals("zip", ormOverride.getName()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME_ + "Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals("address", embeddedIdMapping.getName()); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - AttributeOverride specifiedAttributeOverride = specifiedAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getSpecifiedName()); - - this.ormXmlResource.saveIfNecessary(); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - JavaVirtualColumn virtualColumn = virtualAttributeOverride.getColumn(); - assertEquals("id", virtualColumn.getName()); - assertNull(virtualColumn.getSpecifiedName()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - virtualColumn = virtualAttributeOverride.getColumn(); - assertEquals("A_STATE", virtualColumn.getName()); - assertEquals("A_STATE", virtualColumn.getSpecifiedName()); - assertEquals("A_STATE", virtualColumn.getDefaultName()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualColumn = virtualAttributeOverride.getColumn(); - assertEquals("zip", virtualColumn.getName()); - assertNull(virtualColumn.getSpecifiedName()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertTrue(ormPersistentAttribute.isVirtual()); - - //will be an OrmEmbeddedMapping instead of OrmEmbeddedIdMapping since that is the default - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", embeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedIdMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedIdMapping.defaultAttributeOverrides())); -// ListIterator ormAttributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedIdMapping.getName()); - - assertEquals(0, ormEmbeddedIdMapping.getAttributeOverrideContainer().specifiedOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedIdMapping.defaultAttributeOverrides())); -// ListIterator ormAttributeOverrides = ormEmbeddedIdMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java deleted file mode 100644 index ad7b8ed1e9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java +++ /dev/null @@ -1,943 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.VirtualColumn; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVirtualAttributeOverride; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmEmbeddedMappingTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public OrmEmbeddedMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityEmbeddedMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Column(name=\"A_STATE\")").append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress2() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// OrmAttributeOverride attributeOverride = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride.setName("FOO"); -// -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// OrmAttributeOverride attributeOverride2 = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride2.setName("BAR"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// OrmAttributeOverride attributeOverride3 = ormEmbeddedMapping.addSpecifiedAttributeOverride(1); -// attributeOverride3.setName("BAZ"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// ormEmbeddedMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedResource.getAttributeOverrides().size()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedResource.getAttributeOverrides().size()); -// } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedResource.getAttributeOverrides().size()); - - attributeOverrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - - - attributeOverrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(2, 0); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(0); - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - - assertEquals("foo", ormEmbeddedMapping.getName()); - - - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - assertFalse(attributeOverrideContainer.virtualOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME_ + "Address"); - - //embedded mapping is virtual, Java attribute overrides should exist - OrmReadOnlyPersistentAttribute ormPersistentAttribute = persistentType.getAttributeNamed("address"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) ormPersistentAttribute.getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - AttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - JavaVirtualAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - - JavaEmbeddedMapping javaEmbeddedMapping = (JavaEmbeddedMapping) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - Column javaAttributeOverrideColumn = javaEmbeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next().getColumn(); - - javaAttributeOverrideColumn.setSpecifiedName("FOO_COLUMN"); - javaAttributeOverrideColumn.setSpecifiedTable("FOO_TABLE"); - javaAttributeOverrideColumn.setColumnDefinition("COLUMN_DEF"); - javaAttributeOverrideColumn.setSpecifiedInsertable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUnique(Boolean.TRUE); - javaAttributeOverrideColumn.setSpecifiedNullable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedLength(Integer.valueOf(5)); - javaAttributeOverrideColumn.setSpecifiedPrecision(Integer.valueOf(6)); - javaAttributeOverrideColumn.setSpecifiedScale(Integer.valueOf(7)); - - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType2.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - embeddedMapping = (JavaEmbeddedMapping) ormPersistentAttribute.getMapping(); - attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", attributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, attributeOverride.getColumn().isInsertable()); - assertEquals(false, attributeOverride.getColumn().isUpdatable()); - assertEquals(true, attributeOverride.getColumn().isUnique()); - assertEquals(false, attributeOverride.getColumn().isNullable()); - assertEquals(5, attributeOverride.getColumn().getLength()); - assertEquals(6, attributeOverride.getColumn().getPrecision()); - assertEquals(7, attributeOverride.getColumn().getScale()); - - virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualOverride.getName()); - assertEquals("MY_STATE_COLUMN", virtualOverride.getColumn().getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").convertToSpecified(); - OrmEmbeddedMapping ormMapping = (OrmEmbeddedMapping) persistentType.getAttributeNamed("address").getMapping(); - OrmAttributeOverrideContainer ormOverrideContainer = ormMapping.getAttributeOverrideContainer(); - assertEquals(4, ormOverrideContainer.overridesSize()); - assertEquals(4, ormOverrideContainer.virtualOverridesSize()); - assertEquals(0, ormOverrideContainer.specifiedOverridesSize()); - ListIterator ormVirtualAttributeOverrides = ormOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride ormVirtualOverride = ormVirtualAttributeOverrides.next(); - assertEquals("id", ormVirtualOverride.getName()); - ormVirtualOverride = ormVirtualAttributeOverrides.next(); - assertEquals("city", ormVirtualOverride.getName()); - assertEquals("city", ormVirtualOverride.getColumn().getName()); - assertEquals(TYPE_NAME, ormVirtualOverride.getColumn().getTable()); - assertEquals(null, ormVirtualOverride.getColumn().getColumnDefinition()); - assertEquals(true, ormVirtualOverride.getColumn().isInsertable()); - assertEquals(true, ormVirtualOverride.getColumn().isUpdatable()); - assertEquals(false, ormVirtualOverride.getColumn().isUnique()); - assertEquals(true, ormVirtualOverride.getColumn().isNullable()); - assertEquals(255, ormVirtualOverride.getColumn().getLength()); - assertEquals(0, ormVirtualOverride.getColumn().getPrecision()); - assertEquals(0, ormVirtualOverride.getColumn().getScale()); - ormVirtualOverride = ormVirtualAttributeOverrides.next(); - assertEquals("state", ormVirtualOverride.getName()); - assertEquals("MY_STATE_COLUMN", ormVirtualOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, ormVirtualOverride.getColumn().getDefaultTable()); - ormVirtualOverride = ormVirtualAttributeOverrides.next(); - assertEquals("zip", ormVirtualOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - ormOverrideContainer.virtualOverrides().next().convertToSpecified(); - - assertEquals(4, ormOverrideContainer.overridesSize()); - assertEquals(1, ormOverrideContainer.specifiedOverridesSize()); - assertEquals(3, ormOverrideContainer.virtualOverridesSize()); - assertEquals("id", ormOverrideContainer.specifiedOverrides().next().getName()); - ormVirtualAttributeOverrides = ormOverrideContainer.virtualOverrides(); - ormVirtualOverride = ormVirtualAttributeOverrides.next(); - assertEquals("city", ormVirtualOverride.getName()); - ormVirtualOverride = ormVirtualAttributeOverrides.next(); - assertEquals("state", ormVirtualOverride.getName()); - ormVirtualOverride = ormVirtualAttributeOverrides.next(); - assertEquals("zip", ormVirtualOverride.getName()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) ormPersistentAttribute.getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals("address", embeddedMapping.getName()); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - JavaAttributeOverride specifiedAttributeOverride = specifiedAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getSpecifiedName()); - - - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - VirtualColumn virtualColumn = virtualAttributeOverride.getColumn(); - assertEquals("id", virtualColumn.getName()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - virtualColumn = virtualAttributeOverride.getColumn(); - assertEquals("A_STATE", virtualColumn.getName()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualColumn = virtualAttributeOverride.getColumn(); - assertEquals("zip", virtualColumn.getName()); - - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", embeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator ormAttributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedMapping.getName()); - - assertEquals(0, ormEmbeddedMapping.getAttributeOverrideContainer().specifiedOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator ormAttributeOverrides = ormEmbeddedMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - - - public void testEmbeddedMorphToIdMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToEmbeddedIdMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedIdMapping) ormPersistentAttribute.getMapping()).getAttributeOverrideContainer().specifiedOverrides().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - //1.0 projects do not support dot-notation, this tests to make sure that support does not exist - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress2(); - createTestEmbeddableZipCode(); - - OrmPersistentType customerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - customerPersistentType.getAttributeNamed("address").convertToSpecified(); - OrmEmbeddedMapping embeddedMapping = (OrmEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - assertEquals(false, virtualAttributeOverrides.hasNext()); - - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - OrmEmbeddedMapping nestedEmbeddedMapping = (OrmEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - OrmAttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = nestedAttributeOverrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) ((OrmEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify there is no attribute override named zipCode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) ((OrmEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java deleted file mode 100644 index c907067943..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java +++ /dev/null @@ -1,2790 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.IdClassReference; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.ReadOnlyPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.ReadOnlySecondaryTable; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmVirtualAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmVirtualJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmVirtualJoinColumnRelationship; -import org.eclipse.jpt.core.context.orm.OrmVirtualJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmVirtualSecondaryTable; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmEntityTests extends ContextModelTestCase -{ - protected static final String CHILD_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_CHILD_TYPE_NAME = PACKAGE_NAME + "." + CHILD_TYPE_NAME; - - - public OrmEntityTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityDefaultFieldAccess() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityFieldAccess() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityPropertyAccess() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append(CHILD_TYPE_NAME).append(" "); - sb.append("extends ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestSubTypeUnmapped() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append(CHILD_TYPE_NAME).append(" "); - sb.append("extends ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator( - JPA.MAPPED_SUPERCLASS, - JPA.BASIC, - JPA.VERSION, - JPA.TRANSIENT, - JPA.EMBEDDED, - JPA.EMBEDDED_ID, - JPA.ONE_TO_ONE, - JPA.ONE_TO_MANY, - JPA.MANY_TO_ONE, - JPA.MANY_TO_MANY, - JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @Basic"); - sb.append(CR); - sb.append(" private int basic;").append(CR); - sb.append(CR); - sb.append(" @Version"); - sb.append(CR); - sb.append(" private int version;").append(CR); - sb.append(CR); - sb.append(" @Transient"); - sb.append(CR); - sb.append(" private int transient;").append(CR); - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" private int embedded;").append(CR); - sb.append(CR); - sb.append(" @EmbeddedId"); - sb.append(CR); - sb.append(" private int embeddedId;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private " + CHILD_TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int oneToMany;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int manyToOne;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int manyToMany;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestAbstractType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - private ICompilationUnit createAbstractTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - sb.append("abstract"); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private void createTestIdClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append("TestTypeId").append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - - //set name in the resource model, verify context model updated - entityResource.setName("foo"); - assertEquals("foo", ormEntity.getSpecifiedName()); - assertEquals("foo", entityResource.getName()); - - //set name to null in the resource model - entityResource.setName(null); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - - //set name in the context model, verify resource model modified - ormEntity.setSpecifiedName("foo"); - assertEquals("foo", ormEntity.getSpecifiedName()); - assertEquals("foo", entityResource.getName()); - - //set name to null in the context model - ormEntity.setSpecifiedName(null); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - } - - public void testUpdateDefaultName() throws Exception { - createTestEntityFieldAccess(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - ormEntity.getJavaTypeMapping().setSpecifiedName("Foo"); - //xml default entity name comes from java - assertEquals("Foo", ormEntity.getDefaultName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("Bar", ormEntity.getDefaultName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertNull(ormEntity.getDefaultName()); - - entityResource.setClassName(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("Foo", ormEntity.getDefaultName()); - entityResource.setMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - ormEntity.getJavaTypeMapping().setSpecifiedName("Foo1"); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - entityResource.setMetadataComplete(null); - assertEquals("Foo1", ormEntity.getDefaultName()); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals("Foo", ormEntity.getName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("Bar", ormEntity.getName()); - - entityResource.setName("Baz"); - assertEquals("Baz", ormEntity.getName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertEquals("Baz", ormEntity.getName()); - - entityResource.setName(null); - assertNull(ormEntity.getName()); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals("model.Foo", entityResource.getClassName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormEntity.getClass_()); - assertEquals("com.Bar", entityResource.getClassName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertNull(ormEntity.getClass_()); - assertNull(entityResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals("model.Foo", entityResource.getClassName()); - - //set class in the context model, verify resource model modified - ormEntity.setClass("com.Bar"); - assertEquals("com.Bar", ormEntity.getClass_()); - assertEquals("com.Bar", entityResource.getClassName()); - - //set class to null in the context model - ormEntity.setClass(null); - assertNull(ormEntity.getClass_()); - assertNull(entityResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - //set access in the resource model, verify context model updated - entityResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormPersistentType.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, entityResource.getAccess()); - - //set access to null in the resource model - entityResource.setAccess(null); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - //set access in the context model, verify resource model modified - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormPersistentType.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entityResource.getAccess()); - - //set access to null in the context model - ormPersistentType.setSpecifiedAccess(null); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - } - - public void testUpdateDefaultAccessFromPersistenceUnitDefaults() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - assertNull(entityResource.getAccess()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - assertNull(entityResource.getAccess()); - } - - public void testUpdateDefaultAccessFromJava() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - //java has no annotations, defaultAccess in xml is FIELD anyway - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - //entityMappings access wins over persistence-unit-defaults access - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - getEntityMappings().setSpecifiedAccess(null); - //persistence-unit-defaults access used now - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - //java has annotations on fields now, that should win in all cases - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.PROPERTY); - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - } - - public void testUpdateDefaultAccessFromJavaFieldAccess() throws Exception { - createTestEntityFieldAccess(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - } - - public void testUpdateDefaultAccessFromJavaPropertyAccess() throws Exception { - createTestEntityPropertyAccess(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - } - - public void testUpdateDefaultAccessNoUnderlyingJava() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - } - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - entityResource.setMetadataComplete(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(Boolean.TRUE, entityResource.getMetadataComplete()); - - //set access to false in the resource model - entityResource.setMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(Boolean.FALSE, entityResource.getMetadataComplete()); - - entityResource.setMetadataComplete(null); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertTrue(ormEntity.getSpecifiedMetadataComplete().booleanValue()); - assertTrue(entityResource.getMetadataComplete().booleanValue()); - - //set access to null in the context model - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertFalse(ormEntity.getSpecifiedMetadataComplete().booleanValue()); - assertFalse(entityResource.getMetadataComplete().booleanValue()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isOverrideMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEntity.isOverrideMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isOverrideMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEntity.getSpecifiedMetadataComplete()); - assertTrue(ormEntity.isOverrideMetadataComplete()); - assertTrue(ormEntity.isMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEntity.isMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormEntity.isMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - - public void testUpdateInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set inheritance strategy in the resource model, verify context model updated - entityResource.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.TABLE_PER_CLASS, ormEntity.getInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS, entityResource.getInheritance().getStrategy()); - } - - public void testUpdateDefaultInheritanceStrategyFromJava() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - //no inheritance strategy specified in java so single-table is default - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.getJavaTypeMapping().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - //inheritance tag exists in xml, so it overrides anything in java - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedInheritanceStrategy(null); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //this setting overrides the false meta-data complete found on ormEntity - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - } - - public void testUpdateDefaultInheritanceStrategyFromParent() throws Exception { - createTestEntityDefaultFieldAccess(); - createTestSubType(); - - OrmPersistentType superPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType subPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) superPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) subPersistentType.getMapping(); - - assertEquals(parentXmlEntity, childXmlEntity.getParentEntity()); - assertEquals(InheritanceType.SINGLE_TABLE, childXmlEntity.getDefaultInheritanceStrategy()); - - //change root inheritance strategy, verify default is changed for child entity - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - assertEquals(InheritanceType.SINGLE_TABLE, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childXmlEntity.getDefaultInheritanceStrategy()); - assertNull(childXmlEntity.getSpecifiedInheritanceStrategy()); - - //set specified inheritance strategy in java and verify defaults in xml are correct - parentXmlEntity.setSpecifiedInheritanceStrategy(null); - parentXmlEntity.getJavaTypeMapping().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.JOINED, childXmlEntity.getDefaultInheritanceStrategy()); - assertNull(parentXmlEntity.getSpecifiedInheritanceStrategy()); - assertNull(childXmlEntity.getSpecifiedInheritanceStrategy()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(InheritanceType.SINGLE_TABLE, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.SINGLE_TABLE, childXmlEntity.getDefaultInheritanceStrategy()); - } - - public void testUpdateSpecifiedInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set strategy in the resource model, verify context model updated - entityResource.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.JOINED, entityResource.getInheritance().getStrategy()); - - //set strategy to null in the resource model - entityResource.getInheritance().setStrategy(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance().getStrategy()); - - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.SINGLE_TABLE); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.SINGLE_TABLE, entityResource.getInheritance().getStrategy()); - - entityResource.setInheritance(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - } - - public void testModifySpecifiedInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set strategy in the context model, verify resource model modified - ormEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - assertEquals(InheritanceType.TABLE_PER_CLASS, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS, entityResource.getInheritance().getStrategy()); - - //set strategy to null in the context model - ormEntity.setSpecifiedInheritanceStrategy(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - } - - public void testAddSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedName("FOO"); - - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getName()); - - OrmSecondaryTable secondaryTable2 = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable2.setSpecifiedName("BAR"); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(1).getName()); - - OrmSecondaryTable secondaryTable3 = ormEntity.addSpecifiedSecondaryTable(1); - secondaryTable3.setSpecifiedName("BAZ"); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - - ListIterator secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals(secondaryTable2, secondaryTables.next()); - assertEquals(secondaryTable3, secondaryTables.next()); - assertEquals(secondaryTable, secondaryTables.next()); - - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - } - - public void testRemoveSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getSecondaryTables().size()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(2, entityResource.getSecondaryTables().size()); - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(1, entityResource.getSecondaryTables().size()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(0).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testMoveSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getSecondaryTables().size()); - - - ormEntity.moveSpecifiedSecondaryTable(2, 0); - ListIterator secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - - - ormEntity.moveSpecifiedSecondaryTable(0, 1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - - assertEquals("BAZ", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAR", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - } - - public void testUpdateSecondaryTables() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTable()); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTable()); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTable()); - - entityResource.getSecondaryTables().get(0).setName("FOO"); - entityResource.getSecondaryTables().get(1).setName("BAR"); - entityResource.getSecondaryTables().get(2).setName("BAZ"); - - ListIterator secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().move(2, 0); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().move(0, 1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - } - - public void testVirtualSecondaryTables() throws Exception { - createTestEntityFieldAccess(); - createTestSubType(); - - OrmPersistentType superPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType subPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentOrmEntity = (OrmEntity) superPersistentType.getMapping(); - OrmEntity childOrmEntity = (OrmEntity) subPersistentType.getMapping(); - JavaEntity javaEntity = childOrmEntity.getJavaTypeMapping(); - - JavaSecondaryTable javaSecondaryTableFoo = javaEntity.addSpecifiedSecondaryTable(0); - javaSecondaryTableFoo.setSpecifiedName("FOO"); - OrmVirtualSecondaryTable virtualSecondaryTableFoo = childOrmEntity.virtualSecondaryTables().next(); - assertEquals("FOO", childOrmEntity.secondaryTables().next().getName()); - assertEquals("FOO", virtualSecondaryTableFoo.getName()); - assertEquals(0, virtualSecondaryTableFoo.specifiedPrimaryKeyJoinColumnsSize()); - assertEquals("id", virtualSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultName()); - assertEquals("id", virtualSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultReferencedColumnName()); - - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(1, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(1, childOrmEntity.secondaryTablesSize()); - - javaEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - ListIterator virtualSecondaryTables = childOrmEntity.virtualSecondaryTables(); - ListIterator secondaryTables = childOrmEntity.secondaryTables(); - assertEquals("BAR", virtualSecondaryTables.next().getName()); - assertEquals("FOO", virtualSecondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - - childOrmEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - - childOrmEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - - - childOrmEntity.setSecondaryTablesAreDefinedInXml(true); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - ListIterator specifiedSecondaryTables = childOrmEntity.specifiedSecondaryTables(); - assertEquals("BAR", specifiedSecondaryTables.next().getName()); - OrmSecondaryTable specifiedSecondaryTableFoo = specifiedSecondaryTables.next(); - assertEquals("FOO", specifiedSecondaryTableFoo.getName()); - assertEquals(0, specifiedSecondaryTableFoo.specifiedPrimaryKeyJoinColumnsSize()); - assertEquals("id", specifiedSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultName()); - assertEquals("id", specifiedSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultReferencedColumnName()); - - - childOrmEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(1, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(1, childOrmEntity.secondaryTablesSize()); - assertEquals("FOO", childOrmEntity.specifiedSecondaryTables().next().getName()); - - - childOrmEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - virtualSecondaryTables = childOrmEntity.virtualSecondaryTables(); - assertEquals("BAR", virtualSecondaryTables.next().getName()); - assertEquals("FOO", virtualSecondaryTables.next().getName()); - - - //add a specified secondary table to the parent, this will not affect virtual secondaryTables in child - parentOrmEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("PARENT_TABLE"); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - } - - public void testAssociatedTables() throws Exception { - createTestEntityFieldAccess(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertEquals(1, CollectionTools.size(entity.associatedTables())); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - assertEquals(2, CollectionTools.size(entity.associatedTables())); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - assertEquals(3, CollectionTools.size(entity.associatedTables())); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - // TODO - } - - public void testTableNameIsInvalid() throws Exception { - // TODO - } - - public void testMakeEntityEmbeddable() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = getXmlEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, entityPersistentType.getSpecifiedAccess()); - } - - //TODO test that attribute mappings are not removed when changing type mapping. - public void testMakeEntityEmbeddable2() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); -// entityPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - - entityPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = getXmlEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); -// assertEquals("basicMapping", embeddable.getAttributes().getBasics().get(0).getName()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, entityPersistentType.getSpecifiedAccess()); -// assertEquals("basicMapping", ormEmbeddable.persistentType().attributes().next().getName()); - } - - public void testMakeEntityMappedSuperclass() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, entityPersistentType.getSpecifiedAccess()); - } - - public void testMakeEntityMappedSuperclass2() throws Exception { - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, entityPersistentType.getSpecifiedAccess()); - } - - - public void testAddSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - ormEntity.getGeneratorContainer().addSequenceGenerator(); - - assertNotNull(entityResource.getSequenceGenerator()); - assertNotNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormEntity.getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - ormEntity.getGeneratorContainer().addSequenceGenerator(); - assertNotNull(entityResource.getSequenceGenerator()); - assertNotNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - - ormEntity.getGeneratorContainer().removeSequenceGenerator(); - - assertNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormEntity.getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - assertEquals(0, ormEntity.getPersistenceUnit().generatorsSize()); - - entityResource.setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGenerator()); - - assertNotNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - assertNotNull(entityResource.getSequenceGenerator()); - assertEquals(1, ormEntity.getPersistenceUnit().generatorsSize()); - - ormEntity.getGeneratorContainer().getSequenceGenerator().setName("foo"); - assertEquals(1, ormEntity.getPersistenceUnit().generatorsSize()); - - entityResource.setSequenceGenerator(null); - assertNull(ormEntity.getGeneratorContainer().getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - assertEquals(0, ormEntity.getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getGeneratorContainer().getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - ormEntity.getGeneratorContainer().addTableGenerator(); - - assertNotNull(entityResource.getTableGenerator()); - assertNotNull(ormEntity.getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - ormEntity.getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getGeneratorContainer().getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - ormEntity.getGeneratorContainer().addTableGenerator(); - assertNotNull(entityResource.getTableGenerator()); - assertNotNull(ormEntity.getGeneratorContainer().getTableGenerator()); - - ormEntity.getGeneratorContainer().removeTableGenerator(); - - assertNull(ormEntity.getGeneratorContainer().getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - //try removing the table generator again, should get an IllegalStateException - try { - ormEntity.getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getGeneratorContainer().getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - assertEquals(0, ormEntity.getPersistenceUnit().generatorsSize()); - - entityResource.setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGenerator()); - - assertNotNull(ormEntity.getGeneratorContainer().getTableGenerator()); - assertNotNull(entityResource.getTableGenerator()); - assertEquals(1, ormEntity.getPersistenceUnit().generatorsSize()); - - ormEntity.getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, ormEntity.getPersistenceUnit().generatorsSize()); - - entityResource.setTableGenerator(null); - assertNull(ormEntity.getGeneratorContainer().getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - assertEquals(0, ormEntity.getPersistenceUnit().generatorsSize()); - } - - public void testUpdateDiscriminatorColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNotNull(ormEntity.getDiscriminatorColumn()); - - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setName("FOO"); - - assertEquals("FOO", ormEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - entityResource.getDiscriminatorColumn().setName(null); - - assertNull(ormEntity.getDiscriminatorColumn().getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn().getName()); - - entityResource.setDiscriminatorColumn(null); - - assertNotNull(ormEntity.getDiscriminatorColumn()); - } - - public void testUpdateDiscriminatorValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - - entityResource.setDiscriminatorValue("FOO"); - - assertEquals("FOO", ormEntity.getSpecifiedDiscriminatorValue()); - assertEquals("FOO", entityResource.getDiscriminatorValue()); - - entityResource.setDiscriminatorValue(null); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - } - - public void testModifyDiscriminatorValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - - ormEntity.setSpecifiedDiscriminatorValue("FOO"); - - assertEquals("FOO", ormEntity.getSpecifiedDiscriminatorValue()); - assertEquals("FOO", entityResource.getDiscriminatorValue()); - - ormEntity.setSpecifiedDiscriminatorValue(null); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - } - - public void testGetDefaultDiscriminatorValue() throws Exception { - createTestEntityFieldAccess(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - JavaEntity javaEntity = (JavaEntity) persistentType.getJavaPersistentType().getMapping(); - assertEquals(null, ormEntity.getDefaultDiscriminatorValue()); - - createTestSubType(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - assertEquals(ormEntity.getName(), ormEntity.getDefaultDiscriminatorValue()); - - javaEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.INTEGER); - assertNull(ormEntity.getDefaultDiscriminatorValue()); - - javaEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - javaEntity.setSpecifiedDiscriminatorValue("FOO"); - - assertEquals("FOO", ormEntity.getDefaultDiscriminatorValue()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(ormEntity.getName(), ormEntity.getDefaultDiscriminatorValue()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn2 = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn3 = ormEntity.addSpecifiedPrimaryKeyJoinColumn(1); - primaryKeyJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals(primaryKeyJoinColumn2, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn3, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn, primaryKeyJoinColumns.next()); - - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getPrimaryKeyJoinColumns().size()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(2, entityResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(1, entityResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(0, entityResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getPrimaryKeyJoinColumns().size()); - - - ormEntity.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormEntity.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - - entityResource.getPrimaryKeyJoinColumns().get(0).setName("FOO"); - entityResource.getPrimaryKeyJoinColumns().get(1).setName("BAR"); - entityResource.getPrimaryKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().move(2, 0); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().move(0, 1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - } - - public void testDefaultPrimaryKeyJoinColumns() throws Exception { - createTestType(); - createTestSubTypeUnmapped(); - - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - persistentType.getAttributeNamed("id").convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - ((OrmEntity) persistentType.getMapping()).setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - OrmPrimaryKeyJoinColumn specifiedPkJoinColumn = childEntity.addSpecifiedPrimaryKeyJoinColumn(0); - specifiedPkJoinColumn.setSpecifiedName("FOO"); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("BAR"); - - assertFalse(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - - //remove the pkJoinColumn from the context mode, verify context model has a default pkJoinColumn - childEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - specifiedPkJoinColumn = childEntity.addSpecifiedPrimaryKeyJoinColumn(0); - specifiedPkJoinColumn.setSpecifiedName("FOO"); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("BAR"); - assertFalse(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - //now remove the pkJoinColumn from the resource model, verify context model updates and has a default pkJoinColumn - childEntity.getXmlTypeMapping().getPrimaryKeyJoinColumns().remove(0); - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - } - - public void testDefaultPrimaryKeyJoinColumnsFromJava() throws Exception { - createTestEntityFieldAccess(); - createTestSubType(); - - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - - - ((JavaEntity) persistentType.getJavaPersistentType().getMapping()).setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - JavaEntity javaEntity = (JavaEntity) childPersistentType.getJavaPersistentType().getMapping(); - JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn = javaEntity.addSpecifiedPrimaryKeyJoinColumn(0); - javaPrimaryKeyJoinColumn.setSpecifiedName("FOO"); - javaPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName("BAR"); - - JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn2 = javaEntity.addSpecifiedPrimaryKeyJoinColumn(1); - javaPrimaryKeyJoinColumn2.setSpecifiedName("FOO2"); - javaPrimaryKeyJoinColumn2.setSpecifiedReferencedColumnName("BAR2"); - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - ListIterator defaultPrimaryKeyJoinColumns = childEntity.defaultPrimaryKeyJoinColumns(); - ReadOnlyPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("FOO", defaultPrimaryKeyJoinColumn.getName()); - assertEquals("BAR", defaultPrimaryKeyJoinColumn.getReferencedColumnName()); - - defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("FOO2", defaultPrimaryKeyJoinColumn.getName()); - assertEquals("BAR2", defaultPrimaryKeyJoinColumn.getReferencedColumnName()); - assertFalse(defaultPrimaryKeyJoinColumns.hasNext()); - - childEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - defaultPrimaryKeyJoinColumns = childEntity.defaultPrimaryKeyJoinColumns(); - defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("id", defaultPrimaryKeyJoinColumn.getDefaultName()); - assertEquals("id", defaultPrimaryKeyJoinColumn.getDefaultReferencedColumnName()); - - assertFalse(defaultPrimaryKeyJoinColumns.hasNext()); - - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, entityResource.getAttributeOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(2, 0); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(0, 1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - assertFalse(overrideContainer.specifiedOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualOverride.getName()); - assertEquals("name", virtualOverride.getColumn().getName()); - assertEquals(CHILD_TYPE_NAME, virtualOverride.getColumn().getTable()); - assertEquals(null, virtualOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualOverride.getColumn().isInsertable()); - assertEquals(true, virtualOverride.getColumn().isUpdatable()); - assertEquals(false, virtualOverride.getColumn().isUnique()); - assertEquals(true, virtualOverride.getColumn().isNullable()); - assertEquals(255, virtualOverride.getColumn().getLength()); - assertEquals(0, virtualOverride.getColumn().getPrecision()); - assertEquals(0, virtualOverride.getColumn().getScale()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualOverride.getName()); - - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualOverride.getName()); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - entity.setSpecifiedMetadataComplete(Boolean.FALSE); - entity.getJavaTypeMapping().getAttributeOverrideContainer().virtualOverrides().next().convertToSpecified(); - JavaColumn javaColumn = entity.getJavaTypeMapping().getAttributeOverrideContainer().specifiedOverrides().next().getColumn(); - javaColumn.setSpecifiedName("FOO"); - javaColumn.setSpecifiedTable("BAR"); - javaColumn.setColumnDefinition("COLUMN_DEF"); - javaColumn.setSpecifiedInsertable(Boolean.FALSE); - javaColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaColumn.setSpecifiedUnique(Boolean.TRUE); - javaColumn.setSpecifiedNullable(Boolean.FALSE); - javaColumn.setSpecifiedLength(Integer.valueOf(7)); - javaColumn.setSpecifiedPrecision(Integer.valueOf(8)); - javaColumn.setSpecifiedScale(Integer.valueOf(9)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualOverride.getName()); - assertEquals("FOO", virtualOverride.getColumn().getSpecifiedName()); - assertEquals("FOO", virtualOverride.getColumn().getDefaultName()); - assertEquals("BAR", virtualOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", virtualOverride.getColumn().getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualOverride.getColumn().getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualOverride.getColumn().getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, virtualOverride.getColumn().getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualOverride.getColumn().getSpecifiedNullable()); - assertEquals(Integer.valueOf(7), virtualOverride.getColumn().getSpecifiedLength()); - assertEquals(Integer.valueOf(8), virtualOverride.getColumn().getSpecifiedPrecision()); - assertEquals(Integer.valueOf(9), virtualOverride.getColumn().getSpecifiedScale()); - - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualOverride.getName()); - assertNull(virtualOverride.getColumn().getSpecifiedName()); - assertEquals("basic", virtualOverride.getColumn().getDefaultName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualOverride.getName()); - - persistentType2.getAttributeNamed("basic").convertToSpecified(); - OrmBasicMapping basicMapping = (OrmBasicMapping) persistentType2.getAttributeNamed("basic").getMapping(); - basicMapping.getColumn().setSpecifiedName("MY_NAME"); - basicMapping.getColumn().setSpecifiedTable("BAR"); - basicMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - basicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - - - assertEquals(4, overrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualOverride.getName()); - assertEquals("MY_NAME", virtualOverride.getColumn().getSpecifiedName()); - assertEquals("BAR", virtualOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", virtualOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualOverride.getColumn().isInsertable()); - assertEquals(false, virtualOverride.getColumn().isUpdatable()); - assertEquals(true, virtualOverride.getColumn().isUnique()); - assertEquals(false, virtualOverride.getColumn().isNullable()); - assertEquals(5, virtualOverride.getColumn().getLength()); - assertEquals(6, virtualOverride.getColumn().getPrecision()); - assertEquals(7, virtualOverride.getColumn().getScale()); - - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualOverride.getName()); - assertEquals("FOO", virtualOverride.getColumn().getSpecifiedName());//TODO specified or default? - assertEquals("BAR", virtualOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", virtualOverride.getColumn().getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualOverride.getColumn().getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualOverride.getColumn().getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, virtualOverride.getColumn().getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualOverride.getColumn().getSpecifiedNullable()); - assertEquals(Integer.valueOf(7), virtualOverride.getColumn().getSpecifiedLength()); - assertEquals(Integer.valueOf(8), virtualOverride.getColumn().getSpecifiedPrecision()); - assertEquals(Integer.valueOf(9), virtualOverride.getColumn().getSpecifiedScale()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - } - - public void testVirtualAttributeOverridesNoJavaEntity() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(4, overrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("basic", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - } - - public void testAttributeOverrideColumnDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - - OrmAttributeOverride attributeOverride = overrideContainer.specifiedOverrides().next(); - assertEquals("foo", attributeOverride.getColumn().getDefaultName()); - assertEquals(CHILD_TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - - ((JavaEntity) persistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals("foo", attributeOverride.getColumn().getDefaultName()); - assertEquals("FOO", attributeOverride.getColumn().getDefaultTable()); - - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals("foo", attributeOverride.getColumn().getDefaultName()); - assertEquals(CHILD_TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - - entity.setSpecifiedMetadataComplete(Boolean.FALSE); - entity.getTable().setSpecifiedName("BAR"); - assertEquals("foo", attributeOverride.getColumn().getDefaultName()); - assertEquals("BAR", attributeOverride.getColumn().getDefaultTable()); - } - - public void testAttributeOverrideColumnDefaultsNoJavaAnnotations() throws Exception { - createTestType(); - createTestSubTypeUnmapped(); - OrmPersistentType childType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmEntity childEntity = (OrmEntity) childType.getMapping(); - OrmAttributeOverrideContainer childOverrideContainer = childEntity.getAttributeOverrideContainer(); - OrmReadOnlyAttributeOverride attributeOverride = childOverrideContainer.virtualOverrides().next(); - ((OrmReadOnlyPersistentAttribute) childType.getSuperPersistentType().getAttributeNamed("id")).convertToSpecified(); - BasicMapping basicMapping = (BasicMapping) ((OrmReadOnlyPersistentAttribute) childType.getSuperPersistentType().getAttributeNamed("id")).getMapping(); - basicMapping.getColumn().setSpecifiedName("MY_COLUMN"); - basicMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals("MY_COLUMN", attributeOverride.getColumn().getDefaultName()); - assertEquals("BAR", attributeOverride.getColumn().getDefaultTable()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - attributeOverride = childOverrideContainer.virtualOverrides().next(); - assertEquals("MY_COLUMN", attributeOverride.getColumn().getName()); - assertEquals("BAR", attributeOverride.getColumn().getTable()); - } - - public void testOverridableAttributes() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - Entity entity = (Entity) persistentType.getMapping(); - Iterator overridableAttributes = persistentType.getMapping().overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = entity.overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - Entity entity = (Entity) persistentType.getMapping(); - Iterator overridableAttributeNames = persistentType.getMapping().overridableAttributeNames(); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = entity.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - - Iterator overridableAttributes = entity.allOverridableAttributeNames(); - assertEquals("foo", overridableAttributes.next()); - assertEquals("basic", overridableAttributes.next()); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - OrmPersistentType abstractPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - OrmEntity abstractEntity = (OrmEntity) abstractPersistentType.getMapping(); - - Iterator overridableAttributes = entity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testVirtualAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - - OrmPersistentType abstractPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType concretePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - OrmEntity concreteEntity = (OrmEntity) concretePersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = concreteEntity.getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - OrmVirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(CHILD_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - abstractPersistentType.getAttributeNamed("id").convertToSpecified(); - BasicMapping idMapping = (OrmBasicMapping) abstractPersistentType.getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(CHILD_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - assertEquals(3, entityResource.getAssociationOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - - assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("BAZ", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - - assertEquals("BAZ", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("BAR", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); - } - - public void testUpdateAssociationOverrides() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(2, 0); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(overrideContainer.specifiedOverrides().hasNext()); - } - - public void testVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - ListIterator virtualOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualOverride = virtualOverrides.next(); - OrmVirtualJoinColumnRelationshipStrategy joiningStrategy = ((OrmVirtualJoinColumnRelationship) virtualOverride.getRelationship()).getJoinColumnStrategy(); - - assertEquals("oneToOne", virtualOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - OrmVirtualJoinColumn virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("oneToOne_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(CHILD_TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - - virtualOverride = virtualOverrides.next(); - assertEquals("manyToOne", virtualOverride.getName()); - assertFalse(virtualOverrides.hasNext()); - - - overrideContainer.virtualOverrides().next().convertToSpecified(); - - assertEquals(1, overrideContainer.virtualOverridesSize()); - virtualOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualOverrides.next(); - assertEquals("manyToOne", virtualOverride.getName()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(1, overrideContainer.virtualOverridesSize()); - virtualOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualOverrides.next(); - assertEquals("manyToOne", virtualOverride.getName()); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - ormEntity.getJavaTypeMapping().getAssociationOverrideContainer().virtualOverrides().next().convertToSpecified(); - - - JavaAssociationOverride javaAssociationOverride = ormEntity.getJavaTypeMapping().getAssociationOverrideContainer().specifiedOverrides().next(); - JavaJoinColumnRelationshipStrategy javaJoiningStrategy = javaAssociationOverride.getRelationship().getJoinColumnStrategy(); - JavaJoinColumn javaJoinColumn = javaJoiningStrategy.joinColumns().next(); - javaJoinColumn.setSpecifiedName("FOO"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCE"); - javaJoinColumn.setSpecifiedTable("BAR"); - javaJoinColumn.setColumnDefinition("COLUMN_DEF"); - javaJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - javaJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaJoinColumn.setSpecifiedUnique(Boolean.TRUE); - javaJoinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualOverrides.next(); - joiningStrategy = virtualOverride.getRelationship().getJoinColumnStrategy(); - assertEquals("oneToOne", virtualOverride.getName()); - OrmVirtualJoinColumn ormJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("FOO", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCE", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", ormJoinColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEF", ormJoinColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - - virtualOverride = virtualOverrides.next(); - joiningStrategy = virtualOverride.getRelationship().getJoinColumnStrategy(); - assertEquals("manyToOne", virtualOverride.getName()); - assertEquals(null, joiningStrategy.joinColumns().next().getSpecifiedName()); - - persistentType2.getAttributeNamed("manyToOne").convertToSpecified(); - OrmManyToOneMapping manyToOneMapping = (OrmManyToOneMapping) persistentType2.getAttributeNamed("manyToOne").getMapping(); - OrmJoinColumn joinColumn = manyToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_NAME"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERNCE_NAME"); - joinColumn.setSpecifiedTable("BAR2"); - joinColumn.setColumnDefinition("COLUMN_DEF2"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualOverrides = overrideContainer.virtualOverrides(); - virtualOverride = virtualOverrides.next(); - joiningStrategy = virtualOverride.getRelationship().getJoinColumnStrategy(); - assertEquals("manyToOne", virtualOverride.getName()); - ormJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("MY_NAME", ormJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERNCE_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR2", ormJoinColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEF2", ormJoinColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - - virtualOverride = virtualOverrides.next(); - joiningStrategy = virtualOverride.getRelationship().getJoinColumnStrategy(); - assertEquals("oneToOne", virtualOverride.getName()); - ormJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("FOO", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCE", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", ormJoinColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEF", ormJoinColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - } -//TODO -// public void testVirtualAssociationOverridesNoJavaEntity() throws Exception { -// createTestMappedSuperclass(); -// createTestSubType(); -// OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); -// OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// persistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); -// persistentType2.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); -// -// persistentType2.getAttributeNamed("oneToOne").setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); -// persistentType2.getAttributeNamed("manyToOne").setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); -// -// OrmEntity entity = (OrmEntity) persistentType.getMapping(); -// -// assertEquals(2, entity.virtualAssociationOverridesSize()); -// ListIterator virtualAssociationOverrides = entity.virtualAssociationOverrides(); -// OrmAssociationOverride associationOverride = virtualAssociationOverrides.next(); -// assertEquals("oneToOne", associationOverride.getName()); -// assertEquals(1, associationOverride.joinColumnsSize()); -// OrmJoinColumn joinColumn = associationOverride.joinColumns().next(); -// assertEquals("oneToOne_id", joinColumn.getName()); -// assertEquals("id", joinColumn.getReferencedColumnName()); -// assertEquals(CHILD_TYPE_NAME, joinColumn.getTable()); -// assertEquals(null, joinColumn.getColumnDefinition()); -// assertEquals(true, joinColumn.isInsertable()); -// assertEquals(true, joinColumn.isUpdatable()); -// assertEquals(false, joinColumn.isUnique()); -// assertEquals(true, joinColumn.isNullable()); -// -// -// associationOverride = virtualAssociationOverrides.next(); -// assertEquals("manyToOne", associationOverride.getName()); -// assertFalse(virtualAssociationOverrides.hasNext()); -// -// -// entity.virtualAssociationOverrides().next().convertToSpecified(); -// -// assertEquals(1, entity.virtualAssociationOverridesSize()); -// virtualAssociationOverrides = entity.virtualAssociationOverrides(); -// associationOverride = virtualAssociationOverrides.next(); -// assertEquals("manyToOne", associationOverride.getName()); -// -// entity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(1, entity.virtualAssociationOverridesSize()); -// virtualAssociationOverrides = entity.virtualAssociationOverrides(); -// associationOverride = virtualAssociationOverrides.next(); -// assertEquals("manyToOne", associationOverride.getName()); -// -// entity.specifiedAssociationOverrides().next().setVirtual(true); -// entity.setSpecifiedMetadataComplete(Boolean.FALSE); -// entity.getJavaEntity().virtualAssociationOverrides().next().convertToSpecified(); -// JavaAssociationOverride javaAssociationOverride = entity.getJavaEntity().specifiedAssociationOverrides().next(); -// JavaJoinColumn javaJoinColumn = javaAssociationOverride.addSpecifiedJoinColumn(0); -// javaJoinColumn.setSpecifiedName("FOO"); -// javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCE"); -// javaJoinColumn.setSpecifiedTable("BAR"); -// javaJoinColumn.setColumnDefinition("COLUMN_DEF"); -// javaJoinColumn.setSpecifiedInsertable(Boolean.FALSE); -// javaJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); -// javaJoinColumn.setSpecifiedUnique(Boolean.TRUE); -// javaJoinColumn.setSpecifiedNullable(Boolean.FALSE); -// -// assertEquals(2, entity.virtualAssociationOverridesSize()); -// virtualAssociationOverrides = entity.virtualAssociationOverrides(); -// associationOverride = virtualAssociationOverrides.next(); -// assertEquals("oneToOne", associationOverride.getName()); -// OrmJoinColumn ormJoinColumn = associationOverride.joinColumns().next(); -// assertEquals("FOO", ormJoinColumn.getSpecifiedName()); -// assertEquals("REFERENCE", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals("BAR", ormJoinColumn.getSpecifiedTable()); -// assertEquals("COLUMN_DEF", ormJoinColumn.getColumnDefinition()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); -// -// associationOverride = virtualAssociationOverrides.next(); -// assertEquals("manyToOne", associationOverride.getName()); -// assertEquals(null, associationOverride.joinColumns().next().getSpecifiedName()); -// -// persistentType2.getAttributeNamed("manyToOne").makeSpecified(); -// OrmManyToOneMapping manyToOneMapping = (OrmManyToOneMapping) persistentType2.getAttributeNamed("manyToOne").getMapping(); -// joinColumn = manyToOneMapping.getRelationship().getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(0); -// joinColumn.setSpecifiedName("MY_NAME"); -// joinColumn.setSpecifiedReferencedColumnName("MY_REFERNCE_NAME"); -// joinColumn.setSpecifiedTable("BAR2"); -// joinColumn.setColumnDefinition("COLUMN_DEF2"); -// joinColumn.setSpecifiedInsertable(Boolean.FALSE); -// joinColumn.setSpecifiedUpdatable(Boolean.FALSE); -// joinColumn.setSpecifiedUnique(Boolean.TRUE); -// joinColumn.setSpecifiedNullable(Boolean.FALSE); -// -// -// -// assertEquals(2, entity.virtualAssociationOverridesSize()); -// virtualAssociationOverrides = entity.virtualAssociationOverrides(); -// assertEquals("oneToOne", associationOverride.getName()); -// ormJoinColumn = associationOverride.joinColumns().next(); -// assertEquals("FOO", ormJoinColumn.getSpecifiedName()); -// assertEquals("REFERENCE", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals("BAR", ormJoinColumn.getSpecifiedTable()); -// assertEquals("COLUMN_DEF", ormJoinColumn.getColumnDefinition()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); -// -// -// associationOverride = entity.virtualAssociationOverrides().next(); -// associationOverride = entity.virtualAssociationOverrides().next(); -// assertEquals("manyToOne", associationOverride.getName()); -// ormJoinColumn = associationOverride.joinColumns().next(); -// assertEquals("MY_NAME", ormJoinColumn.getSpecifiedName()); -// assertEquals("MY_REFERNCE_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals("BAR2", ormJoinColumn.getSpecifiedTable()); -// assertEquals("COLUMN_DEF2", ormJoinColumn.getColumnDefinition()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); -// } - - public void testAddNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - OrmNamedQuery namedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - namedQuery.setName("FOO"); - - assertEquals("FOO", entityResource.getNamedQueries().get(0).getName()); - - OrmNamedQuery namedQuery2 = ormEntity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(1).getName()); - - OrmNamedQuery namedQuery3 = ormEntity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - ListIterator namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedQuery(0).setName("FOO"); - ormEntity.getQueryContainer().addNamedQuery(1).setName("BAR"); - ormEntity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(2, entityResource.getNamedQueries().size()); - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(1, entityResource.getNamedQueries().size()); - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(0, entityResource.getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedQuery(0).setName("FOO"); - ormEntity.getQueryContainer().addNamedQuery(1).setName("BAR"); - ormEntity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - - ormEntity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - - ormEntity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAR", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, ormEntity.getPersistenceUnit().queriesSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().get(0).setName("FOO"); - entityResource.getNamedQueries().get(1).setName("BAR"); - entityResource.getNamedQueries().get(2).setName("BAZ"); - - ListIterator namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedQueries().move(2, 0); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().move(0, 1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedQueries().remove(0); - assertFalse(ormEntity.getQueryContainer().namedQueries().hasNext()); - assertEquals(0, ormEntity.getPersistenceUnit().queriesSize()); - } - - public void testAddNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - OrmNamedNativeQuery namedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - assertEquals("FOO", entityResource.getNamedNativeQueries().get(0).getName()); - - OrmNamedNativeQuery namedNativeQuery2 = ormEntity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(1).getName()); - - OrmNamedNativeQuery namedNativeQuery3 = ormEntity.getQueryContainer().addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - - ListIterator namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals(namedNativeQuery2, namedNativeQueries.next()); - assertEquals(namedNativeQuery3, namedNativeQueries.next()); - assertEquals(namedNativeQuery, namedNativeQueries.next()); - - namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - ormEntity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - ormEntity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedNativeQueries().size()); - - ormEntity.getQueryContainer().removeNamedNativeQuery(0); - assertEquals(2, entityResource.getNamedNativeQueries().size()); - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - - ormEntity.getQueryContainer().removeNamedNativeQuery(0); - assertEquals(1, entityResource.getNamedNativeQueries().size()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(0).getName()); - - ormEntity.getQueryContainer().removeNamedNativeQuery(0); - assertEquals(0, entityResource.getNamedNativeQueries().size()); - } - - public void testMoveNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - ormEntity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - ormEntity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedNativeQueries().size()); - - - ormEntity.getQueryContainer().moveNamedNativeQuery(2, 0); - ListIterator namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - - - ormEntity.getQueryContainer().moveNamedNativeQuery(0, 1); - namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAR", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, ormEntity.getPersistenceUnit().queriesSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().get(0).setName("FOO"); - entityResource.getNamedNativeQueries().get(1).setName("BAR"); - entityResource.getNamedNativeQueries().get(2).setName("BAZ"); - ListIterator namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(3, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedNativeQueries().move(2, 0); - namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - entityResource.getNamedNativeQueries().move(0, 1); - namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - entityResource.getNamedNativeQueries().remove(1); - namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(2, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedNativeQueries().remove(1); - namedNativeQueries = ormEntity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(1, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedNativeQueries().remove(0); - assertFalse(ormEntity.getQueryContainer().namedNativeQueries().hasNext()); - assertEquals(0, ormEntity.getPersistenceUnit().queriesSize()); - } - - public void testUpdateIdClass() throws Exception { - createTestIdClass(); - OrmPersistentType persistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - IdClassReference idClassRef = ormEntity.getIdClassReference(); - - assertNull(entityResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - entityResource.setIdClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNotNull(entityResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - entityResource.getIdClass().setClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, entityResource.getIdClass().getClassName()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - entityResource.getIdClass().setClassName(existentIdClassName); - assertEquals(existentIdClassName, entityResource.getIdClass().getClassName()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - //test setting @IdClass value to null, id-class tag is not removed - entityResource.getIdClass().setClassName(null); - assertNotNull(entityResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - //reset @IdClass value and then remove id-class tag - entityResource.setIdClass(OrmFactory.eINSTANCE.createXmlClassReference()); - entityResource.getIdClass().setClassName("model.Foo"); - entityResource.setIdClass(null); - assertNull(entityResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - createTestIdClass(); - OrmPersistentType persistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - IdClassReference idClassRef = ormEntity.getIdClassReference(); - - assertNull(entityResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClassRef.setSpecifiedIdClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, entityResource.getIdClass().getClassName()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClassRef.setSpecifiedIdClassName(existentIdClassName); - assertEquals(existentIdClassName, entityResource.getIdClass().getClassName()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - idClassRef.setSpecifiedIdClassName(null); - assertNull(entityResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } - - - public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType superPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType subPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity childXmlEntity = (OrmEntity) subPersistentType.getMapping(); - - superPersistentType.getAttributeNamed("id").convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("id", childXmlEntity.getPrimaryKeyColumnName()); - - ((OrmIdMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("MY_ID", childXmlEntity.getPrimaryKeyColumnName()); - - //TODO once bug 228718 is fixed - OrmVirtualAttributeOverride ormAttributeOverride = childXmlEntity.getAttributeOverrideContainer().virtualOverrides().next(); - assertEquals("id", ormAttributeOverride.getName()); - - ormAttributeOverride.convertToSpecified().getColumn().setSpecifiedName("ID"); - assertEquals("ID", childXmlEntity.getPrimaryKeyColumnName()); - } - - - public void testDiscriminatorValueIsUndefinedConcreteClass() throws Exception { - createTestType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertTrue(entity.discriminatorValueIsUndefined()); - - createTestSubType(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - assertFalse(entity.discriminatorValueIsUndefined()); - } - - public void testDiscriminatorValueIsAllowedAbstractClass() throws Exception { - createTestAbstractType(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertTrue(entity.discriminatorValueIsUndefined()); - - createTestSubType(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - assertTrue(entity.discriminatorValueIsUndefined()); - } - - public void testDiscriminatorColumnIsAllowed() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - OrmPersistentType concretePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmPersistentType abstractPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Entity concreteEntity = (Entity) concretePersistentType.getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) abstractPersistentType.getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - - //table-per-class, no discriminator column allowed - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertFalse(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - - - //single-table, discriminator column allowed on root entity - ((JavaEntity) abstractPersistentType.getJavaPersistentType().getMapping()).setSpecifiedInheritanceStrategy(null); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertTrue(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - } - - public void testAbstractEntityGetDefaultDiscriminatorColumnNameTablePerClassInheritance() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - - OrmPersistentType concretePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmPersistentType abstractPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Entity concreteEntity = (Entity) concretePersistentType.getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) abstractPersistentType.getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - - assertEquals(null, abstractEntity.getSpecifiedInheritanceStrategy()); - assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy()); - - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(null, concreteEntity.getDiscriminatorColumn().getDefaultName()); - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertEquals(null, abstractEntity.getDefaultDiscriminatorValue()); - assertTrue(concreteEntity.discriminatorValueIsUndefined()); - assertEquals(null, concreteEntity.getDefaultDiscriminatorValue()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java deleted file mode 100644 index 37d51ccc92..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - - -@SuppressWarnings("nls")public class OrmGeneratedValueTests extends ContextModelTestCase -{ - public OrmGeneratedValueTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - OrmGeneratedValue ormGeneratedValue = ormIdMapping.addGeneratedValue(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - XmlGeneratedValue generatedValueResource = idResource.getGeneratedValue(); - - //set generator in the resource model, verify context model updated - generatedValueResource.setGenerator("FOO"); - assertEquals("FOO", ormGeneratedValue.getSpecifiedGenerator()); - assertEquals("FOO", generatedValueResource.getGenerator()); - - //set name to null in the resource model - generatedValueResource.setGenerator(null); - assertNull(ormGeneratedValue.getSpecifiedGenerator()); - assertNull(generatedValueResource.getGenerator()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - OrmGeneratedValue ormGeneratedValue = ormIdMapping.addGeneratedValue(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - XmlGeneratedValue generatedValueResource = idResource.getGeneratedValue(); - - //set name in the context model, verify resource model modified - ormGeneratedValue.setSpecifiedGenerator("FOO"); - assertEquals("FOO", generatedValueResource.getGenerator()); - assertEquals("FOO", ormGeneratedValue.getSpecifiedGenerator()); - - //set name to null in the context model - ormGeneratedValue.setSpecifiedGenerator(null); - assertNull(generatedValueResource.getGenerator()); - assertNull(ormGeneratedValue.getSpecifiedGenerator()); - } - - public void testDefaultsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormIdAttribute = ormPersistentType.virtualAttributes().next(); - IdMapping ormIdMapping = (IdMapping) ormIdAttribute.getMapping(); - assertEquals(null, ormIdMapping.getGeneratedValue()); - - IdMapping javaIdMapping = (IdMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - GeneratedValue javaGeneratedValue = javaIdMapping.addGeneratedValue(); - javaGeneratedValue.setSpecifiedGenerator("Foo"); - javaGeneratedValue.setSpecifiedStrategy(GenerationType.SEQUENCE); - - assertEquals("Foo", ormIdMapping.getGeneratedValue().getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, ormIdMapping.getGeneratedValue().getSpecifiedStrategy()); - assertEquals("Foo", javaGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, javaGeneratedValue.getSpecifiedStrategy()); - - ormIdAttribute.convertToSpecified(); - ormIdAttribute = ormPersistentType.specifiedAttributes().next(); - ormIdMapping = (IdMapping) ormIdAttribute.getMapping(); - assertEquals(null, ormIdMapping.getGeneratedValue()); - assertEquals("Foo", javaGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, javaGeneratedValue.getSpecifiedStrategy()); - - ((OrmPersistentAttribute) ormIdAttribute).convertToVirtual(); - ormIdAttribute = ormPersistentType.getAttributeNamed("id"); - ormIdMapping = (IdMapping) ormIdAttribute.getMapping(); - assertEquals("Foo", ormIdMapping.getGeneratedValue().getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, ormIdMapping.getGeneratedValue().getSpecifiedStrategy()); - assertEquals("Foo", javaGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, javaGeneratedValue.getSpecifiedStrategy()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java deleted file mode 100644 index 7aa082b878..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java +++ /dev/null @@ -1,746 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmIdMappingTests extends ContextModelTestCase -{ - public OrmIdMappingTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN, JPA.TEMPORAL, JPA.TEMPORAL_TYPE, JPA.GENERATED_VALUE, JPA.GENERATION_TYPE, JPA.TABLE_GENERATOR, JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - sb.append(CR); - sb.append(" @GeneratedValue(strategy=GenerationType.TABLE, generator=\"myTableGenerator\")"); - sb.append(CR); - sb.append(" @TableGenerator(name=\"myTableGenerator\", table=\"myTable\", catalog=\"myCatalog\", schema=\"mySchema\", pkColumnName=\"myPkColumnName\", valueColumnName=\"myValueColumnName\", pkColumnValue=\"myPkColumnValue\", initialValue=1, allocationSize=1)"); - sb.append(CR); - sb.append(" @SequenceGenerator(name=\"mySequenceGenerator\")"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertEquals("idMapping", ormIdMapping.getName()); - assertEquals("idMapping", idResource.getName()); - - //set name in the resource model, verify context model updated - idResource.setName("newName"); - assertEquals("newName", ormIdMapping.getName()); - assertEquals("newName", idResource.getName()); - - //set name to null in the resource model - idResource.setName(null); - assertNull(ormIdMapping.getName()); - assertNull(idResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertEquals("idMapping", ormIdMapping.getName()); - assertEquals("idMapping", idResource.getName()); - - //set name in the context model, verify resource model updated - ormIdMapping.setName("newName"); - assertEquals("newName", ormIdMapping.getName()); - assertEquals("newName", idResource.getName()); - - //set name to null in the context model - ormIdMapping.setName(null); - assertNull(ormIdMapping.getName()); - assertNull(idResource.getName()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getConverter().getType()); - assertNull(idResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, idResource.getTemporal()); - - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, idResource.getTemporal()); - - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, idResource.getTemporal()); - - //set temporal to null in the resource model - idResource.setTemporal(null); - assertNull(ormIdMapping.getConverter().getType()); - assertNull(idResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getConverter().getType()); - assertNull(idResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormIdMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) ormIdMapping.getConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, idResource.getTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - - ((TemporalConverter) ormIdMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, idResource.getTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - - ((TemporalConverter) ormIdMapping.getConverter()).setTemporalType(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, idResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - - //set temporal to null in the context model - ormIdMapping.setConverter(null); - assertNull(idResource.getTemporal()); - assertNull(ormIdMapping.getConverter().getType()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - - public void testAddSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - ormIdMapping.getGeneratorContainer().addSequenceGenerator(); - - assertNotNull(idResource.getSequenceGenerator()); - assertNotNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormIdMapping.getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - ormIdMapping.getGeneratorContainer().addSequenceGenerator(); - assertNotNull(idResource.getSequenceGenerator()); - assertNotNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - - ormIdMapping.getGeneratorContainer().removeSequenceGenerator(); - - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormIdMapping.getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - assertEquals(0, ormIdMapping.getPersistenceUnit().generatorsSize()); - - idResource.setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGenerator()); - assertNotNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNotNull(idResource.getSequenceGenerator()); - assertEquals(1, ormIdMapping.getPersistenceUnit().generatorsSize()); - - ormIdMapping.getGeneratorContainer().getSequenceGenerator().setName("foo"); - assertEquals(1, ormIdMapping.getPersistenceUnit().generatorsSize()); - - idResource.setSequenceGenerator(null); - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - assertEquals(0, ormIdMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - ormIdMapping.getGeneratorContainer().addTableGenerator(); - - assertNotNull(idResource.getTableGenerator()); - assertNotNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - ormIdMapping.getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - ormIdMapping.getGeneratorContainer().addTableGenerator(); - assertNotNull(idResource.getTableGenerator()); - assertNotNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - - ormIdMapping.getGeneratorContainer().removeTableGenerator(); - - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - //try removing the table generator again, should get an IllegalStateException - try { - ormIdMapping.getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - assertNull(idResource.getTableGenerator()); - assertEquals(0, ormIdMapping.getPersistenceUnit().generatorsSize()); - - idResource.setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGenerator()); - assertNotNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - assertNotNull(idResource.getTableGenerator()); - assertEquals(1, ormIdMapping.getPersistenceUnit().generatorsSize()); - - ormIdMapping.getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, ormIdMapping.getGeneratorContainer().getPersistenceUnit().generatorsSize()); - - idResource.setTableGenerator(null); - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - assertNull(idResource.getTableGenerator()); - assertEquals(0, ormIdMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - ormIdMapping.addGeneratedValue(); - - assertNotNull(idResource.getGeneratedValue()); - assertNotNull(ormIdMapping.getGeneratedValue()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormIdMapping.addGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - ormIdMapping.addGeneratedValue(); - assertNotNull(idResource.getGeneratedValue()); - assertNotNull(ormIdMapping.getGeneratedValue()); - - ormIdMapping.removeGeneratedValue(); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormIdMapping.removeGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - idResource.setGeneratedValue(OrmFactory.eINSTANCE.createXmlGeneratedValue()); - - assertNotNull(ormIdMapping.getGeneratedValue()); - assertNotNull(idResource.getGeneratedValue()); - - idResource.setGeneratedValue(null); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - } - - - public void testIdMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityIdMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormIdMapping.getName()); - assertNull(ormIdMapping.getConverter().getType()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(255, ormColumn.getDefaultLength()); - assertEquals(0, ormColumn.getDefaultPrecision()); - assertEquals(0, ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", idMapping.getName()); - assertEquals(TemporalConverter.class, idMapping.getConverter().getType()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) idMapping.getConverter()).getTemporalType()); - - Column column = idMapping.getColumn(); - assertEquals("MY_COLUMN", column.getSpecifiedName()); - assertEquals(Boolean.TRUE, column.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, column.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, column.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, column.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", column.getColumnDefinition()); - assertEquals("MY_TABLE", column.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), column.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), column.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), column.getSpecifiedScale()); - - GeneratedValue generatedValue = idMapping.getGeneratedValue(); - assertEquals("myTableGenerator", generatedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.TABLE, generatedValue.getSpecifiedStrategy()); - - TableGenerator tableGenerator = idMapping.getGeneratorContainer().getTableGenerator(); - assertEquals("myTableGenerator", tableGenerator.getName()); - assertEquals("myTable", tableGenerator.getSpecifiedTable()); - assertEquals("myCatalog", tableGenerator.getSpecifiedCatalog()); - assertEquals("mySchema", tableGenerator.getSpecifiedSchema()); - assertEquals("myPkColumnName", tableGenerator.getSpecifiedPkColumnName()); - assertEquals("myPkColumnValue", tableGenerator.getSpecifiedPkColumnValue()); - assertEquals("myValueColumnName", tableGenerator.getSpecifiedValueColumnName()); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedAllocationSize()); - - SequenceGenerator sequenceGenerator = idMapping.getGeneratorContainer().getSequenceGenerator(); - assertEquals("mySequenceGenerator", sequenceGenerator.getName()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals("id", ormIdMapping.getName()); - assertNull(ormIdMapping.getConverter().getType()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertEquals("id", ormColumn.getName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getTable()); - assertEquals(255, ormColumn.getLength()); - assertEquals(0, ormColumn.getPrecision()); - assertEquals(0, ormColumn.getScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityIdMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormIdMapping.getName()); - assertNull(ormIdMapping.getConverter().getType()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(ormIdMapping.getGeneratorContainer().getTableGenerator()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(255, ormColumn.getDefaultLength()); - assertEquals(0, ormColumn.getDefaultPrecision()); - assertEquals(0, ormColumn.getDefaultScale()); - } - - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - - public void testIdMorphToBasicMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testIdMorphToVersionMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((VersionMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testIdMorphToTransientMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToEmbeddedMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToEmbeddedIdMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToOneToOneMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToOneToManyMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToManyToOneMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToManyToManyMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java deleted file mode 100644 index b8b85fd857..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java +++ /dev/null @@ -1,506 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmJoinColumnTests extends ContextModelTestCase -{ - public OrmJoinColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - //set name in the resource model, verify context model updated - joinColumnResource.setName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", joinColumnResource.getName()); - - //set name to null in the resource model - joinColumnResource.setName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - joinColumnResource.setName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", joinColumnResource.getName()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - assertEquals("foo", joinColumn.getSpecifiedName()); - assertEquals("foo", joinColumnResource.getName()); - - //set name to null in the context model - joinColumn.setSpecifiedName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinTableResource.getJoinColumns().get(0).getName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - //set name in the resource model, verify context model updated - joinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", joinColumnResource.getReferencedColumnName()); - - //set name to null in the resource model - joinColumnResource.setReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - joinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", joinColumnResource.getReferencedColumnName()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("foo", joinColumnResource.getReferencedColumnName()); - - //set name to null in the context model - joinColumn.setSpecifiedReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinTableResource.getJoinColumns().get(0).getReferencedColumnName()); - } - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - //set name in the resource model, verify context model updated - joinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", joinColumn.getColumnDefinition()); - assertEquals("FOO", joinColumnResource.getColumnDefinition()); - - //set name to null in the resource model - joinColumnResource.setColumnDefinition(null); - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - joinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", joinColumn.getColumnDefinition()); - assertEquals("FOO", joinColumnResource.getColumnDefinition()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - //set name in the context model, verify resource model modified - joinColumn.setColumnDefinition("foo"); - assertEquals("foo", joinColumn.getColumnDefinition()); - assertEquals("foo", joinColumnResource.getColumnDefinition()); - - //set name to null in the context model - joinColumn.setColumnDefinition(null); - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinTableResource.getJoinColumns().get(0).getColumnDefinition()); - } - - public void testUpdateSpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - //set table in the resource model, verify context model updated - joinColumnResource.setTable("FOO"); - assertEquals("FOO", ormJoinColumn.getSpecifiedTable()); - assertEquals("FOO", joinColumnResource.getTable()); - - //set table to null in the resource model - joinColumnResource.setTable(null); - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - joinColumnResource.setTable("FOO"); - assertEquals("FOO", ormJoinColumn.getSpecifiedTable()); - assertEquals("FOO", joinColumnResource.getTable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - //set table in the context model, verify resource model modified - ormJoinColumn.setSpecifiedTable("foo"); - assertEquals("foo", ormJoinColumn.getSpecifiedTable()); - assertEquals("foo", joinColumnResource.getTable()); - - //set table to null in the context model - ormJoinColumn.setSpecifiedTable(null); - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinTableResource.getJoinColumns().get(0).getTable()); - } - - public void testUpdateSpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - //set nullable in the resource model, verify context model updated - joinColumnResource.setNullable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, joinColumnResource.getNullable()); - - //set nullable to null in the resource model - joinColumnResource.setNullable(null); - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - joinColumnResource.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumnResource.getNullable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - //set nullable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumnResource.getNullable()); - - //set nullable to null in the context model - ormJoinColumn.setSpecifiedNullable(null); - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinTableResource.getJoinColumns().get(0).getNullable()); - } - - public void testUpdateSpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - //set updatable in the resource model, verify context model updated - joinColumnResource.setUpdatable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, joinColumnResource.getUpdatable()); - - //set updatable to null in the resource model - joinColumnResource.setUpdatable(null); - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - joinColumnResource.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, joinColumnResource.getUpdatable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - //set updatable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, joinColumnResource.getUpdatable()); - - //set updatable to null in the context model - ormJoinColumn.setSpecifiedUpdatable(null); - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinTableResource.getJoinColumns().get(0).getUpdatable()); - } - - public void testUpdateSpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - //set insertable in the resource model, verify context model updated - joinColumnResource.setInsertable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, joinColumnResource.getInsertable()); - - //set insertable to null in the resource model - joinColumnResource.setInsertable(null); - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - joinColumnResource.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumnResource.getInsertable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - //set insertable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumnResource.getInsertable()); - - //set insertable to null in the context model - ormJoinColumn.setSpecifiedInsertable(null); - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinTableResource.getJoinColumns().get(0).getInsertable()); - } - - public void testUpdateSpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - //set unique in the resource model, verify context model updated - joinColumnResource.setUnique(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, joinColumnResource.getUnique()); - - //set unique to null in the resource model - joinColumnResource.setUnique(null); - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - joinColumnResource.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumnResource.getUnique()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - //set unique in the context model, verify resource model modified - ormJoinColumn.setSpecifiedUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumnResource.getUnique()); - - //set unique to null in the context model - ormJoinColumn.setSpecifiedUnique(null); - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinTableResource.getJoinColumns().get(0).getUnique()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java deleted file mode 100644 index debd347d33..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java +++ /dev/null @@ -1,1365 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.internal.context.orm.VirtualOrmPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmJoinTableTests extends ContextModelTestCase -{ - public OrmJoinTableTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityWithValidManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - sb.append(" private Collection projects;").append(CR); - } - }); - } - - private void createTargetEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - private void createTargetEntityWithBackPointer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(" @ManyToMany(mappedBy=\"projects\"").append(CR); - sb.append(" private java.util.Collection<" + TYPE_NAME + "> employees;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - - - //set name in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - manyToMany.getJoinTable().setName("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("FOO", manyToMany.getJoinTable().getName()); - - //set name to null in the resource model - manyToMany.getJoinTable().setName(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable().getName()); - - manyToMany.getJoinTable().setName("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("FOO", manyToMany.getJoinTable().getName()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - - //set name in the context model, verify resource model modified - ormJoinTable.setSpecifiedName("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedName()); - assertEquals("foo", manyToMany.getJoinTable().getName()); - - //set name to null in the context model - ormJoinTable.setSpecifiedName(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - JoinTable virtualJoinTable = virtualManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, virtualJoinTable.getSpecifiedName()); - - createTargetEntity(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME_ + "Project"); - - assertEquals(TYPE_NAME + "_Project", virtualJoinTable.getName()); - assertNull(virtualJoinTable.getSpecifiedCatalog()); - assertNull(virtualJoinTable.getSpecifiedSchema()); - assertEquals(0, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(0, virtualJoinTable.specifiedInverseJoinColumnsSize()); - JoinColumn ormJoinColumn = virtualJoinTable.getDefaultJoinColumn(); -//TODO need to test joinColumn defaults here as well as in java and all the relatioship mapping types -// assertEquals("id_project_id", ormJoinColumn.getDefaultName()); -// assertEquals("id_project_id", ormJoinColumn.getDefaultReferencedColumnName()); - JoinColumn inverseOrmJoinColumn = virtualJoinTable.getDefaultInverseJoinColumn(); -// assertEquals("id_project_id", inverseOrmJoinColumn.getDefaultName()); -// assertEquals("id_project_id", inverseOrmJoinColumn.getDefaultReferencedColumnName()); - - JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) javaPersistentAttribute.getMapping(); - JavaJoinTable javaJoinTable = javaManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", virtualJoinTable.getSpecifiedName()); - assertEquals("CATALOG", virtualJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualJoinTable.getSpecifiedSchema()); - assertEquals(1, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(1, virtualJoinTable.specifiedInverseJoinColumnsSize()); - ormJoinColumn = virtualJoinTable.specifiedJoinColumns().next(); - assertEquals("NAME", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); - inverseOrmJoinColumn = virtualJoinTable.specifiedInverseJoinColumns().next(); - assertEquals("INVERSE_NAME", inverseOrmJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", inverseOrmJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "projects"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTargetEntity(); - OrmPersistentType targetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - JavaManyToManyMapping javaManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").getMapping(); - javaManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("projects"); - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentAttribute2.getMapping(); - JoinTable virtualJoinTable = virtualManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - assertTrue(ormPersistentAttribute2.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", virtualJoinTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - javaManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName(null); - javaManyMapping.getRelationship().setStrategyToJoinTable(); - assertNull(virtualJoinTable.getSpecifiedName()); - assertEquals("BAR_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", virtualJoinTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - - //set schema in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - manyToMany.getJoinTable().setSchema("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedSchema()); - assertEquals("FOO", manyToMany.getJoinTable().getSchema()); - - //set Schema to null in the resource model - manyToMany.getJoinTable().setSchema(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable().getSchema()); - - manyToMany.getJoinTable().setSchema("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedSchema()); - assertEquals("FOO", manyToMany.getJoinTable().getSchema()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - } - -// public void testUpdateDefaultSchemaFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedSchema("Foo"); -// assertEquals("Foo", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// xmlEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.setSpecifiedMetadataComplete(null); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName("Bar"); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertNull(childXmlEntity.getTable().getDefaultSchema()); -// -// parentXmlEntity.getTable().setSpecifiedSchema("FOO"); -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultSchema()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertNull(childXmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("FOO"); -// assertEquals("FOO", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().setSpecifiedSchema("BAR"); -// assertEquals("BAR", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedSchema("JAVA_SCHEMA"); -// assertEquals("JAVA_SCHEMA", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName("BLAH"); -// //xml entity now has a table element so default schema is not taken from java -// assertEquals("BAR", xmlEntity.getTable().getDefaultSchema()); -// -// -// xmlEntity.entityMappings().setSpecifiedSchema(null); -// assertEquals("FOO", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema(null); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName(null); -// assertEquals("JAVA_SCHEMA", xmlEntity.getTable().getDefaultSchema()); -// } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - - //set Schema in the context model, verify resource model modified - ormJoinTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedSchema()); - assertEquals("foo", manyToMany.getJoinTable().getSchema()); - - //set Schema to null in the context model - ormJoinTable.setSpecifiedSchema(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - - //set Catalog in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - manyToMany.getJoinTable().setCatalog("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedCatalog()); - assertEquals("FOO", manyToMany.getJoinTable().getCatalog()); - - //set Catalog to null in the resource model - manyToMany.getJoinTable().setCatalog(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable().getCatalog()); - - manyToMany.getJoinTable().setCatalog("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedCatalog()); - assertEquals("FOO", manyToMany.getJoinTable().getCatalog()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - - //set Catalog in the context model, verify resource model modified - ormJoinTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedCatalog()); - assertEquals("foo", manyToMany.getJoinTable().getCatalog()); - - //set Catalog to null in the context model - ormJoinTable.setSpecifiedCatalog(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - } - -// public void testUpdateDefaultCatalogFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedCatalog("Foo"); -// assertEquals("Foo", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// xmlEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.setSpecifiedMetadataComplete(null); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName("Bar"); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertNull(childXmlEntity.getTable().getDefaultCatalog()); -// -// parentXmlEntity.getTable().setSpecifiedCatalog("FOO"); -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultCatalog()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertNull(childXmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("FOO"); -// assertEquals("FOO", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().setSpecifiedCatalog("BAR"); -// assertEquals("BAR", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedCatalog("JAVA_CATALOG"); -// assertEquals("JAVA_CATALOG", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName("BLAH"); -// //xml entity now has a table element so default schema is not taken from java -// assertEquals("BAR", xmlEntity.getTable().getDefaultCatalog()); -// -// -// xmlEntity.entityMappings().setSpecifiedCatalog(null); -// assertEquals("FOO", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog(null); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName(null); -// assertEquals("JAVA_CATALOG", xmlEntity.getTable().getDefaultCatalog()); -//} - -// -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// Entity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals("Foo", xmlEntity.getName()); -// -// //set class in the resource model, verify context model updated -// entityResource.setClassName("com.Bar"); -// assertEquals("Bar", xmlEntity.getName()); -// -// entityResource.setName("Baz"); -// assertEquals("Baz", xmlEntity.getName()); -// -// //set class to null in the resource model -// entityResource.setClassName(null); -// assertEquals("Baz", xmlEntity.getName()); -// -// entityResource.setName(null); -// assertNull(xmlEntity.getName()); -// } - - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals("FOO", joinTableResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormJoinTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormJoinTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - - ListIterator joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - ormJoinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getJoinColumns().size()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.getJoinColumns().size()); - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.getJoinColumns().size()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(0).getName()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - ormJoinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getJoinColumns().size()); - - - ormJoinTable.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - - - ormJoinTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - } - - public void testUpdateInverseJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - joinTableResource.getInverseJoinColumns().get(0).setName("FOO"); - joinTableResource.getInverseJoinColumns().get(1).setName("BAR"); - joinTableResource.getInverseJoinColumns().get(2).setName("BAZ"); - - ListIterator joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().move(2, 0); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().move(0, 1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedInverseJoinColumns().hasNext()); - } - - public void testAddSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedInverseJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormJoinTable.addSpecifiedInverseJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormJoinTable.addSpecifiedInverseJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - - ListIterator joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - ormJoinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getInverseJoinColumns().size()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTableResource.getInverseJoinColumns().size()); - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTableResource.getInverseJoinColumns().size()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(0).getName()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTableResource.getInverseJoinColumns().size()); - } - - public void testMoveSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - ormJoinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getInverseJoinColumns().size()); - - - ormJoinTable.moveSpecifiedInverseJoinColumn(2, 0); - ListIterator joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - - - ormJoinTable.moveSpecifiedInverseJoinColumn(0, 1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - joinTableResource.getJoinColumns().get(0).setName("FOO"); - joinTableResource.getJoinColumns().get(1).setName("BAR"); - joinTableResource.getJoinColumns().get(2).setName("BAZ"); - - ListIterator joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().move(2, 0); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().move(0, 1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - } - - - public void testUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ListIterator uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - assertEquals(0, ormJoinTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - joinTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormJoinTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = joinTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = joinTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, joinTableResource.getUniqueConstraints().size()); - - ormJoinTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormJoinTable.removeUniqueConstraint(1); - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormJoinTable.removeUniqueConstraint(0); - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, joinTableResource.getUniqueConstraints().size()); - - - ormJoinTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormJoinTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - joinTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - joinTableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(0); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.attributes().next(); - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) virtualAttribute.getMapping(); - JoinTable virtualJoinTable = virtualManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - assertTrue(virtualAttribute.isVirtual()); - - ListIterator uniqueConstraints = (ListIterator) virtualJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - JavaJoinTable javaJoinTable = javaManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - javaJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaJoinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = (ListIterator) virtualJoinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - OrmManyToManyMapping specifiedManyToManyMapping = (OrmManyToManyMapping) ((VirtualOrmPersistentAttribute) virtualAttribute).convertToSpecified().getMapping(); - assertEquals(0, specifiedManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().uniqueConstraintsSize()); - } - - public void testDefaultName() throws Exception { - createTestEntityWithValidManyToMany(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ormPersistentType.getAttributeNamed("projects").convertToSpecified(); - OrmManyToManyMapping manyToManyMapping = (OrmManyToManyMapping) ormPersistentType.getAttributeNamed("projects").getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinTable.getDefaultName()); - - //add target entity to the persistence unit, now join table name is [table name]_[target table name] - createTargetEntity(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - assertNull(manyToMany.getJoinTable()); - - //target entity does not resolve, default name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertNull(joinTable.getDefaultName()); - - //default target entity does resolve, so default name is again [table name]_[target table name] - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - - //add the join table xml element, verify default join table name is the same - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - assertNotNull(manyToMany.getJoinTable()); - - //set a table on the target entity, very default join table name updates - manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName()); - - //set a table on the owning entity, very default join table name updates - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", joinTable.getDefaultName()); - } - - public void testDefaultJoinColumns() throws Exception { - createTestEntityWithValidManyToMany(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ormPersistentType.getAttributeNamed("projects").convertToSpecified(); - OrmManyToManyMapping manyToManyMapping = (OrmManyToManyMapping) ormPersistentType.getAttributeNamed("projects").getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - JoinColumn joinColumn = joinTable.joinColumns().next(); - JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key - createTargetEntity(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //create primary key in owning entity - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(TYPE_NAME + "_id", joinColumn.getDefaultName()); - assertEquals("id", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //set specified column name on primary key in owning entity - ((IdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - assertNull(manyToMany.getJoinTable()); - - //target entity does not resolve, inverse join column name and referenced column name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //default target entity does resolve, so defaults for join column are back - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //add the join table xml element, verify default join column defaults are the same - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - assertNotNull(manyToMany.getJoinTable()); - } - - public void testDefaultJoinColumnsBidirectionalRelationship() throws Exception { - createTestEntityWithValidManyToMany(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ormPersistentType.getAttributeNamed("projects").convertToSpecified(); - OrmManyToManyMapping manyToManyMapping = (OrmManyToManyMapping) ormPersistentType.getAttributeNamed("projects").getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable(); - JoinColumn joinColumn = joinTable.joinColumns().next(); - JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key - createTargetEntityWithBackPointer(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //create primary key in owning entity - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("employees_id", joinColumn.getDefaultName()); - assertEquals("id", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //set specified column name on primary key in owning entity - ((IdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - assertNull(manyToMany.getJoinTable()); - - //target entity does not resolve, inverse join column name and referenced column name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //default target entity does resolve, so defaults for join column are back - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //add the join table xml element, verify default join column defaults are the same - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - assertNotNull(manyToMany.getJoinTable()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java deleted file mode 100644 index 3d97ad52a4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java +++ /dev/null @@ -1,1065 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyRelationship; -import org.eclipse.jpt.core.context.orm.OrmMappedByRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmManyToManyMappingTests extends ContextModelTestCase -{ - public OrmManyToManyMappingTests(String name) { - super(name); - } - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEntityWithManyToManyMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertEquals("manyToManyMapping", ormManyToManyMapping.getName()); - assertEquals("manyToManyMapping", manyToMany.getName()); - - //set name in the resource model, verify context model updated - manyToMany.setName("newName"); - assertEquals("newName", ormManyToManyMapping.getName()); - assertEquals("newName", manyToMany.getName()); - - //set name to null in the resource model - manyToMany.setName(null); - assertNull(ormManyToManyMapping.getName()); - assertNull(manyToMany.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertEquals("manyToManyMapping", ormManyToManyMapping.getName()); - assertEquals("manyToManyMapping", manyToMany.getName()); - - //set name in the context model, verify resource model updated - ormManyToManyMapping.setName("newName"); - assertEquals("newName", ormManyToManyMapping.getName()); - assertEquals("newName", manyToMany.getName()); - - //set name to null in the context model - ormManyToManyMapping.setName(null); - assertNull(ormManyToManyMapping.getName()); - assertNull(manyToMany.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the resource model - manyToMany.setTargetEntity(null); - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the context model - ormManyToManyMapping.setSpecifiedTargetEntity(null); - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToManyResource.getFetch()); - - manyToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToManyResource.getFetch()); - - //set fetch to null in the resource model - manyToManyResource.setFetch(null); - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToManyResource.getFetch()); - assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch()); - - ormManyToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToManyResource.getFetch()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormManyToManyMapping.setSpecifiedFetch(null); - assertNull(manyToManyResource.getFetch()); - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - OrmMappedByRelationshipStrategy strategy = ormManyToManyMapping.getRelationship().getMappedByStrategy(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(strategy.getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - manyToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", strategy.getMappedByAttribute()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //setmappedBy to null in the resource model - manyToMany.setMappedBy(null); - assertNull(strategy.getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - OrmMappedByRelationshipStrategy strategy = ormManyToManyMapping.getRelationship().getMappedByStrategy(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(strategy.getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - strategy.setMappedByAttribute("newMappedBy"); - assertEquals("newMappedBy", strategy.getMappedByAttribute()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //set mappedBy to null in the context model - strategy.setMappedByAttribute(null); - assertNull(strategy.getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToManyMapping contextMapping = (OrmManyToManyMapping) contextAttribute.getMapping(); - OrmManyToManyRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToMany resourceMapping = resourceEntity.getAttributes().getManyToManys().get(0); - - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToManyMapping contextMapping = (OrmManyToManyMapping) contextAttribute.getMapping(); - OrmManyToManyRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToMany resourceMapping = resourceEntity.getAttributes().getManyToManys().get(0); - - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNotNull(manyToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKey().setName(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey().getName()); - - manyToMany.getMapKey().setName("myMapKey"); - manyToMany.setMapKey(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setNoMapKey(true); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidManyToManyMapMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualManyToManyMapping.getSpecifiedMapKey()); - assertNull(virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertTrue(virtualManyToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setPkMapKey(true); - assertEquals("id", virtualManyToManyMapping.getMapKey()); - assertTrue(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setCustomMapKey(true); - javaManyToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualManyToManyMapping.getSpecifiedMapKey()); - assertEquals("city", virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertTrue(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - } - - public void testUpdateOrderBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(manyToMany.getOrderBy()); - - //set orderBy in the resource model, verify context model updated - manyToMany.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", manyToMany.getOrderBy()); - - //set orderBy to null in the resource model - manyToMany.setOrderBy(null); - assertNull(ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(manyToMany.getOrderBy()); - } - - public void testModifyOrderBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(manyToMany.getOrderBy()); - - //set mappedBy in the context model, verify resource model updated - ormManyToManyMapping.getOrderable().setSpecifiedOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", manyToMany.getOrderBy()); - - //set mappedBy to null in the context model - ormManyToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertNull(ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(manyToMany.getOrderBy()); - } - - public void testIsNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - - ormManyToManyMapping.getOrderable().setSpecifiedOrderBy("foo"); - assertFalse(ormManyToManyMapping.getOrderable().isNoOrdering()); - - ormManyToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - } - - public void testSetNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - - ormManyToManyMapping.getOrderable().setSpecifiedOrderBy("foo"); - assertFalse(ormManyToManyMapping.getOrderable().isNoOrdering()); - - ormManyToManyMapping.getOrderable().setNoOrdering(true); - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - assertNull(ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - } -//TODO -// public boolean isOrderByPk() { -// return "".equals(getOrderBy()); -// } -// -// public void setOrderByPk() { -// setOrderBy(""); -// } - - public void testIsCustomOrdering() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertFalse(ormManyToManyMapping.getOrderable().isCustomOrdering()); - - ormManyToManyMapping.getOrderable().setSpecifiedOrderBy("foo"); - assertTrue(ormManyToManyMapping.getOrderable().isCustomOrdering()); - - ormManyToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertFalse(ormManyToManyMapping.getOrderable().isCustomOrdering()); - } - - public void testManyToManyMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToOneToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - manyToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testManyToManyMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - JoinTable joinTable = ((OneToManyMapping) ormPersistentAttribute.getMapping()).getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals("name", joinTable.joinColumns().next().getSpecifiedName()); - assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName()); - assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName()); - assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName()); - } - - public void testManyToManyMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testManyToManyMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - manyToManyMapping.setSpecifiedMapKey("mapKey"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - OrmManyToManyMapping specifiedManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = specifiedManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - specifiedManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = specifiedManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - specifiedManyToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = specifiedManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualManyToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualManyToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualManyToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = virtualManyToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - - assertTrue(virtualManyToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - OrmPersistentAttribute ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch()); - assertEquals("test.Address", ormManyToManyMapping.getTargetEntity()); - assertNull(ormManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = ormManyToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java deleted file mode 100644 index 4d58ecf07a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java +++ /dev/null @@ -1,618 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneRelationship; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmManyToOneMappingTests extends ContextModelTestCase -{ - public OrmManyToOneMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestEntityWithManyToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertEquals("manyToOneMapping", ormManyToOneMapping.getName()); - assertEquals("manyToOneMapping", manyToOne.getName()); - - //set name in the resource model, verify context model updated - manyToOne.setName("newName"); - assertEquals("newName", ormManyToOneMapping.getName()); - assertEquals("newName", manyToOne.getName()); - - //set name to null in the resource model - manyToOne.setName(null); - assertNull(ormManyToOneMapping.getName()); - assertNull(manyToOne.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertEquals("manyToOneMapping", ormManyToOneMapping.getName()); - assertEquals("manyToOneMapping", manyToOne.getName()); - - //set name in the context model, verify resource model updated - ormManyToOneMapping.setName("newName"); - assertEquals("newName", ormManyToOneMapping.getName()); - assertEquals("newName", manyToOne.getName()); - - //set name to null in the context model - ormManyToOneMapping.setName(null); - assertNull(ormManyToOneMapping.getName()); - assertNull(manyToOne.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the resource model - manyToOne.setTargetEntity(null); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the context model - ormManyToOneMapping.setSpecifiedTargetEntity(null); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToOneResource.getFetch()); - - manyToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToOneResource.getFetch()); - - //set fetch to null in the resource model - manyToOneResource.setFetch(null); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToOneResource.getFetch()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getSpecifiedFetch()); - - ormManyToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToOneResource.getFetch()); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormManyToOneMapping.setSpecifiedFetch(null); - assertNull(manyToOneResource.getFetch()); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - - //set optional in the resource model, verify context model updated - manyToOneResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOneResource.getOptional()); - - manyToOneResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOneResource.getOptional()); - - //set optional to null in the resource model - manyToOneResource.setOptional(null); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - - //set optional in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, manyToOneResource.getOptional()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getSpecifiedOptional()); - - ormManyToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOneResource.getOptional()); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - - //set optional to null in the context model - ormManyToOneMapping.setSpecifiedOptional(null); - assertNull(manyToOneResource.getOptional()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - OrmJoinColumnRelationshipStrategy strategy = ormManyToOneMapping.getRelationship().getJoinColumnStrategy(); - XmlManyToOne manyToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - OrmJoinColumn joinColumn = strategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", manyToOneResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = strategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = strategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - - ListIterator joinColumns = strategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = strategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - OrmJoinColumnRelationshipStrategy strategy = ormManyToOneMapping.getRelationship().getJoinColumnStrategy(); - XmlManyToOne manyToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - strategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - strategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - strategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToOneResource.getJoinColumns().size()); - - strategy.removeSpecifiedJoinColumn(0); - assertEquals(2, manyToOneResource.getJoinColumns().size()); - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - - strategy.removeSpecifiedJoinColumn(0); - assertEquals(1, manyToOneResource.getJoinColumns().size()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(0).getName()); - - strategy.removeSpecifiedJoinColumn(0); - assertEquals(0, manyToOneResource.getJoinColumns().size()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping contextMapping = (OrmManyToOneMapping) contextAttribute.getMapping(); - OrmManyToOneRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(rel.strategyIsJoinColumn()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(rel.strategyIsJoinColumn()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping contextMapping = (OrmManyToOneMapping) contextAttribute.getMapping(); - OrmManyToOneRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(rel.strategyIsJoinColumn()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(rel.strategyIsJoinColumn()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(rel.strategyIsJoinColumn()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - OrmJoinColumnRelationshipStrategy strategy = ormManyToOneMapping.getRelationship().getJoinColumnStrategy(); - XmlManyToOne manyToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - strategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - strategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - strategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToOneResource.getJoinColumns().size()); - - - strategy.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = strategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - - - strategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = strategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - } - - - public void testManyToOneMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - OrmJoinColumnRelationshipStrategy strategy = ormManyToOneMapping.getRelationship().getJoinColumnStrategy(); - - assertEquals("foo", ormManyToOneMapping.getName()); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getFetch()); - assertEquals(true, ormManyToOneMapping.isOptional()); - assertNull(ormManyToOneMapping.getTargetEntity()); - - - assertFalse(strategy.specifiedJoinColumns().hasNext()); - //TODO default joinColumns - //assertTrue(ormManyToOneMapping.defaultJoinColumns().hasNext()); - - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", manyToOneMapping.getName()); - assertEquals(FetchType.LAZY, manyToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, manyToOneMapping.getSpecifiedOptional()); - assertEquals("Address", manyToOneMapping.getSpecifiedTargetEntity()); - - JoinColumn joinColumn = manyToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", joinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", joinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", joinColumn.getSpecifiedTable()); - - Cascade cascade = manyToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertTrue(ormPersistentAttribute.isVirtual()); - - ormPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch()); - assertEquals(true, ormManyToOneMapping.isDefaultOptional()); - //TODO hmm, is this correct? - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormManyToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormManyToOneMapping.getName()); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getFetch()); - assertEquals(true, ormManyToOneMapping.isOptional()); - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - assertFalse(ormManyToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().hasNext()); - - //TODO default join columns for specified xmlManyToOne mapping -// XmlJoinColumn ormJoinColumn = ormManyToOneMapping.defaultJoinColumns().next(); -// assertNull(ormJoinColumn.getSpecifiedName()); -// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertNull(ormJoinColumn.getSpecifiedUnique()); -// assertNull(ormJoinColumn.getSpecifiedNullable()); -// assertNull(ormJoinColumn.getSpecifiedInsertable()); -// assertNull(ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertNull(ormJoinColumn.getSpecifiedTable()); -// -// assertEquals("address", ormJoinColumn.getDefaultName()); -// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable()); -// assertEquals(null, ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java deleted file mode 100644 index 07b01749fc..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java +++ /dev/null @@ -1,386 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.IdClassReference; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmMappedSuperclassTests extends ContextModelTestCase -{ - public OrmMappedSuperclassTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private void createTestIdClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append("TestTypeId").append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals("model.Foo", mappedSuperclassResource.getClassName()); - - //set class in the resource model, verify context model updated - mappedSuperclassResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormMappedSuperclass.getClass_()); - assertEquals("com.Bar", mappedSuperclassResource.getClassName()); - - //set class to null in the resource model - mappedSuperclassResource.setClassName(null); - assertNull(ormMappedSuperclass.getClass_()); - assertNull(mappedSuperclassResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals("model.Foo", mappedSuperclassResource.getClassName()); - - //set class in the context model, verify resource model modified - ormMappedSuperclass.setClass("com.Bar"); - assertEquals("com.Bar", ormMappedSuperclass.getClass_()); - assertEquals("com.Bar", mappedSuperclassResource.getClassName()); - - //set class to null in the context model - ormMappedSuperclass.setClass(null); - assertNull(ormMappedSuperclass.getClass_()); - assertNull(mappedSuperclassResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - - //set access in the resource model, verify context model updated - mappedSuperclassResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormPersistentType.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, mappedSuperclassResource.getAccess()); - - //set access to null in the resource model - mappedSuperclassResource.setAccess(null); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - - //set access in the context model, verify resource model modified - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormPersistentType.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclassResource.getAccess()); - - //set access to null in the context model - ormPersistentType.setSpecifiedAccess(null); - assertNull(ormPersistentType.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - } - //TODO test default access from - //underlying java - //persistence-unit-defaults - //entity-mappings - //with xml-mapping-metadata-complete set - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - mappedSuperclassResource.setMetadataComplete(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(Boolean.TRUE, mappedSuperclassResource.getMetadataComplete()); - - //set access to false in the resource model - mappedSuperclassResource.setMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(Boolean.FALSE, mappedSuperclassResource.getMetadataComplete()); - - mappedSuperclassResource.setMetadataComplete(null); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(Boolean.TRUE, mappedSuperclassResource.getMetadataComplete()); - - //set access to null in the context model - ormMappedSuperclass.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(Boolean.FALSE, mappedSuperclassResource.getMetadataComplete()); - - ormMappedSuperclass.setSpecifiedMetadataComplete(null); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isOverrideMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormMappedSuperclass.isOverrideMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isOverrideMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormMappedSuperclass.isMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormMappedSuperclass.isMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - - public void testMakeMappedSuperclassEntity() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclassPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, mappedSuperclassPersistentType.getSpecifiedAccess()); - } - - //test with 2 MappedSuperclasses, make the first one an Entity so it has to move to the end of the list - public void testMakeMappedSuperclassEntity2() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo2"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclassPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = getXmlEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, mappedSuperclassPersistentType.getSpecifiedAccess()); - - ListIterator persistentTypes = getEntityMappings().getPersistentTypes().iterator(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testMakeMappedSuperclassEmbeddable() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclassPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = getXmlEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, mappedSuperclassPersistentType.getSpecifiedAccess()); - } - //test with 2 MappedSuperclasses, make the first one an Embeddable so it has to move to the end of the list - public void testMakeMappedSuperclassEmbeddable2() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo2"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclassPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = getXmlEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, mappedSuperclassPersistentType.getSpecifiedAccess()); - - ListIterator persistentTypes = getEntityMappings().getPersistentTypes().iterator(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testUpdateIdClass() throws Exception { - createTestIdClass(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - IdClassReference idClassRef = ormMappedSuperclass.getIdClassReference(); - - assertNull(mappedSuperclassResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - mappedSuperclassResource.setIdClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNotNull(mappedSuperclassResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - mappedSuperclassResource.getIdClass().setClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, mappedSuperclassResource.getIdClass().getClassName()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - mappedSuperclassResource.getIdClass().setClassName(existentIdClassName); - assertEquals(existentIdClassName, mappedSuperclassResource.getIdClass().getClassName()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - //test setting @IdClass value to null, id-class tag is not removed - mappedSuperclassResource.getIdClass().setClassName(null); - assertNotNull(mappedSuperclassResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - //reset @IdClass value and then remove id-class tag - mappedSuperclassResource.setIdClass(OrmFactory.eINSTANCE.createXmlClassReference()); - mappedSuperclassResource.getIdClass().setClassName("model.Foo"); - mappedSuperclassResource.setIdClass(null); - assertNull(mappedSuperclassResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - createTestIdClass(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - - XmlMappedSuperclass mappedSuperclassResource = getXmlEntityMappings().getMappedSuperclasses().get(0); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - IdClassReference idClassRef = ormMappedSuperclass.getIdClassReference(); - - assertNull(mappedSuperclassResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClassRef.setSpecifiedIdClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, mappedSuperclassResource.getIdClass().getClassName()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClassRef.setSpecifiedIdClassName(existentIdClassName); - assertEquals(existentIdClassName, mappedSuperclassResource.getIdClass().getClassName()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - idClassRef.setSpecifiedIdClassName(null); - assertNull(mappedSuperclassResource.getIdClass()); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java deleted file mode 100644 index c113a7c555..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java +++ /dev/null @@ -1,358 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmNamedNativeQueryTests extends ContextModelTestCase -{ - public OrmNamedNativeQueryTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setName("newName"); - assertEquals("newName", ormNamedNativeQuery.getName()); - assertEquals("newName", namedNativeQueryResource.getName()); - - //set name to null in the resource model - namedNativeQueryResource.setName(null); - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setName("newName"); - assertEquals("newName", ormNamedNativeQuery.getName()); - assertEquals("newName", namedNativeQueryResource.getName()); - - //set name to null in the context model - ormNamedNativeQuery.setName(null); - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - } - - public void testUpdateQuery() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setQuery("newName"); - assertEquals("newName", ormNamedNativeQuery.getQuery()); - assertEquals("newName", namedNativeQueryResource.getQuery()); - - //set name to null in the resource model - namedNativeQueryResource.setQuery(null); - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - } - - public void testModifyQuery() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setQuery("newName"); - assertEquals("newName", ormNamedNativeQuery.getQuery()); - assertEquals("newName", namedNativeQueryResource.getQuery()); - - //set name to null in the context model - ormNamedNativeQuery.setQuery(null); - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - } - - public void testAddHint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - OrmQueryHint queryHint = ormNamedNativeQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", namedNativeQueryResource.getHints().get(0).getName()); - - OrmQueryHint queryHint2 = ormNamedNativeQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(1).getName()); - - OrmQueryHint queryHint3 = ormNamedNativeQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - - ListIterator queryHints = ormNamedNativeQuery.getHints().iterator(); - assertEquals(queryHint2, queryHints.next()); - assertEquals(queryHint3, queryHints.next()); - assertEquals(queryHint, queryHints.next()); - - queryHints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("BAR", queryHints.next().getName()); - assertEquals("BAZ", queryHints.next().getName()); - assertEquals("FOO", queryHints.next().getName()); - } - - public void testRemoveHint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - ormNamedNativeQuery.addHint(0).setName("FOO"); - ormNamedNativeQuery.addHint(1).setName("BAR"); - ormNamedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedNativeQueryResource.getHints().size()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(2, namedNativeQueryResource.getHints().size()); - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(1, namedNativeQueryResource.getHints().size()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(0).getName()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(0, namedNativeQueryResource.getHints().size()); - } - - public void testMoveHint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - ormNamedNativeQuery.addHint(0).setName("FOO"); - ormNamedNativeQuery.addHint(1).setName("BAR"); - ormNamedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedNativeQueryResource.getHints().size()); - - - ormNamedNativeQuery.moveHint(2, 0); - ListIterator hints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - - - ormNamedNativeQuery.moveHint(0, 1); - hints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAR", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - } - - public void testUpdateHints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - - namedNativeQueryResource.getHints().get(0).setName("FOO"); - namedNativeQueryResource.getHints().get(1).setName("BAR"); - namedNativeQueryResource.getHints().get(2).setName("BAZ"); - - ListIterator hints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().move(2, 0); - hints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().move(0, 1); - hints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(1); - hints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(1); - hints = ormNamedNativeQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(0); - assertFalse(ormNamedNativeQuery.getHints().iterator().hasNext()); - } - - - public void testUpdateResultSetMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultSetMapping()); - assertEquals(null, ormNamedNativeQuery.getResultSetMapping()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setResultSetMapping("foo"); - assertEquals("foo", namedNativeQueryResource.getResultSetMapping()); - assertEquals("foo", ormNamedNativeQuery.getResultSetMapping()); - - //set name to null in the resource model - namedNativeQueryResource.setResultSetMapping(null); - assertNull(namedNativeQueryResource.getResultSetMapping()); - assertNull(ormNamedNativeQuery.getResultSetMapping()); - } - - public void testModifyResultSetMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultSetMapping()); - assertEquals(null, ormNamedNativeQuery.getResultSetMapping()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setResultSetMapping("foo"); - assertEquals("foo", namedNativeQueryResource.getResultSetMapping()); - assertEquals("foo", ormNamedNativeQuery.getResultSetMapping()); - - //set name to null in the context model - ormNamedNativeQuery.setResultSetMapping(null); - assertNull(namedNativeQueryResource.getResultSetMapping()); - assertNull(ormNamedNativeQuery.getResultSetMapping()); - } - - public void testUpdateResultClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultClass()); - assertEquals(null, ormNamedNativeQuery.getResultClass()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setResultClass("foo"); - assertEquals("foo", namedNativeQueryResource.getResultClass()); - assertEquals("foo", ormNamedNativeQuery.getResultClass()); - - //set name to null in the resource model - namedNativeQueryResource.setResultClass(null); - assertNull(namedNativeQueryResource.getResultClass()); - assertNull(ormNamedNativeQuery.getResultClass()); - } - - public void testModifyResultClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.getQueryContainer().addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultClass()); - assertEquals(null, ormNamedNativeQuery.getResultClass()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setResultClass("foo"); - assertEquals("foo", namedNativeQueryResource.getResultClass()); - assertEquals("foo", ormNamedNativeQuery.getResultClass()); - - //set name to null in the context model - ormNamedNativeQuery.setResultClass(null); - assertNull(namedNativeQueryResource.getResultClass()); - assertNull(ormNamedNativeQuery.getResultClass()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java deleted file mode 100644 index f35a05d468..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmNamedQueryTests extends ContextModelTestCase -{ - public OrmNamedQueryTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - - //set name in the resource model, verify context model updated - namedQueryResource.setName("newName"); - assertEquals("newName", ormNamedQuery.getName()); - assertEquals("newName", namedQueryResource.getName()); - - //set name to null in the resource model - namedQueryResource.setName(null); - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - - //set name in the context model, verify resource model updated - ormNamedQuery.setName("newName"); - assertEquals("newName", ormNamedQuery.getName()); - assertEquals("newName", namedQueryResource.getName()); - - //set name to null in the context model - ormNamedQuery.setName(null); - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - } - - public void testUpdateQuery() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - - //set name in the resource model, verify context model updated - namedQueryResource.setQuery("newName"); - assertEquals("newName", ormNamedQuery.getQuery()); - assertEquals("newName", namedQueryResource.getQuery()); - - //set name to null in the resource model - namedQueryResource.setQuery(null); - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - } - - public void testModifyQuery() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - - //set name in the context model, verify resource model updated - ormNamedQuery.setQuery("newName"); - assertEquals("newName", ormNamedQuery.getQuery()); - assertEquals("newName", namedQueryResource.getQuery()); - - //set name to null in the context model - ormNamedQuery.setQuery(null); - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - } - - public void testAddHint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - OrmQueryHint queryHint = ormNamedQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", namedQueryResource.getHints().get(0).getName()); - - OrmQueryHint queryHint2 = ormNamedQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(1).getName()); - - OrmQueryHint queryHint3 = ormNamedQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - - ListIterator queryHints = ormNamedQuery.getHints().iterator(); - assertEquals(queryHint2, queryHints.next()); - assertEquals(queryHint3, queryHints.next()); - assertEquals(queryHint, queryHints.next()); - - queryHints = ormNamedQuery.getHints().iterator(); - assertEquals("BAR", queryHints.next().getName()); - assertEquals("BAZ", queryHints.next().getName()); - assertEquals("FOO", queryHints.next().getName()); - } - - public void testRemoveHint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - ormNamedQuery.addHint(0).setName("FOO"); - ormNamedQuery.addHint(1).setName("BAR"); - ormNamedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedQueryResource.getHints().size()); - - ormNamedQuery.removeHint(0); - assertEquals(2, namedQueryResource.getHints().size()); - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - - ormNamedQuery.removeHint(0); - assertEquals(1, namedQueryResource.getHints().size()); - assertEquals("BAZ", namedQueryResource.getHints().get(0).getName()); - - ormNamedQuery.removeHint(0); - assertEquals(0, namedQueryResource.getHints().size()); - } - - public void testMoveHint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - ormNamedQuery.addHint(0).setName("FOO"); - ormNamedQuery.addHint(1).setName("BAR"); - ormNamedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedQueryResource.getHints().size()); - - - ormNamedQuery.moveHint(2, 0); - ListIterator hints = ormNamedQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - - - ormNamedQuery.moveHint(0, 1); - hints = ormNamedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAR", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - } - - public void testUpdateHints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.getQueryContainer().addNamedQuery(0); - - XmlNamedQuery namedQueryResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - - namedQueryResource.getHints().get(0).setName("FOO"); - namedQueryResource.getHints().get(1).setName("BAR"); - namedQueryResource.getHints().get(2).setName("BAZ"); - - ListIterator hints = ormNamedQuery.getHints().iterator(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().move(2, 0); - hints = ormNamedQuery.getHints().iterator(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().move(0, 1); - hints = ormNamedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(1); - hints = ormNamedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(1); - hints = ormNamedQuery.getHints().iterator(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(0); - assertFalse(ormNamedQuery.getHints().iterator().hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java deleted file mode 100644 index ab8fee5854..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java +++ /dev/null @@ -1,1058 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedByRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyRelationship; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmOneToManyMappingTests extends ContextModelTestCase -{ - public OrmOneToManyMappingTests(String name) { - super(name); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityWithOneToManyMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals("oneToManyMapping", ormOneToManyMapping.getName()); - assertEquals("oneToManyMapping", oneToMany.getName()); - - //set name in the resource model, verify context model updated - oneToMany.setName("newName"); - assertEquals("newName", ormOneToManyMapping.getName()); - assertEquals("newName", oneToMany.getName()); - - //set name to null in the resource model - oneToMany.setName(null); - assertNull(ormOneToManyMapping.getName()); - assertNull(oneToMany.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals("oneToManyMapping", ormOneToManyMapping.getName()); - assertEquals("oneToManyMapping", oneToMany.getName()); - - //set name in the context model, verify resource model updated - ormOneToManyMapping.setName("newName"); - assertEquals("newName", ormOneToManyMapping.getName()); - assertEquals("newName", oneToMany.getName()); - - //set name to null in the context model - ormOneToManyMapping.setName(null); - assertNull(ormOneToManyMapping.getName()); - assertNull(oneToMany.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the resource model - oneToMany.setTargetEntity(null); - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the context model - ormOneToManyMapping.setSpecifiedTargetEntity(null); - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToManyResource.getFetch()); - - oneToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToManyResource.getFetch()); - - //set fetch to null in the resource model - oneToManyResource.setFetch(null); - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToManyResource.getFetch()); - assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch()); - - ormOneToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToManyResource.getFetch()); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormOneToManyMapping.setSpecifiedFetch(null); - assertNull(oneToManyResource.getFetch()); - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - OrmMappedByRelationshipStrategy strategy = ormOneToManyMapping.getRelationship().getMappedByStrategy(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", strategy.getMappedByAttribute()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //setmappedBy to null in the resource model - oneToMany.setMappedBy(null); - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - OrmMappedByRelationshipStrategy strategy = ormOneToManyMapping.getRelationship().getMappedByStrategy(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - strategy.setMappedByAttribute("newMappedBy"); - assertEquals("newMappedBy", strategy.getMappedByAttribute()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //set mappedBy to null in the context model - strategy.setMappedByAttribute(null); - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToManyMapping contextMapping = (OrmOneToManyMapping) contextAttribute.getMapping(); - OrmOneToManyRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToManyMapping contextMapping = (OrmOneToManyMapping) contextAttribute.getMapping(); - OrmOneToManyRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualOneToManyMapping.getSpecifiedMapKey()); - assertNull(virtualOneToManyMapping.getMapKey()); - assertFalse(virtualOneToManyMapping.isPkMapKey()); - assertFalse(virtualOneToManyMapping.isCustomMapKey()); - assertTrue(virtualOneToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setPkMapKey(true); - assertEquals("id", virtualOneToManyMapping.getMapKey()); - assertTrue(virtualOneToManyMapping.isPkMapKey()); - assertFalse(virtualOneToManyMapping.isCustomMapKey()); - assertFalse(virtualOneToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setCustomMapKey(true); - javaOneToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualOneToManyMapping.getSpecifiedMapKey()); - assertEquals("city", virtualOneToManyMapping.getMapKey()); - assertFalse(virtualOneToManyMapping.isPkMapKey()); - assertTrue(virtualOneToManyMapping.isCustomMapKey()); - assertFalse(virtualOneToManyMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setNoMapKey(true); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateOrderBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(oneToMany.getOrderBy()); - - //set orderBy in the resource model, verify context model updated - oneToMany.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", oneToMany.getOrderBy()); - - //set orderBy to null in the resource model - oneToMany.setOrderBy(null); - assertNull(ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(oneToMany.getOrderBy()); - } - - public void testModifyOrderBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(oneToMany.getOrderBy()); - - //set mappedBy in the context model, verify resource model updated - ormOneToManyMapping.getOrderable().setSpecifiedOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", oneToMany.getOrderBy()); - - //set mappedBy to null in the context model - ormOneToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertNull(ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(oneToMany.getOrderBy()); - } - - public void testIsNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering()); - - ormOneToManyMapping.getOrderable().setSpecifiedOrderBy("foo"); - assertFalse(ormOneToManyMapping.getOrderable().isNoOrdering()); - - ormOneToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering()); - } - - public void testSetNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering()); - - ormOneToManyMapping.getOrderable().setSpecifiedOrderBy("foo"); - assertFalse(ormOneToManyMapping.getOrderable().isNoOrdering()); - - ormOneToManyMapping.getOrderable().setNoOrdering(true); - assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering()); - assertNull(ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - } -//TODO -// public boolean isOrderByPk() { -// return "".equals(getOrderBy()); -// } -// -// public void setOrderByPk() { -// setOrderBy(""); -// } - - public void testIsCustomOrdering() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertFalse(ormOneToManyMapping.getOrderable().isCustomOrdering()); - - ormOneToManyMapping.getOrderable().setSpecifiedOrderBy("foo"); - assertTrue(ormOneToManyMapping.getOrderable().isCustomOrdering()); - - ormOneToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertFalse(ormOneToManyMapping.getOrderable().isCustomOrdering()); - } - - public void testOneToManyMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToOneToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToManyMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - JoinTable joinTable = ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals("name", joinTable.joinColumns().next().getSpecifiedName()); - assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName()); - assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName()); - assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName()); - } - - public void testOneToManyMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToManyMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("customOrder"); - oneToManyMapping.setSpecifiedMapKey("mapKey"); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) virtualAttribute.getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - OrmOneToManyMapping specifiedOneToManyMapping = (OrmOneToManyMapping) virtualAttribute.convertToSpecified().getMapping(); - mapKeyNames = specifiedOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - specifiedOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = specifiedOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - specifiedOneToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = specifiedOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualOneToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = virtualOneToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - - assertTrue(virtualOneToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = virtualPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch()); - assertEquals("test.Address", ormOneToManyMapping.getTargetEntity()); - assertNull(ormOneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = ormOneToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - - assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java deleted file mode 100644 index 148e3a3f92..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java +++ /dev/null @@ -1,1196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.MappedByRelationshipStrategy; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneRelationship; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmOneToOneMappingTests extends ContextModelTestCase -{ - public OrmOneToOneMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestEntityWithOneToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals("oneToOneMapping", ormOneToOneMapping.getName()); - assertEquals("oneToOneMapping", oneToOne.getName()); - - //set name in the resource model, verify context model updated - oneToOne.setName("newName"); - assertEquals("newName", ormOneToOneMapping.getName()); - assertEquals("newName", oneToOne.getName()); - - //set name to null in the resource model - oneToOne.setName(null); - assertNull(ormOneToOneMapping.getName()); - assertNull(oneToOne.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals("oneToOneMapping", ormOneToOneMapping.getName()); - assertEquals("oneToOneMapping", oneToOne.getName()); - - //set name in the context model, verify resource model updated - ormOneToOneMapping.setName("newName"); - assertEquals("newName", ormOneToOneMapping.getName()); - assertEquals("newName", oneToOne.getName()); - - //set name to null in the context model - ormOneToOneMapping.setName(null); - assertNull(ormOneToOneMapping.getName()); - assertNull(oneToOne.getName()); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the resource model - oneToOne.setTargetEntity(null); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the context model - ormOneToOneMapping.setSpecifiedTargetEntity(null); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToOneResource.getFetch()); - - oneToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToOneResource.getFetch()); - - //set fetch to null in the resource model - oneToOneResource.setFetch(null); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToOneResource.getFetch()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getSpecifiedFetch()); - - ormOneToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToOneResource.getFetch()); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormOneToOneMapping.setSpecifiedFetch(null); - assertNull(oneToOneResource.getFetch()); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - MappedByRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getMappedByStrategy(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToOne.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", strategy.getMappedByAttribute()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the resource model - oneToOne.setMappedBy(null); - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - MappedByRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getMappedByStrategy(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - strategy.setMappedByAttribute("newMappedBy"); - assertEquals("newMappedBy", strategy.getMappedByAttribute()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the context model - strategy.setMappedByAttribute(null); - assertNull(strategy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping contextMapping = (OrmOneToOneMapping) contextAttribute.getMapping(); - OrmOneToOneRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping contextMapping = (OrmOneToOneMapping) contextAttribute.getMapping(); - OrmOneToOneRelationship rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.getPrimaryKeyJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - - //set optional in the resource model, verify context model updated - oneToOneResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOneResource.getOptional()); - - oneToOneResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOneResource.getOptional()); - - //set optional to null in the resource model - oneToOneResource.setOptional(null); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - - //set optional in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneResource.getOptional()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getSpecifiedOptional()); - - ormOneToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneResource.getOptional()); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - - //set optional to null in the context model - ormOneToOneMapping.setSpecifiedOptional(null); - assertNull(oneToOneResource.getOptional()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - OrmJoinColumnRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getJoinColumnStrategy(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - OrmJoinColumn joinColumn = strategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", oneToOneResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = strategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = strategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - - ListIterator joinColumns = strategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = strategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - OrmJoinColumnRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getJoinColumnStrategy(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - strategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - strategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - strategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getJoinColumns().size()); - - strategy.removeSpecifiedJoinColumn(0); - assertEquals(2, oneToOneResource.getJoinColumns().size()); - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - - strategy.removeSpecifiedJoinColumn(0); - assertEquals(1, oneToOneResource.getJoinColumns().size()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(0).getName()); - - strategy.removeSpecifiedJoinColumn(0); - assertEquals(0, oneToOneResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - OrmJoinColumnRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getJoinColumnStrategy(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - strategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - strategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - strategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getJoinColumns().size()); - - - strategy.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = strategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - - - strategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = strategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - } - - public void testOneToOneMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormOneToOneMapping.getName()); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - assertNull(ormOneToOneMapping.getTargetEntity()); - - - assertTrue(ormOneToOneMapping.getRelationship().getJoinColumnStrategy().joinColumnsSize() > 0); - //TODO default joinColumns - //assertTrue(ormOneToOneMapping.defaultJoinColumns().hasNext()); - - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", oneToOneMapping.getName()); - assertEquals(FetchType.LAZY, oneToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOptional()); - assertEquals("Address", oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOneMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - JoinColumn joinColumn = - oneToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", joinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", joinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", joinColumn.getSpecifiedTable()); - - Cascade cascade = oneToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertTrue(ormPersistentAttribute.isVirtual()); - - ormPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - assertEquals("test.Address", ormOneToOneMapping.getTargetEntity()); - assertNull(ormOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormOneToOneMapping.getName()); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(ormOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - //TODO default target entity in xml - //assertEquals("test.Address", ormOneToOneMapping.getDefaultTargetEntity()); - - assertTrue(ormOneToOneMapping.getRelationship().getJoinColumnStrategy().joinColumnsSize() > 0); - - //TODO default join columns for specified xmlOneToOne mapping -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.defaultJoinColumns().next(); -// assertNull(ormJoinColumn.getSpecifiedName()); -// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertNull(ormJoinColumn.getSpecifiedUnique()); -// assertNull(ormJoinColumn.getSpecifiedNullable()); -// assertNull(ormJoinColumn.getSpecifiedInsertable()); -// assertNull(ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertNull(ormJoinColumn.getSpecifiedTable()); -// -// assertEquals("address", ormJoinColumn.getDefaultName()); -// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable()); -// assertEquals(null, ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - - public void testOneToOneMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToOneMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToOneMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - - joinColumn = ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("name", joinColumn.getName()); - assertEquals("referenceName", joinColumn.getReferencedColumnName()); - } - - public void testOneToOneMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - - - - - public void testAddPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - OrmPrimaryKeyJoinColumnRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - OrmPrimaryKeyJoinColumn joinColumn = strategy.addPrimaryKeyJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn joinColumn2 = strategy.addPrimaryKeyJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn joinColumn3 = strategy.addPrimaryKeyJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemovePrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - OrmPrimaryKeyJoinColumnRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getPrimaryKeyJoinColumns().size()); - - strategy.removePrimaryKeyJoinColumn(0); - assertEquals(2, oneToOneResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - - strategy.removePrimaryKeyJoinColumn(0); - assertEquals(1, oneToOneResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - - strategy.removePrimaryKeyJoinColumn(0); - assertEquals(0, oneToOneResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMovePrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - OrmPrimaryKeyJoinColumnRelationshipStrategy strategy = ormOneToOneMapping.getRelationship().getPrimaryKeyJoinColumnStrategy(); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getPrimaryKeyJoinColumns().size()); - - - strategy.movePrimaryKeyJoinColumn(2, 0); - ListIterator joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - strategy.movePrimaryKeyJoinColumn(0, 1); - joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java deleted file mode 100644 index df11aa43ec..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmPrimaryKeyJoinColumnTests extends ContextModelTestCase -{ - public OrmPrimaryKeyJoinColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getName()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - primaryKeyJoinColumnResource.setName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getName()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setSpecifiedName("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("foo", primaryKeyJoinColumnResource.getName()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setSpecifiedName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setReferencedColumnName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - primaryKeyJoinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getReferencedColumnName()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("foo", primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getReferencedColumnName()); - } - -// public void testUpdateDefaultNameFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.javaEntity().getTable().setSpecifiedName("Foo"); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(null); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.getTable().setSpecifiedName("Bar"); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -// } - - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("FOO", primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setColumnDefinition(null); - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - primaryKeyJoinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("FOO", primaryKeyJoinColumnResource.getColumnDefinition()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setColumnDefinition("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("foo", primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setColumnDefinition(null); - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getColumnDefinition()); - } - - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java deleted file mode 100644 index 8ca1ed4d62..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmQueryHintTests extends ContextModelTestCase -{ - public OrmQueryHintTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.getQueryContainer().addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - - //set name in the resource model, verify context model updated - queryHintResource.setName("newName"); - assertEquals("newName", ormQueryHint.getName()); - assertEquals("newName", queryHintResource.getName()); - - //set name to null in the resource model - queryHintResource.setName(null); - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.getQueryContainer().addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - - //set name in the context model, verify resource model updated - ormQueryHint.setName("newName"); - assertEquals("newName", ormQueryHint.getName()); - assertEquals("newName", queryHintResource.getName()); - - //set name to null in the context model - ormQueryHint.setName(null); - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - } - - public void testUpdateValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.getQueryContainer().addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - - //set name in the resource model, verify context model updated - queryHintResource.setValue("newName"); - assertEquals("newName", ormQueryHint.getValue()); - assertEquals("newName", queryHintResource.getValue()); - - //set name to null in the resource model - queryHintResource.setValue(null); - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - } - - public void testModifyValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.getQueryContainer().addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = getXmlEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - - //set name in the context model, verify resource model updated - ormQueryHint.setValue("newName"); - assertEquals("newName", ormQueryHint.getValue()); - assertEquals("newName", queryHintResource.getValue()); - - //set name to null in the context model - ormQueryHint.setValue(null); - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java deleted file mode 100644 index a552d2674f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java +++ /dev/null @@ -1,767 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.ReadOnlySecondaryTable; -import org.eclipse.jpt.core.context.ReadOnlyUniqueConstraint; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmVirtualSecondaryTable; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmSecondaryTableTests extends ContextModelTestCase -{ - public OrmSecondaryTableTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //set name in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTable()); - entityResource.getSecondaryTables().get(0).setName("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getName()); - - //set name to null in the resource model - entityResource.getSecondaryTables().get(0).setName(null); - assertNull(secondaryTable.getSpecifiedName()); - assertNull(entityResource.getSecondaryTables().get(0).getName()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //set name in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedName("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedName()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getName()); - - //set name to null in the context model - secondaryTable.setSpecifiedName(null); - assertNull(secondaryTable.getSpecifiedName()); - assertNull(entityResource.getSecondaryTables().get(0).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - ormEntity.getJavaTypeMapping().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - - ReadOnlySecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("FOO", ormSecondaryTable.getSpecifiedName()); - - ormEntity.getJavaTypeMapping().specifiedSecondaryTables().next().setSpecifiedName("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedName()); - - ormEntity.setSecondaryTablesAreDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultName()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedName()); - - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //set schema in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTable()); - entityResource.getSecondaryTables().get(0).setSchema("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getSchema()); - - //set schema to null in the resource model - entityResource.getSecondaryTables().get(0).setSchema(null); - assertNull(secondaryTable.getSpecifiedSchema()); - assertNull(entityResource.getSecondaryTables().get(0).getSchema()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //set schema in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedSchema("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedSchema()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getSchema()); - - //set schema to null in the context model - secondaryTable.setSpecifiedSchema(null); - assertNull(secondaryTable.getSpecifiedSchema()); - assertNull(entityResource.getSecondaryTables().get(0).getSchema()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultSchemaFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaTypeMapping().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedSchema("BAR"); - - OrmVirtualSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("BAR", ormSecondaryTable.getSpecifiedSchema()); - - javaSecondaryTable.setSpecifiedSchema("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedSchema()); - - - ormEntity.setSecondaryTablesAreDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultSchema()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentOrmEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childOrmEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertNull(childOrmEntity.getTable().getDefaultSchema()); - - parentOrmEntity.getTable().setSpecifiedSchema("FOO"); - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertEquals("FOO", childOrmEntity.getTable().getDefaultSchema()); - - parentOrmEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertNull(childOrmEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - ormSecondaryTable.setSpecifiedName("FOO"); - assertNull(ormSecondaryTable.getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", ormSecondaryTable.getDefaultSchema()); - - getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", ormSecondaryTable.getDefaultSchema()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaTypeMapping().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedSchema("JAVA_SCHEMA"); - assertEquals("BAR", ormSecondaryTable.getDefaultSchema()); //schema is not defaulted from underlying java - - getEntityMappings().setSpecifiedSchema(null); - assertEquals("FOO", ormSecondaryTable.getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(ormSecondaryTable.getDefaultSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //set catalog in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTable()); - entityResource.getSecondaryTables().get(0).setCatalog("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getCatalog()); - - //set catalog to null in the resource model - entityResource.getSecondaryTables().get(0).setCatalog(null); - assertNull(secondaryTable.getSpecifiedCatalog()); - assertNull(entityResource.getSecondaryTables().get(0).getCatalog()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //set catalog in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedCatalog("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedCatalog()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getCatalog()); - - //set catalog to null in the context model - secondaryTable.setSpecifiedCatalog(null); - assertNull(secondaryTable.getSpecifiedCatalog()); - assertNull(entityResource.getSecondaryTables().get(0).getCatalog()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultCatalogFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaTypeMapping().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedCatalog("BAR"); - - OrmVirtualSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("BAR", ormSecondaryTable.getSpecifiedCatalog()); - - javaSecondaryTable.setSpecifiedCatalog("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedCatalog()); - - ormEntity.setSecondaryTablesAreDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultCatalog()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - ormSecondaryTable.setSpecifiedName("FOO"); - assertNull(ormSecondaryTable.getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", ormSecondaryTable.getDefaultCatalog()); - - getEntityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", ormSecondaryTable.getDefaultCatalog()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaTypeMapping().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedCatalog("JAVA_CATALOG"); - assertEquals("BAR", ormSecondaryTable.getDefaultCatalog()); //schema is not defaulted from underlying java - - getEntityMappings().setSpecifiedCatalog(null); - assertEquals("FOO", ormSecondaryTable.getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(ormSecondaryTable.getDefaultCatalog()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn2 = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn3 = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1); - primaryKeyJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals(primaryKeyJoinColumn2, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn3, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn, primaryKeyJoinColumns.next()); - - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(2, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(1, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(0, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - - - ormSecondaryTable.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormSecondaryTable.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - - secondaryTableResource.getPrimaryKeyJoinColumns().get(0).setName("FOO"); - secondaryTableResource.getPrimaryKeyJoinColumns().get(1).setName("BAR"); - secondaryTableResource.getPrimaryKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().move(2, 0); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().move(0, 1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormSecondaryTable.specifiedPrimaryKeyJoinColumns().hasNext()); - } - - - public void testUniqueConstraints() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ListIterator uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - assertEquals(0, ormSecondaryTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - secondaryTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormSecondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = secondaryTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = secondaryTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, secondaryTableResource.getUniqueConstraints().size()); - - ormSecondaryTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormSecondaryTable.removeUniqueConstraint(1); - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormSecondaryTable.removeUniqueConstraint(0); - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, secondaryTableResource.getUniqueConstraints().size()); - - - ormSecondaryTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormSecondaryTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - secondaryTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - secondaryTableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(0); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - JavaEntity javaEntity = (JavaEntity) ormPersistentType.getJavaPersistentType().getMapping(); - JavaSecondaryTable javaSecondaryTable = javaEntity.addSpecifiedSecondaryTable(); - javaSecondaryTable.setSpecifiedName("SECONDARY"); - - ReadOnlySecondaryTable ormSecondaryTable = ormEntity.secondaryTables().next(); - assertTrue(ormSecondaryTable.isVirtual()); - assertFalse(ormSecondaryTable.uniqueConstraints().hasNext()); - - - javaSecondaryTable.addUniqueConstraint().addColumnName("FOO"); - javaSecondaryTable.addUniqueConstraint().addColumnName("BAR"); - javaSecondaryTable.addUniqueConstraint().addColumnName("BAZ"); - - List uniqueConstraints = CollectionTools.list(ormSecondaryTable.uniqueConstraints()); - assertEquals(3, uniqueConstraints.size()); - assertEquals("FOO", uniqueConstraints.get(0).getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.get(1).getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.get(2).getColumnNames().iterator().next()); - - ormEntity.setSecondaryTablesAreDefinedInXml(true); - OrmSecondaryTable ormSecondaryTable2 = ormEntity.specifiedSecondaryTables().next(); - ormSecondaryTable2.setSpecifiedName("SECONDARY"); - - assertEquals("SECONDARY", ormSecondaryTable.getSpecifiedName()); - assertFalse(ormSecondaryTable2.isVirtual()); - assertEquals(3, ormSecondaryTable2.uniqueConstraintsSize()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java deleted file mode 100644 index 5ee35680f5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmSequenceGeneratorTests extends ContextModelTestCase -{ - public OrmSequenceGeneratorTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateSpecifiedName() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setName("FOO"); - assertEquals("FOO", sequenceGenerator.getName()); - assertEquals("FOO", sequenceGeneratorResource.getName()); - - //set name to null in the resource model - sequenceGeneratorResource.setName(null); - assertNull(sequenceGenerator.getName()); - assertNull(sequenceGeneratorResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setName("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getName()); - assertEquals("FOO", sequenceGenerator.getName()); - - //set name to null in the context model - sequenceGenerator.setName(null); - assertNull(sequenceGeneratorResource.getName()); - assertNull(sequenceGenerator.getName()); - } - - public void testUpdateSpecifiedSequenceName() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setSequenceName("FOO"); - assertEquals("FOO", sequenceGenerator.getSpecifiedSequenceName()); - assertEquals("FOO", sequenceGeneratorResource.getSequenceName()); - - //set name to null in the resource model - sequenceGeneratorResource.setSequenceName(null); - assertNull(sequenceGenerator.getSpecifiedSequenceName()); - assertNull(sequenceGeneratorResource.getSequenceName()); - } - - public void testModifySpecifiedSequenceName() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setSpecifiedSequenceName("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getSequenceName()); - assertEquals("FOO", sequenceGenerator.getSpecifiedSequenceName()); - - //set name to null in the context model - sequenceGenerator.setSpecifiedSequenceName(null); - assertNull(sequenceGeneratorResource.getSequenceName()); - assertNull(sequenceGenerator.getSpecifiedSequenceName()); - } - - public void testUpdateSpecifiedInitialValue() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set initial value in the resource model, verify context model updated - sequenceGeneratorResource.setInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getInitialValue()); - - //set initial value to 1, which happens to be the default, in the resource model - sequenceGeneratorResource.setInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getInitialValue()); - - //set initial value to null in the resource model - sequenceGeneratorResource.setInitialValue(null); - assertNull(sequenceGenerator.getSpecifiedInitialValue()); - assertNull(sequenceGeneratorResource.getInitialValue()); - } - - public void testModifySpecifiedInitialValue() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set initial value in the context model, verify resource model modified - sequenceGenerator.setSpecifiedInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedInitialValue()); - - sequenceGenerator.setSpecifiedInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedInitialValue()); - - //set initial value to null in the context model - sequenceGenerator.setSpecifiedInitialValue(null); - assertNull(sequenceGeneratorResource.getInitialValue()); - assertNull(sequenceGenerator.getSpecifiedInitialValue()); - } - - public void testUpdateSpecifiedAllocationSize() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set allocation size in the resource model, verify context model updated - sequenceGeneratorResource.setAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getAllocationSize()); - - //set allocation size to 50, which happens to be the default, in the resource model - sequenceGeneratorResource.setAllocationSize(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getAllocationSize()); - - //set allocation size to null in the resource model - sequenceGeneratorResource.setAllocationSize(null); - assertNull(sequenceGenerator.getSpecifiedAllocationSize()); - assertNull(sequenceGeneratorResource.getAllocationSize()); - } - - public void testModifySpecifiedAllocationSize() throws Exception { - SequenceGenerator sequenceGenerator = getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set allocation size in the context model, verify resource model modified - sequenceGenerator.setSpecifiedAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedAllocationSize()); - - sequenceGenerator.setSpecifiedAllocationSize(Integer.valueOf(50)); - assertEquals(Integer.valueOf(50), sequenceGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(50), sequenceGenerator.getSpecifiedAllocationSize()); - - //set allocation size to null in the context model - sequenceGenerator.setSpecifiedAllocationSize(null); - assertNull(sequenceGeneratorResource.getAllocationSize()); - assertNull(sequenceGenerator.getSpecifiedAllocationSize()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java deleted file mode 100644 index 1d5b4932fb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java +++ /dev/null @@ -1,604 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmTableGeneratorTests extends ContextModelTestCase -{ - public OrmTableGeneratorTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public void testUpdateSpecifiedName() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setName("FOO"); - assertEquals("FOO", tableGenerator.getName()); - assertEquals("FOO", tableGeneratorResource.getName()); - - //set name to null in the resource model - tableGeneratorResource.setName(null); - assertNull(tableGenerator.getName()); - assertNull(tableGeneratorResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setName("FOO"); - assertEquals("FOO", tableGeneratorResource.getName()); - assertEquals("FOO", tableGenerator.getName()); - - //set name to null in the context model - tableGenerator.setName(null); - assertNull(tableGeneratorResource.getName()); - assertNull(tableGenerator.getName()); - } - - public void testUpdateSpecifiedInitialValue() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set initial value in the resource model, verify context model updated - tableGeneratorResource.setInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getInitialValue()); - - //set initial value to 1, which happens to be the default, in the resource model - tableGeneratorResource.setInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getInitialValue()); - - //set initial value to null in the resource model - tableGeneratorResource.setInitialValue(null); - assertNull(tableGenerator.getSpecifiedInitialValue()); - assertNull(tableGeneratorResource.getInitialValue()); - } - - public void testModifySpecifiedInitialValue() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set initial value in the context model, verify resource model modified - tableGenerator.setSpecifiedInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedInitialValue()); - - tableGenerator.setSpecifiedInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - - //set initial value to null in the context model - tableGenerator.setSpecifiedInitialValue(null); - assertNull(tableGeneratorResource.getInitialValue()); - assertNull(tableGenerator.getSpecifiedInitialValue()); - } - - public void testUpdateSpecifiedAllocationSize() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set allocation size in the resource model, verify context model updated - tableGeneratorResource.setAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getAllocationSize()); - - //set allocation size to 50, which happens to be the default, in the resource model - tableGeneratorResource.setAllocationSize(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getAllocationSize()); - - //set allocation size to null in the resource model - tableGeneratorResource.setAllocationSize(null); - assertNull(tableGenerator.getSpecifiedAllocationSize()); - assertNull(tableGeneratorResource.getAllocationSize()); - } - - public void testModifySpecifiedAllocationSize() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set allocation size in the context model, verify resource model modified - tableGenerator.setSpecifiedAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedAllocationSize()); - - tableGenerator.setSpecifiedAllocationSize(Integer.valueOf(50)); - assertEquals(Integer.valueOf(50), tableGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(50), tableGenerator.getSpecifiedAllocationSize()); - - //set allocation size to null in the context model - tableGenerator.setSpecifiedAllocationSize(null); - assertNull(tableGeneratorResource.getAllocationSize()); - assertNull(tableGenerator.getSpecifiedAllocationSize()); - } - - public void testUpdateSpecifiedTable() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setTable("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedTable()); - assertEquals("FOO", tableGeneratorResource.getTable()); - - //set name to null in the resource model - tableGeneratorResource.setTable(null); - assertNull(tableGenerator.getSpecifiedTable()); - assertNull(tableGeneratorResource.getTable()); - } - - public void testModifySpecifiedTable() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedTable("FOO"); - assertEquals("FOO", tableGeneratorResource.getTable()); - assertEquals("FOO", tableGenerator.getSpecifiedTable()); - - //set name to null in the context model - tableGenerator.setSpecifiedTable(null); - assertNull(tableGeneratorResource.getTable()); - assertNull(tableGenerator.getSpecifiedTable()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setSchema("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedSchema()); - assertEquals("FOO", tableGeneratorResource.getSchema()); - - //set name to null in the resource model - tableGeneratorResource.setSchema(null); - assertNull(tableGenerator.getSpecifiedSchema()); - assertNull(tableGeneratorResource.getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedSchema("FOO"); - assertEquals("FOO", tableGeneratorResource.getSchema()); - assertEquals("FOO", tableGenerator.getSpecifiedSchema()); - - //set name to null in the context model - tableGenerator.setSpecifiedSchema(null); - assertNull(tableGeneratorResource.getSchema()); - assertNull(tableGenerator.getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - - assertNull(tableGenerator.getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", tableGenerator.getDefaultSchema()); - - getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", tableGenerator.getDefaultSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setCatalog("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedCatalog()); - assertEquals("FOO", tableGeneratorResource.getCatalog()); - - //set name to null in the resource model - tableGeneratorResource.setCatalog(null); - assertNull(tableGenerator.getSpecifiedCatalog()); - assertNull(tableGeneratorResource.getCatalog()); - } - - public void testModifySpecifiedCatalog() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedCatalog("FOO"); - assertEquals("FOO", tableGeneratorResource.getCatalog()); - assertEquals("FOO", tableGenerator.getSpecifiedCatalog()); - - //set name to null in the context model - tableGenerator.setSpecifiedCatalog(null); - assertNull(tableGeneratorResource.getCatalog()); - assertNull(tableGenerator.getSpecifiedCatalog()); - } - - public void testUpdateSpecifiedPkColumnName() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setPkColumnName("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnName()); - assertEquals("FOO", tableGeneratorResource.getPkColumnName()); - - //set name to null in the resource model - tableGeneratorResource.setPkColumnName(null); - assertNull(tableGenerator.getSpecifiedPkColumnName()); - assertNull(tableGeneratorResource.getPkColumnName()); - } - - public void testModifySpecifiedPkColumnName() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedPkColumnName("FOO"); - assertEquals("FOO", tableGeneratorResource.getPkColumnName()); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnName()); - - //set name to null in the context model - tableGenerator.setSpecifiedPkColumnName(null); - assertNull(tableGeneratorResource.getPkColumnName()); - assertNull(tableGenerator.getSpecifiedPkColumnName()); - } - - public void testUpdateSpecifiedValueColumnName() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setValueColumnName("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedValueColumnName()); - assertEquals("FOO", tableGeneratorResource.getValueColumnName()); - - //set name to null in the resource model - tableGeneratorResource.setValueColumnName(null); - assertNull(tableGenerator.getSpecifiedValueColumnName()); - assertNull(tableGeneratorResource.getValueColumnName()); - } - - public void testModifySpecifiedValueColumnName() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedValueColumnName("FOO"); - assertEquals("FOO", tableGeneratorResource.getValueColumnName()); - assertEquals("FOO", tableGenerator.getSpecifiedValueColumnName()); - - //set name to null in the context model - tableGenerator.setSpecifiedValueColumnName(null); - assertNull(tableGeneratorResource.getValueColumnName()); - assertNull(tableGenerator.getSpecifiedValueColumnName()); - } - - public void testUpdateSpecifiedPkColumnValue() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setPkColumnValue("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnValue()); - assertEquals("FOO", tableGeneratorResource.getPkColumnValue()); - - //set name to null in the resource model - tableGeneratorResource.setPkColumnValue(null); - assertNull(tableGenerator.getSpecifiedPkColumnValue()); - assertNull(tableGeneratorResource.getPkColumnValue()); - } - - public void testModifySpecifiedPkColumnValue() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedPkColumnValue("FOO"); - assertEquals("FOO", tableGeneratorResource.getPkColumnValue()); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnValue()); - - //set name to null in the context model - tableGenerator.setSpecifiedPkColumnValue(null); - assertNull(tableGeneratorResource.getPkColumnValue()); - assertNull(tableGenerator.getSpecifiedPkColumnValue()); - } - - - public void testUniqueConstraints() throws Exception { - OrmTableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - assertEquals(0, tableGenerator.getUniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableGeneratorResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, tableGenerator.getUniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = tableGeneratorResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = tableGeneratorResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, tableGeneratorResource.getUniqueConstraints().size()); - - tableGenerator.removeUniqueConstraint(1); - - ListIterator uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(1); - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(0); - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, tableGeneratorResource.getUniqueConstraints().size()); - - - tableGenerator.moveUniqueConstraint(2, 0); - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - tableGenerator.moveUniqueConstraint(0, 1); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - TableGenerator tableGenerator = getEntityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = getXmlEntityMappings().getTableGenerators().get(0); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableGeneratorResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableGeneratorResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(1); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(1); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(0); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.attributes().next(); - IdMapping virtualIdMapping = (IdMapping) virtualAttribute.getMapping(); - - JavaIdMapping javaIdMapping = (JavaIdMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - JavaTableGenerator javaTableGenerator = javaIdMapping.getGeneratorContainer().addTableGenerator(); - javaTableGenerator.setName("TABLE_GENERATOR"); - - TableGenerator tableGenerator = virtualIdMapping.getGeneratorContainer().getTableGenerator(); - Iterator uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - - - javaTableGenerator.addUniqueConstraint().addColumnName("FOO"); - javaTableGenerator.addUniqueConstraint().addColumnName("BAR"); - javaTableGenerator.addUniqueConstraint().addColumnName("BAZ"); - - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - OrmIdMapping ormIdMapping = (OrmIdMapping) virtualAttribute.convertToSpecified().getMapping(); - - OrmTableGenerator ormTableGenerator2 = ormIdMapping.getGeneratorContainer().addTableGenerator(); - ormTableGenerator2.setName("TABLE_GENERATOR"); - - assertEquals(0, ormTableGenerator2.getUniqueConstraintsSize()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java deleted file mode 100644 index 6e75cd8bf6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java +++ /dev/null @@ -1,827 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmTableTests extends ContextModelTestCase -{ - public OrmTableTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private ICompilationUnit createAbstractTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - sb.append("abstract"); - } - }); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - - //set name in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setName("FOO"); - assertEquals("FOO", ormTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getTable().getName()); - - //set name to null in the resource model - entityResource.getTable().setName(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable().getName()); - - entityResource.getTable().setName("FOO"); - assertEquals("FOO", ormTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getTable().getName()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmTable ormTable = ((OrmEntity) ormPersistentType.getMapping()).getTable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - - //set name in the context model, verify resource model modified - ormTable.setSpecifiedName("foo"); - assertEquals("foo", ormTable.getSpecifiedName()); - assertEquals("foo", entityResource.getTable().getName()); - - //set name to null in the context model - ormTable.setSpecifiedName(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getJavaTypeMapping().getTable().setSpecifiedName("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameNoJava() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameFromEntityName() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - ormEntity.setSpecifiedName("foo"); - - assertEquals("foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedName(null); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getJavaTypeMapping().setSpecifiedName("foo"); - assertEquals("foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); - - parentXmlEntity.getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - - //set schema in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setSchema("FOO"); - assertEquals("FOO", ormTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getTable().getSchema()); - - //set Schema to null in the resource model - entityResource.getTable().setSchema(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable().getSchema()); - - entityResource.getTable().setSchema("FOO"); - assertEquals("FOO", ormTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getTable().getSchema()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultSchemaFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getJavaTypeMapping().getTable().setSpecifiedSchema("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultSchema()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getTable().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getTable().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertNull(ormEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaNoJava() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertNull(childXmlEntity.getTable().getDefaultSchema()); - - parentXmlEntity.getTable().setSpecifiedSchema("FOO"); - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultSchema()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertNull(childXmlEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", ormEntity.getTable().getDefaultSchema()); - - getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getJavaTypeMapping().getTable().setSpecifiedSchema("JAVA_SCHEMA"); - assertEquals("JAVA_SCHEMA", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName("BLAH"); - //xml entity now has a table element so default schema is not taken from java - assertEquals("BAR", ormEntity.getTable().getDefaultSchema()); - - - getEntityMappings().setSpecifiedSchema(null); - assertEquals("FOO", ormEntity.getTable().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName(null); - assertEquals("JAVA_SCHEMA", ormEntity.getTable().getDefaultSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - - //set Schema in the context model, verify resource model modified - ormTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormTable.getSpecifiedSchema()); - assertEquals("foo", entityResource.getTable().getSchema()); - - //set Schema to null in the context model - ormTable.setSpecifiedSchema(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - - //set Catalog in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setCatalog("FOO"); - assertEquals("FOO", ormTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getTable().getCatalog()); - - //set Catalog to null in the resource model - entityResource.getTable().setCatalog(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable().getCatalog()); - - entityResource.getTable().setCatalog("FOO"); - assertEquals("FOO", ormTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getTable().getCatalog()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - - //set Catalog in the context model, verify resource model modified - ormTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormTable.getSpecifiedCatalog()); - assertEquals("foo", entityResource.getTable().getCatalog()); - - //set Catalog to null in the context model - ormTable.setSpecifiedCatalog(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultCatalogFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getJavaTypeMapping().getTable().setSpecifiedCatalog("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertNull(ormEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogNoJava() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertNull(childXmlEntity.getTable().getDefaultCatalog()); - - parentXmlEntity.getTable().setSpecifiedCatalog("FOO"); - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultCatalog()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertNull(childXmlEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", ormEntity.getTable().getDefaultCatalog()); - - getEntityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getJavaTypeMapping().getTable().setSpecifiedCatalog("JAVA_CATALOG"); - assertEquals("JAVA_CATALOG", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName("BLAH"); - //xml entity now has a table element so default schema is not taken from java - assertEquals("BAR", ormEntity.getTable().getDefaultCatalog()); - - - getEntityMappings().setSpecifiedCatalog(null); - assertEquals("FOO", ormEntity.getTable().getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName(null); - assertEquals("JAVA_CATALOG", ormEntity.getTable().getDefaultCatalog()); -} - -// -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// Entity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals("Foo", ormEntity.getName()); -// -// //set class in the resource model, verify context model updated -// entityResource.setClassName("com.Bar"); -// assertEquals("Bar", ormEntity.getName()); -// -// entityResource.setName("Baz"); -// assertEquals("Baz", ormEntity.getName()); -// -// //set class to null in the resource model -// entityResource.setClassName(null); -// assertEquals("Baz", ormEntity.getName()); -// -// entityResource.setName(null); -// assertNull(ormEntity.getName()); -// } - - public void testUniqueConstraints() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - ListIterator uniqueConstraints = ormEntity.getTable().uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormEntity.getTable().uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - assertEquals(0, ormEntity.getTable().uniqueConstraintsSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormEntity.getTable().uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(0).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - ListIterator uniqueConstraints = tableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - ListIterator uniqueConstraints = tableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - assertEquals(3, tableResource.getUniqueConstraints().size()); - - table.removeUniqueConstraint(1); - - ListIterator uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(1); - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(0); - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - assertEquals(3, tableResource.getUniqueConstraints().size()); - - - table.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - table.moveUniqueConstraint(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - tableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(0); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - -//TODO not yet supporting unique constriants from java -// public void testUniqueConstraintsFromJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); -// -// ListIterator uniqueConstraints = ormEntity.getTable().uniqueConstraints(); -// assertFalse(uniqueConstraints.hasNext()); -// -// JavaEntity javaEntity = (JavaEntity) ormPersistentType.getJavaPersistentType().getMapping(); -// javaEntity.getTable().addUniqueConstraint(0).addColumnName(0, "FOO"); -// javaEntity.getTable().addUniqueConstraint(1).addColumnName(0, "BAR"); -// javaEntity.getTable().addUniqueConstraint(2).addColumnName(0, "BAZ"); -// -// -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertNull(entityResource.getTable()); -// -// uniqueConstraints = ormEntity.getTable().uniqueConstraints(); -// assertTrue(uniqueConstraints.hasNext()); -// assertEquals("FOO", uniqueConstraints.next().columnNames().next()); -// assertEquals("BAR", uniqueConstraints.next().columnNames().next()); -// assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); -// assertFalse(uniqueConstraints.hasNext()); -// -// entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); -// assertEquals(0, ormEntity.getTable().uniqueConstraintsSize()); -// } - - public void testAbstractEntityGetDefaultNameTablePerClassInheritance() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - OrmPersistentType abstractPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity abstractEntity = (OrmEntity) abstractPersistentType.getMapping(); - OrmPersistentType concretePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity concreteEntity = (OrmEntity) concretePersistentType.getMapping(); - - assertEquals(null, abstractEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy()); - - - assertEquals(null, abstractEntity.getTable().getDefaultName()); - assertEquals(null, abstractEntity.getTable().getDefaultCatalog()); - assertEquals(null, abstractEntity.getTable().getDefaultSchema()); - - assertEquals("AnnotationTestTypeChild", concreteEntity.getTable().getDefaultName()); - assertEquals(null, concreteEntity.getTable().getDefaultCatalog()); - assertEquals(null, concreteEntity.getTable().getDefaultSchema()); - - //meta-data complete true, inheritance strategy no single-table - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(TYPE_NAME, abstractEntity.getTable().getDefaultName()); - assertEquals(null, abstractEntity.getTable().getDefaultCatalog()); - assertEquals(null, abstractEntity.getTable().getDefaultSchema()); - - assertEquals("AnnotationTestType", concreteEntity.getTable().getDefaultName()); - assertEquals(null, concreteEntity.getTable().getDefaultCatalog()); - assertEquals(null, concreteEntity.getTable().getDefaultSchema()); - - - //set inheritance strategy to table-per-class in orm.xml - abstractEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - assertEquals(null, abstractEntity.getTable().getDefaultName()); - assertEquals(null, abstractEntity.getTable().getDefaultCatalog()); - assertEquals(null, abstractEntity.getTable().getDefaultSchema()); - - assertEquals("AnnotationTestTypeChild", concreteEntity.getTable().getDefaultName()); - assertEquals(null, concreteEntity.getTable().getDefaultCatalog()); - assertEquals(null, concreteEntity.getTable().getDefaultSchema()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java deleted file mode 100644 index 2a2e4292db..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java +++ /dev/null @@ -1,305 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmTransientMappingTests extends ContextModelTestCase -{ - public OrmTransientMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityTransientMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TRANSIENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient"); - } - }); - } - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientMapping"); - OrmTransientMapping xmlTransientnMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - XmlTransient transientResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getTransients().get(0); - - assertEquals("transientMapping", xmlTransientnMapping.getName()); - assertEquals("transientMapping", transientResource.getName()); - - //set name in the resource model, verify context model updated - transientResource.setName("newName"); - assertEquals("newName", xmlTransientnMapping.getName()); - assertEquals("newName", transientResource.getName()); - - //set name to null in the resource model - transientResource.setName(null); - assertNull(xmlTransientnMapping.getName()); - assertNull(transientResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientMapping"); - OrmTransientMapping xmlTransientnMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - XmlTransient transientResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getTransients().get(0); - - assertEquals("transientMapping", xmlTransientnMapping.getName()); - assertEquals("transientMapping", transientResource.getName()); - - //set name in the context model, verify resource model updated - xmlTransientnMapping.setName("newName"); - assertEquals("newName", xmlTransientnMapping.getName()); - assertEquals("newName", transientResource.getName()); - - //set name to null in the context model - xmlTransientnMapping.setName(null); - assertNull(xmlTransientnMapping.getName()); - assertNull(transientResource.getName()); - } - - - public void testTransientMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityTransientMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormTransientMapping.getName()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", transientMapping.getName()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertTrue(ormPersistentAttribute.isVirtual()); - - ormPersistentAttribute.convertToSpecified(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormTransientMapping.getName()); - assertFalse(ormPersistentAttribute.isVirtual()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityTransientMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormTransientMapping.getName()); - } - - public void testTransientMorphToIdMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToVersionMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToTransientMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToEmbeddedMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToEmbeddedIdMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToOneToOneMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToOneToManyMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToManyToOneMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToManyToManyMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java deleted file mode 100644 index 218d27bb5a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java +++ /dev/null @@ -1,489 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmVersionMappingTests extends ContextModelTestCase -{ - public OrmVersionMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityVersionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION, JPA.COLUMN, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertEquals("versionMapping", ormVersionMapping.getName()); - assertEquals("versionMapping", versionResource.getName()); - - //set name in the resource model, verify context model updated - versionResource.setName("newName"); - assertEquals("newName", ormVersionMapping.getName()); - assertEquals("newName", versionResource.getName()); - - //set name to null in the resource model - versionResource.setName(null); - assertNull(ormVersionMapping.getName()); - assertNull(versionResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertEquals("versionMapping", ormVersionMapping.getName()); - assertEquals("versionMapping", versionResource.getName()); - - //set name in the context model, verify resource model updated - ormVersionMapping.setName("newName"); - assertEquals("newName", ormVersionMapping.getName()); - assertEquals("newName", versionResource.getName()); - - //set name to null in the context model - ormVersionMapping.setName(null); - assertNull(ormVersionMapping.getName()); - assertNull(versionResource.getName()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertNull(ormVersionMapping.getConverter().getType()); - assertNull(versionResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, versionResource.getTemporal()); - - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, versionResource.getTemporal()); - - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, versionResource.getTemporal()); - - //set temporal to null in the resource model - versionResource.setTemporal(null); - assertNull(ormVersionMapping.getConverter().getType()); - assertNull(versionResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertNull(ormVersionMapping.getConverter().getType()); - assertNull(versionResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormVersionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) ormVersionMapping.getConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, versionResource.getTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - - ((TemporalConverter) ormVersionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, versionResource.getTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - - ((TemporalConverter) ormVersionMapping.getConverter()).setTemporalType(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, versionResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - - //set temporal to null in the context model - ormVersionMapping.setConverter(null); - assertNull(versionResource.getTemporal()); - assertNull(ormVersionMapping.getConverter().getType()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - public void testVersionMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityVersionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getConverter().getType()); - - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(255, ormColumn.getDefaultLength()); - assertEquals(0, ormColumn.getDefaultPrecision()); - assertEquals(0, ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", versionMapping.getName()); - assertEquals(TemporalConverter.class, versionMapping.getConverter().getType()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) versionMapping.getConverter()).getTemporalType()); - - Column column = versionMapping.getColumn(); - assertEquals("MY_COLUMN", column.getSpecifiedName()); - assertEquals(Boolean.TRUE, column.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, column.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, column.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, column.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", column.getColumnDefinition()); - assertEquals("MY_TABLE", column.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), column.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), column.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), column.getSpecifiedScale()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertTrue(ormPersistentAttribute.isVirtual()); - - ormPersistentAttribute.convertToSpecified(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.getAttributeNamed("id"); - - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormVersionMapping.getName()); - assertFalse(ormPersistentAttribute.isVirtual()); - assertNull(ormVersionMapping.getConverter().getType()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertEquals("id", ormColumn.getName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getTable()); - assertEquals(255, ormColumn.getLength()); - assertEquals(0, ormColumn.getPrecision()); - assertEquals(0, ormColumn.getScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityVersionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getConverter().getType()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(255, ormColumn.getDefaultLength()); - assertEquals(0, ormColumn.getDefaultPrecision()); - assertEquals(0, ormColumn.getDefaultScale()); - } - - public void testVersionMorphToIdMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testVersionMorphToBasicMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testVersionMorphToTransientMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToEmbeddedMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToEmbeddedIdMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToOneToOneMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToOneToManyMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToManyToOneMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToManyToManyMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java deleted file mode 100644 index e9ba77792e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class OrmXmlTests extends ContextModelTestCase -{ - public OrmXmlTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - getXmlPersistenceUnit().setName("foo"); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - protected OrmXml getOrmXml() { - return (OrmXml) getPersistenceUnit().mappingFileRefs().next().getMappingFile(); - } - - public void testUpdateAddEntityMappings() throws Exception { - assertEquals(2, getJpaProject().jpaFilesSize()); - JpaXmlResource ormResource = getOrmXmlResource(); - ormResource.getContents().clear(); - ormResource.save(null); - - //the ContentType of the orm.xml file is no longer orm, so the jpa file is removed - assertNull(getOrmXml()); - assertEquals(1, getJpaProject().jpaFilesSize()); //should only be the persistence.xml file - - XmlEntityMappings xmlEntityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - xmlEntityMappings.setVersion("1.0"); - ormResource.getContents().add(xmlEntityMappings); - ormResource.save(null); - - assertNotNull(getOrmXml().getRoot()); - assertEquals(2, getJpaProject().jpaFilesSize()); - } - - public void testUpdateRemoveEntityMappings() throws Exception { - JpaXmlResource ormResource = getOrmXmlResource(); - - assertNotNull(getOrmXml().getRoot()); - - ormResource.getContents().clear(); - assertNull(getOrmXml()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java deleted file mode 100644 index 109a5c7a04..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class PersistenceUnitDefaultsTests extends ContextModelTestCase -{ - public PersistenceUnitDefaultsTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - protected OrmPersistenceUnitDefaults getPersistenceUnitDefaults() { - return getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults(); - } - - public void testIsAllFeaturesUnset() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - XmlPersistenceUnitMetadata persistenceUnitMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - getXmlEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isUnset()); - - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaultsResource = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - persistenceUnitMetadata.setPersistenceUnitDefaults(persistenceUnitDefaultsResource); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(true); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(false); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setSchema("asdf"); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setSchema(null); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCatalog("asdf"); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCatalog(null); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setAccess(null); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - } - - public void testUpdateSchema() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifySchema2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCatalog() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCatalog2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCascadePersist() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the resource model, persistence-unit-defaults tag not removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCascadePersist2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - - public void testUpdateAccess() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set access in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyAccess2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = getPersistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java deleted file mode 100644 index c3c6330d06..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -public class PersistenceUnitMetadataTests extends ContextModelTestCase -{ - public PersistenceUnitMetadataTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - protected OrmPersistenceUnitMetadata persistenceUnitMetadata() { - return getEntityMappings().getPersistenceUnitMetadata(); - } - - public void testIsAllFeaturesUnset() throws Exception { - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata persistenceUnitMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - getXmlEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertFalse(persistenceUnitMetadata.isUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertTrue(persistenceUnitMetadata.isUnset()); - - persistenceUnitMetadata.setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - assertFalse(persistenceUnitMetadata.isUnset()); - } - - public void testUpdateXmlMappingMetadataComplete() throws Exception { - OrmPersistenceUnitMetadata persistenceUnitMetadata = getEntityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } - - public void testModifyXmlMappingMetadataComplete() throws Exception { - OrmPersistenceUnitMetadata persistenceUnitMetadata = getEntityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyXmlMappingMetadataComplete2() throws Exception { - OrmPersistenceUnitMetadata persistenceUnitMetadata = getEntityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - //set another element on the persistence-unit-metadata element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/ClassRefTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/ClassRefTests.java deleted file mode 100644 index ddb0bebd48..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/ClassRefTests.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class ClassRefTests extends ContextModelTestCase -{ - public ClassRefTests(String name) { - super(name); - } - - public void testUpdateClassName() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add class ref - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - ClassRef classRef = persistenceUnit.specifiedClassRefs().next(); - - // test that class names are initially equal - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set xml class name to different name, test equality - xmlClassRef.setJavaClass("com.bar.Foo"); - - classRef = persistenceUnit.specifiedClassRefs().next(); - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set class name to empty string, test equality - xmlClassRef.setJavaClass(""); - - classRef = persistenceUnit.specifiedClassRefs().next(); - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set name back to non empty string, test equality - xmlClassRef.setJavaClass("com.foo.Bar"); - - classRef = persistenceUnit.specifiedClassRefs().next(); - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - } - - public void testModifyClassName() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add class ref - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - ClassRef classRef = persistenceUnit.specifiedClassRefs().next(); - - // test that class names are initially equal - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set context class name to different name, test equality - classRef.setClassName("com.bar.Foo"); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set class name to empty string, test equality - classRef.setClassName(""); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set class name to null, test equality - classRef.setClassName(null); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set name back to non-null, test equality - classRef.setClassName("com.foo.Bar"); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - } - - - public void testGetPersistentType() throws Exception { - createTestType(); - - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass(FULLY_QUALIFIED_TYPE_NAME); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - ClassRef classRef = getSpecifiedClassRef(); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, classRef.getJavaPersistentType().getName()); - - //test setting to a class that does not exist in the project - xmlClassRef.setJavaClass("com.foo.Bar"); - - classRef = getSpecifiedClassRef(); - assertNull(classRef.getJavaPersistentType()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java deleted file mode 100644 index 3975ab900f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCorePersistenceContextModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptCorePersistenceContextModelTests.class.getPackage().getName()); - suite.addTestSuite(RootContextNodeTests.class); - suite.addTestSuite(PersistenceXmlTests.class); - suite.addTestSuite(PersistenceTests.class); - suite.addTestSuite(PersistenceUnitTests.class); - suite.addTestSuite(MappingFileRefTests.class); - suite.addTestSuite(ClassRefTests.class); - return suite; - } - - private JptCorePersistenceContextModelTests() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/MappingFileRefTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/MappingFileRefTests.java deleted file mode 100644 index 72f7b6ba84..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/MappingFileRefTests.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class MappingFileRefTests extends ContextModelTestCase -{ - public MappingFileRefTests(String name) { - super(name); - } - - protected MappingFileRef mappingFileRef() { - return getPersistenceUnit().mappingFileRefs().next(); - } - - public void testUpdateFileName() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add mapping file ref - XmlMappingFileRef xmlFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlFileRef.setFileName("foo.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlFileRef); - MappingFileRef fileRef = persistenceUnit.specifiedMappingFileRefs().next(); - - // test that file names are initially equal - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set xml to different file name, test equality - xmlFileRef.setFileName("bar.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to empty string, test equality - xmlFileRef.setFileName(""); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to null, test equality - xmlFileRef.setFileName(null); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name back to non-null, test equality - xmlFileRef.setFileName("baz.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - } - - public void testModifyFileName() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add mapping file ref - XmlMappingFileRef xmlFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlFileRef.setFileName("foo.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlFileRef); - MappingFileRef fileRef = persistenceUnit.specifiedMappingFileRefs().next(); - - // test that file names are initially equal - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set context to different file name, test equality - fileRef.setFileName("bar.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to empty string, test equality - fileRef.setFileName(""); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to null, test equality - fileRef.setFileName(null); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name back to non-null, test equality - fileRef.setFileName("baz.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceTests.java deleted file mode 100644 index 5fb73d8693..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceTests.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class PersistenceTests extends ContextModelTestCase -{ - public PersistenceTests(String name) { - super(name); - } - - protected Persistence persistence() { - return getRootContextNode().getPersistenceXml().getPersistence(); - } - - public void testUpdateAddPersistenceUnit() throws Exception { - XmlPersistence xmlPersistence = getXmlPersistence(); - Persistence persistence = getRootContextNode().getPersistenceXml().getPersistence(); - - // clear xml persistence units, test that it's clear in context - xmlPersistence.getPersistenceUnits().clear(); - - assertEquals(0, persistence.persistenceUnitsSize()); - - // add xml persistence unit, test that it's added to context - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(1, persistence.persistenceUnitsSize()); - - // add another, test that it *isn't* add to context - xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test2"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(1, persistence.persistenceUnitsSize()); - } - - public void testModifyAddPersistencUnit() { - XmlPersistence xmlPersistence = getXmlPersistence(); - Persistence persistence = persistence(); - - // clear xml persistence units, test that it's clear in context - xmlPersistence.getPersistenceUnits().clear(); - assertEquals(0, persistence.persistenceUnitsSize()); - - // add persistence unit, test that it's added to resource - persistence.addPersistenceUnit(); - - assertEquals(1, persistence.persistenceUnitsSize()); - - // add another, test that we get an exception - boolean exception = false; - try { - persistence.addPersistenceUnit(); - } - catch (IllegalStateException e) { - exception = true; - } - - assertTrue(exception); - } - - public void testUpdateRemovePersistenceUnit() throws Exception { - XmlPersistence xmlPersistence = getXmlPersistence(); - Persistence persistence = getRootContextNode().getPersistenceXml().getPersistence(); - - // add a persistence unit and test that there are two existing xml and - // one context persistence unit - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(2, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove persistence unit from xml, test that context remains unchanged - xmlPersistenceUnit = xmlPersistence.getPersistenceUnits().get(0); - xmlPersistence.getPersistenceUnits().remove(xmlPersistenceUnit); - - assertEquals(1, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove another one from xml, text that it's now removed from context - xmlPersistenceUnit = xmlPersistence.getPersistenceUnits().get(0); - xmlPersistence.getPersistenceUnits().remove(xmlPersistenceUnit); - - assertEquals(0, xmlPersistence.getPersistenceUnits().size()); - assertEquals(0, persistence.persistenceUnitsSize()); - } - - public void testModifyRemovePersistenceUnit() { - XmlPersistence xmlPersistence = getXmlPersistence(); - Persistence persistence = persistence(); - - // add a persistence unit and test that there are two existing xml and - // one context persistence unit - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(2, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove persistence unit, test that it's removed from resource and that - // a *new* persistence unit representing the previously unrepresented one - // is present - persistence.removePersistenceUnit(0); - - assertEquals(1, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove new persistence unit, test that it's removed from resource and - // context - persistence.removePersistenceUnit(0); - - assertEquals(0, xmlPersistence.getPersistenceUnits().size()); - assertEquals(0, persistence.persistenceUnitsSize()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java deleted file mode 100644 index 2451134b72..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTestCase.java +++ /dev/null @@ -1,361 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import java.util.Iterator; - -import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.model.event.ListEvent; -import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.ListValueModel; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnitProperties; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -/** - * PersistenceUnitTestCase - */ -@SuppressWarnings("nls") -public abstract class PersistenceUnitTestCase extends ContextModelTestCase -{ - protected PropertyChangeEvent propertyChangedEvent; - - protected int propertyChangedEventCount; - - protected int propertiesTotal; - - protected int modelPropertiesSizeOriginal; - - protected int modelPropertiesSize; - - // ********** constructors ********** - protected PersistenceUnitTestCase(String name) { - super(name); - } - - // ****** abstract methods ******* - protected abstract PersistenceUnitProperties getModel(); - - /** - * Initializes directly the PU properties before testing. Cannot use - * Property Holder to initialize because it is not created yet - */ - protected abstract void populatePu(); - - /** - * Gets the model's property identified by the given propertyName. - * - * @param propertyName - * name of property to get - * @throws Exception - */ - protected abstract Object getProperty(String propertyName) throws Exception; - - - /** - * Sets the model's property identified by the given propertyName. - * Used in verifySetProperty() - * - * @param propertyName - * name of property to be set - * @param newValue - * value of property - * @throws Exception - */ - protected abstract void setProperty(String propertyName, Object newValue) throws Exception; - - - // ****** convenience test methods ******* - - protected String getPropertyStringValueOf(Object value) { - return AbstractPersistenceUnitProperties.getPropertyStringValueOf(value); - } - - protected E getFirstElement(Iterator iterator) { - if(iterator.hasNext()) { - return iterator.next(); - } - return null; - } - - /** - * Put into persistenceUnit properties. Do not allows to put duplicate entry. - * - * @param key - - * PersistenceUnit property key - * @param value - - * property value - */ - protected void persistenceUnitSetProperty(String key, Object value) { - - this.persistenceUnitSetProperty( key, value, false); - } - - protected void persistenceUnitSetProperty(String key, Object value, boolean allowDuplicates) { - if (key == null) { - throw new IllegalArgumentException("PersistenceUnit property key cannot be null"); - } - if (value == null) - this.setNullProperty(key); - else - this.putProperty_(key, value, allowDuplicates); - } - - private void putProperty_(String puKey, Object value, boolean allowDuplicates) { - this.clearEvent(); - this.getPersistenceUnit().setProperty(puKey, this.getPropertyStringValueOf(value), allowDuplicates); - } - - protected void setNullProperty(String puKey) { - this.clearEvent(); - this.getPersistenceUnit().setProperty(puKey, 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 + ")"); - } - - public void throwUnsupportedOperationException(ListEvent e) { - throw new UnsupportedOperationException(e.getListName()); - } - - protected PropertyChangeListener buildPropertyChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - PersistenceUnitTestCase.this.propertyChangedEvent = event; - PersistenceUnitTestCase.this.propertyChangedEventCount++; - } - - @Override - public String toString() { - return "PersistenceUnit listener"; - } - }; - } - - /** - * Verify if the property exists in the pesistence.xml - */ - protected boolean propertyExists(String puPropertyName) { - return this.getPersistenceUnit().getProperty(puPropertyName) != null; - } - - protected boolean propertyValueEquals(String puPropertyName, String propertyValue) { - return this.getPersistenceUnit().getProperty(puPropertyName).getValue().equals(propertyValue); - } - - // ****** verify PersistenceUnit properties ******* - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyAAValue(Boolean expectedValue, Boolean subjectValue, PropertyValueModel aa, String persistenceXmlKey) { - assertEquals(expectedValue, subjectValue); - assertEquals(expectedValue, aa.getValue()); - if (expectedValue != null) { - assertTrue("PersistenceUnit property value not equals", this.propertyValueEquals(persistenceXmlKey, expectedValue.toString())); - } - } - - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected > void verifyAAValue(T expectedValue, T subjectValue, PropertyValueModel> aa, String puKey) { - assertEquals(expectedValue, subjectValue); - assertEquals(expectedValue, aa.getValue()); - if (expectedValue != null) { - assertTrue("PersistenceUnit property value not equals", this.propertyValueEquals(puKey, this.getPropertyStringValueOf(expectedValue))); - } - } - - /** - * Performs the following tests:
- * 1. verify total number of PersistenceUnit properties
- * 2. verify PU has the given propertyName
- * 3. verify listening to propertyListAdapter
- * 4. verify that the model can identify propertyName
- */ - protected void verifyInitialState(String propertyName, String puKey, ListValueModel propertyListAdapter) throws Exception { - assertEquals("Total not updated in populatePu(): ", propertyListAdapter.size(), this.propertiesTotal); - this.verifyPuHasProperty(puKey, "Property not added to populatePu()"); - this.verifyHasListeners(propertyListAdapter); - this.verifyHasListeners(this.getModel(), propertyName); - - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(puKey); - assertTrue("model.itemIsProperty() is false: ", this.getModel().itemIsProperty(property)); - assertEquals("propertyIdFor() not updated: ", propertyName, this.getModel().propertyIdOf(property)); - } - - /** - * Verifies that the persistence unit is populated, and that the model for - * the tested Property is initialized with the value from the persistence - * unit. - * @throws Exception - */ - protected void verifyModelInitialized(String puKey, Object expectedValue) throws Exception { - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(puKey); - assertTrue("model.itemIsProperty() is false: ", this.getModel().itemIsProperty(property)); - - assertTrue("PersistenceUnit not populated - populatedPu()", this.propertyValueEquals(puKey, this.getPropertyStringValueOf(expectedValue))); - String propertyName = this.getModel().propertyIdOf(property); - Object modelValue = this.getProperty(propertyName); - assertEquals( - "Model not initialized - model.initializeProperties() - modelValue = " + modelValue, - expectedValue, - modelValue); - } - - /** - * Performs the following operations with the property:
- * 1. verifies the initial state
- * 2. persistenceUnit putProperty
- * 3. adapter setProperty
- */ - protected void verifySetProperty(String puKey, Object testValue1, Object testValue2) throws Exception { - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(puKey); - String propertyName = this.getModel().propertyIdOf(property); - - // Replace - this.persistenceUnitSetProperty(puKey, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // Replace by setting model object - this.clearEvent(); - this.setProperty(propertyName, testValue1); - this.verifyPutProperty(propertyName, testValue1); - } - - /** - * Performs the following operations with the property:
- * 1. performs a remove on the PU
- * 2. performs a add with putProperty
- * 3. performs a replace with putProperty
- */ - protected void verifyAddRemoveProperty(String puKey, Object testValue1, Object testValue2) throws Exception { - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(puKey); - String propertyName = this.getModel().propertyIdOf(property); - - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.verifyPuHasProperty(puKey, "persistenceUnit.properties doesn't contains: "); - this.getPersistenceUnit().removeProperty(puKey); - assertNull(this.getPersistenceUnit().getProperty(puKey)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - this.verifyPutProperty(propertyName, null); - - // Add original CacheTypeDefault - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(puKey, testValue1); - this.verifyPutProperty(propertyName, testValue1); - - // Replace - this.persistenceUnitSetProperty(puKey, testValue2); - this.verifyPutProperty(propertyName, testValue2); - } - - /** - * Verifies the model's property identified by the given propertyName - * Used in verifySetProperty() and verifyAddRemoveProperty - * - * @param propertyName - * name of property to be verified - * @param expectedValue - * @throws Exception - */ - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - - this.verifyPutEvent(propertyName, this.getProperty(propertyName), expectedValue); - } - - /** - * Verifies the event of the put() action. - * - * @param propertyName - * name of property to be verified - * @param propertyValue - * value of property - * @param expectedValue - * @throws Exception - */ - protected void verifyPutEvent(String propertyName, Object propertyValue, Object expectedValue) { - - this.verifyEvent(propertyName); - this.verifyEventValue(propertyValue, expectedValue); - } - - /** - * Performs the following tests:
- * 1. verifies the new value of this.propertyChangedEvent
- * 2. verifies the given value
- */ - protected void verifyEventValue(Object value, Object expectedValue) { - // verify event value - assertEquals(expectedValue, this.propertyChangedEvent.getNewValue()); - assertEquals(expectedValue, value); - } - - /** - * Performs the following tests:
- * 1. verifies that an event is fired
- * 2. verifies that it is the correct event
- * 3. verifies that a single event is fired
- */ - 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.getPropertyName(), propertyName); - // verify event occurrence - assertTrue("No Event Received.", this.propertyChangedEventCount > 0); - assertTrue("Multiple Event Received (" + this.propertyChangedEventCount + ")", - this.propertyChangedEventCount < 2); - } - - protected void verifyHasNoListeners(ListValueModel listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - } - - protected void verifyHasListeners(ListValueModel listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - protected void verifyHasListeners(PersistenceUnitProperties model, String propertyName) throws Exception { - assertTrue("Listener not added in setUp() - " + propertyName, ((AbstractModel) model).hasAnyPropertyChangeListeners(propertyName)); - } - - protected void verifyHasListeners(PropertyValueModel pvm, String propertyName) throws Exception { - assertTrue(((AbstractModel) pvm).hasAnyPropertyChangeListeners(propertyName)); - } - - protected void verifyPuHasProperty(String puPropertyName, String msg) { - assertTrue(msg + " - " + puPropertyName, this.propertyExists(puPropertyName)); - } - - protected void verifyPuHasNotProperty(String puPropertyName, String msg) { - assertFalse(msg + " - " + puPropertyName, this.propertyExists(puPropertyName)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTests.java deleted file mode 100644 index df3297bf7e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTests.java +++ /dev/null @@ -1,1247 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.Tools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnitTransactionType; -import org.eclipse.jpt.core.resource.persistence.XmlProperties; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class PersistenceUnitTests extends ContextModelTestCase -{ - - protected static final String INNER_CLASS_NAME = "InnerAnnotationTestType"; - protected static final String FULLY_QUALIFIED_INNER_CLASS_NAME = PACKAGE_NAME + "." + TYPE_NAME + "." + INNER_CLASS_NAME; - - public static final String OTHER_TYPE_NAME = "OtherTestType"; - public static final String FULLY_QUALIFIED_OTHER_TYPE_NAME = PACKAGE_NAME + "." + OTHER_TYPE_NAME; - - - public PersistenceUnitTests(String name) { - super(name); - } - - public void testUpdateName() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that names are initially equal - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to different name, test equality - xmlPersistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to empty string, test equality - xmlPersistenceUnit.setName(""); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to null, test equality - xmlPersistenceUnit.setName(null); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name back to non-null, test equality - xmlPersistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - } - - public void testModifyName() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that names are initially equal - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to different name, test equality - persistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to empty string, test equality - persistenceUnit.setName(""); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to null, test equality - persistenceUnit.setName(null); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name back to non-null, test equality - persistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - } - - public void testUpdateTransactionType() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // 1 - initial value is default - assertNull(xmlPersistenceUnit.getTransactionType()); - assertNull(persistenceUnit.getSpecifiedTransactionType()); - - // 2 - set value, context changed - xmlPersistenceUnit.setTransactionType(XmlPersistenceUnitTransactionType.JTA); - - assertEquals(PersistenceUnitTransactionType.JTA, persistenceUnit.getSpecifiedTransactionType()); - - xmlPersistenceUnit.setTransactionType(XmlPersistenceUnitTransactionType.RESOURCE_LOCAL); - - assertEquals(PersistenceUnitTransactionType.RESOURCE_LOCAL, persistenceUnit.getSpecifiedTransactionType()); - - // 3 - unset value, context changed - xmlPersistenceUnit.setTransactionType(null); - - assertNull(persistenceUnit.getSpecifiedTransactionType()); - } - - public void testModifyTransactionType() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // 1 - initial value is default - assertNull(xmlPersistenceUnit.getTransactionType()); - assertNull(persistenceUnit.getSpecifiedTransactionType()); - - // 2 - set context value, resource changed - persistenceUnit.setSpecifiedTransactionType(PersistenceUnitTransactionType.JTA); - - assertEquals(XmlPersistenceUnitTransactionType.JTA, xmlPersistenceUnit.getTransactionType()); - - persistenceUnit.setSpecifiedTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL); - - assertEquals(XmlPersistenceUnitTransactionType.RESOURCE_LOCAL, xmlPersistenceUnit.getTransactionType()); - - // 3 - set context value to default, resource unset - persistenceUnit.setSpecifiedTransactionType(null); - - assertNull(persistenceUnit.getSpecifiedTransactionType()); - assertNull(xmlPersistenceUnit.getTransactionType()); - } - - public void testUpdateDescription() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that descriptions are initially equal - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to different description, test equality - xmlPersistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to empty string, test equality - xmlPersistenceUnit.setDescription(""); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to null, test equality - xmlPersistenceUnit.setDescription(null); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description back to non-null, test equality - xmlPersistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - } - - public void testModifyDescription() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that descriptions are initially equal - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to different description, test equality - persistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to empty string, test equality - persistenceUnit.setDescription(""); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to null, test equality - persistenceUnit.setDescription(null); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description back to non-null, test equality - persistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - } - - public void testUpdateProvider() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that providers are initially equal - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to different provider, test equality - xmlPersistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to empty string, test equality - xmlPersistenceUnit.setProvider(""); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to null, test equality - xmlPersistenceUnit.setProvider(null); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider back to non-null, test equality - xmlPersistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - } - - public void testModifyProvider() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that providers are initially equal - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to different provider, test equality - persistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to empty string, test equality - persistenceUnit.setProvider(""); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to null, test equality - persistenceUnit.setProvider(null); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider back to non-null, test equality - persistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - } - - public void testUpdateJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that jtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to different jtaDataSource, test equality - xmlPersistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to empty string, test equality - xmlPersistenceUnit.setJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to null, test equality - xmlPersistenceUnit.setJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource back to non-null, test equality - xmlPersistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - } - - public void testModifyJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that jtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to different jtaDataSource, test equality - persistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to empty string, test equality - persistenceUnit.setJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to null, test equality - persistenceUnit.setJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource back to non-null, test equality - persistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - } - - public void testUpdateNonJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that nonJtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to different nonJtaDataSource, test equality - xmlPersistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to empty string, test equality - xmlPersistenceUnit.setNonJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to null, test equality - xmlPersistenceUnit.setNonJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource back to non-null, test equality - xmlPersistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - } - - public void testModifyNonJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that nonJtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to different nonJtaDataSource, test equality - persistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to empty string, test equality - persistenceUnit.setNonJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to null, test equality - persistenceUnit.setNonJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource back to non-null, test equality - persistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - } - - public void testUpdateJarFileRefs1() { - // TODO - } - - public void testUpdateJarFileRefs2() { - // TODO - } - - public void testUpdateImpliedMappingFileRef1() throws Exception { - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that there is one initially - JpaXmlResource ormResource = getOrmXmlResource(); - assertTrue(ormResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - - // remove orm.xml - deleteResource(ormResource); - - assertFalse(ormResource.fileExists()); - assertNull(persistenceUnit.getImpliedMappingFileRef()); - } - - public void testUpdateImpliedMappingFileRef2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that there is one initially - JpaXmlResource ormResource = getOrmXmlResource(); - assertTrue(ormResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - - // add specified orm.xml - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("META-INF/orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(1, persistenceUnit.specifiedMappingFileRefsSize()); - - assertTrue(ormResource.fileExists()); - assertNull(persistenceUnit.getImpliedMappingFileRef()); - } - - public void testUpdateSpecifiedMappingFileRefs1() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals(0, persistenceUnit.specifiedMappingFileRefsSize()); - - // add mapping file ref, test that it's added to context - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(1, persistenceUnit.specifiedMappingFileRefsSize()); - - // add another ... - xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm2.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(2, persistenceUnit.specifiedMappingFileRefsSize()); - } - - public void testUpdateSpecifiedMappingFileRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two mapping file refs and test that there are two existing in xml and context - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm2.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(xmlPersistenceUnit.getMappingFiles().size(), 2); - assertEquals(2, persistenceUnit.specifiedMappingFileRefsSize()); - - // remove mapping file ref from xml, test that it's removed from context - xmlMappingFileRef = xmlPersistenceUnit.getMappingFiles().get(0); - xmlPersistenceUnit.getMappingFiles().remove(xmlMappingFileRef); - - assertEquals(1, persistenceUnit.specifiedMappingFileRefsSize()); - - // remove another one ... - xmlMappingFileRef = xmlPersistenceUnit.getMappingFiles().get(0); - xmlPersistenceUnit.getMappingFiles().remove(xmlMappingFileRef); - - assertEquals(0, persistenceUnit.specifiedMappingFileRefsSize()); - } - - public void testModifySpecifiedMappingFileRefs1() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals(0, persistenceUnit.specifiedMappingFileRefsSize()); - - // add mapping file ref, test that it's added to resource - persistenceUnit.addSpecifiedMappingFileRef("foo"); - - assertEquals(1, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals("foo", xmlPersistenceUnit.getMappingFiles().get(0).getFileName()); - - // add another ... - persistenceUnit.addSpecifiedMappingFileRef("bar"); - assertEquals("foo", xmlPersistenceUnit.getMappingFiles().get(0).getFileName()); - assertEquals("bar", xmlPersistenceUnit.getMappingFiles().get(1).getFileName()); - - assertEquals(2, xmlPersistenceUnit.getMappingFiles().size()); - - // add another, testing order - persistenceUnit.addSpecifiedMappingFileRef(0, "baz"); - assertEquals(3, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals("baz", xmlPersistenceUnit.getMappingFiles().get(0).getFileName()); - assertEquals("foo", xmlPersistenceUnit.getMappingFiles().get(1).getFileName()); - assertEquals("bar", xmlPersistenceUnit.getMappingFiles().get(2).getFileName()); - } - - public void testModifySpecifiedMappingFileRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two mapping file refs and test that there are two existing in xml and context - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm2.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(2, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals(2, persistenceUnit.specifiedMappingFileRefsSize()); - - // remove mapping file ref from context, test that it's removed from xml - persistenceUnit.removeSpecifiedMappingFileRef(0); - - assertEquals(1, xmlPersistenceUnit.getMappingFiles().size()); - - // remove another one ... - persistenceUnit.removeSpecifiedMappingFileRef(0); - - assertEquals(0, xmlPersistenceUnit.getMappingFiles().size()); - } - - public void testUpdateClassRefs1() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getClasses().size()); - assertEquals(0, persistenceUnit.specifiedClassRefsSize()); - - // add mapping file ref, test that it's added to context - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(1, persistenceUnit.specifiedClassRefsSize()); - - // add another ... - xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Baz"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(2, persistenceUnit.specifiedClassRefsSize()); - } - - public void testUpdateClassRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two class refs and test that there are two existing in xml and context - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Baz"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(2, xmlPersistenceUnit.getClasses().size()); - assertEquals(2, persistenceUnit.specifiedClassRefsSize()); - - // remove class ref from xml, test that it's removed from context - xmlClassRef = xmlPersistenceUnit.getClasses().get(0); - xmlPersistenceUnit.getClasses().remove(xmlClassRef); - - assertEquals(1, persistenceUnit.specifiedClassRefsSize()); - - // remove another one ... - xmlClassRef = xmlPersistenceUnit.getClasses().get(0); - xmlPersistenceUnit.getClasses().remove(xmlClassRef); - - assertEquals(0, persistenceUnit.specifiedClassRefsSize()); - } - - public void testModifyClassRefs1() throws Exception { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getClasses().size()); - assertEquals(0, persistenceUnit.specifiedClassRefsSize()); - - // add class ref, test that it's added to context - persistenceUnit.addSpecifiedClassRef("Foo"); - - getPersistenceXmlResource().save(null); - assertEquals(1, xmlPersistenceUnit.getClasses().size()); - assertEquals("Foo", xmlPersistenceUnit.getClasses().get(0).getJavaClass()); - - // add another ... - persistenceUnit.addSpecifiedClassRef("Bar"); - - assertEquals(2, xmlPersistenceUnit.getClasses().size()); - assertEquals("Foo", xmlPersistenceUnit.getClasses().get(0).getJavaClass()); - assertEquals("Bar", xmlPersistenceUnit.getClasses().get(1).getJavaClass()); - - - persistenceUnit.addSpecifiedClassRef(0, "Baz"); - - assertEquals(3, xmlPersistenceUnit.getClasses().size()); - assertEquals("Baz", xmlPersistenceUnit.getClasses().get(0).getJavaClass()); - assertEquals("Foo", xmlPersistenceUnit.getClasses().get(1).getJavaClass()); - assertEquals("Bar", xmlPersistenceUnit.getClasses().get(2).getJavaClass()); - } - - public void testModifyClassRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two class refs and test that there are two existing in xml and context - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Baz"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(2, xmlPersistenceUnit.getClasses().size()); - assertEquals(2, persistenceUnit.specifiedClassRefsSize()); - - // remove class ref from context, test that it's removed from xml - persistenceUnit.removeSpecifiedClassRef(0); - - assertEquals(1, xmlPersistenceUnit.getClasses().size()); - - // remove another one ... - persistenceUnit.removeSpecifiedClassRef(0); - - assertEquals(0, xmlPersistenceUnit.getClasses().size()); - } - - public void testImpliedClassRefs1() throws Exception { - createTestEntityWithPersistentInnerClass(); - - getJpaProject().setDiscoversAnnotatedClasses(false); - getPersistenceUnit().setSpecifiedExcludeUnlistedClasses(Boolean.TRUE); - assertEquals(0, getPersistenceUnit().impliedClassRefsSize()); - - getJpaProject().setDiscoversAnnotatedClasses(true); - getPersistenceUnit().setSpecifiedExcludeUnlistedClasses(Boolean.FALSE); - assertEquals(2, getPersistenceUnit().impliedClassRefsSize()); - this.verifyVirtualClassRef(FULLY_QUALIFIED_TYPE_NAME); - this.verifyVirtualClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(1, getPersistenceUnit().impliedClassRefsSize()); - this.verifyVirtualClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, getPersistenceUnit().impliedClassRefsSize()); - this.verifyVirtualClassRef(FULLY_QUALIFIED_TYPE_NAME); - this.verifyVirtualClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(1, getPersistenceUnit().impliedClassRefsSize()); - this.verifyVirtualClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - - addXmlClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - assertEquals(0, getPersistenceUnit().impliedClassRefsSize()); - - removeXmlClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - assertEquals(1, getPersistenceUnit().impliedClassRefsSize()); - this.verifyVirtualClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_INNER_CLASS_NAME); - assertEquals(0, getPersistenceUnit().impliedClassRefsSize()); - } - - protected void verifyVirtualClassRef(String className) { - if (this.getVirtualClassRef(className) == null) { - fail("missing virtual class ref: " + className); - } - } - - protected ClassRef getVirtualClassRef(String className) { - for (Iterator stream = this.getPersistenceUnit().impliedClassRefs(); stream.hasNext(); ) { - ClassRef ref = stream.next(); - if (Tools.valuesAreEqual(ref.getClassName(), className)) { - return ref; - } - } - return null; - } - - public void testImpliedClassRefs2() throws Exception { - createTestEntity(); - getJpaProject().setDiscoversAnnotatedClasses(true); - JavaResourcePersistentType javaType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(1, CollectionTools.size(getPersistenceUnit().impliedClassRefs())); - - javaType.removeAnnotation(JPA.ENTITY); - getJpaProject().synchronizeContextModel(); - assertEquals(0, getPersistenceUnit().impliedClassRefsSize()); - - javaType.addAnnotation(JPA.EMBEDDABLE); - getJpaProject().synchronizeContextModel(); - assertEquals(1, getPersistenceUnit().impliedClassRefsSize()); - - javaType.removeAnnotation(JPA.EMBEDDABLE); - getJpaProject().synchronizeContextModel(); - assertEquals(0, getPersistenceUnit().impliedClassRefsSize()); - - javaType.addAnnotation(JPA.MAPPED_SUPERCLASS); - getJpaProject().synchronizeContextModel(); - assertEquals(1, getPersistenceUnit().impliedClassRefsSize()); - } - - public void testRenamePersistentTypeImpliedClassRefs() throws Exception { - getJavaProject().getJpaProject().setDiscoversAnnotatedClasses(true); - ICompilationUnit testType = createTestEntity(); - @SuppressWarnings("unused") - ICompilationUnit otherTestType = this.createTestOtherTypeEntity(); - - ClassRef testTypeClassRef = this.getVirtualClassRef(FULLY_QUALIFIED_TYPE_NAME); - ClassRef otherTestTypeClassRef = this.getVirtualClassRef(FULLY_QUALIFIED_OTHER_TYPE_NAME); - - assertNotNull(testTypeClassRef); - assertNotNull(otherTestTypeClassRef); - - JavaPersistentType testJavaPersistentType = testTypeClassRef.getJavaPersistentType(); - JavaPersistentType otherTestJavaPersistentType = otherTestTypeClassRef.getJavaPersistentType(); - - testType.findPrimaryType().rename("TestType2", false, null); - - testTypeClassRef = this.getVirtualClassRef("test.TestType2"); - otherTestTypeClassRef = this.getVirtualClassRef(FULLY_QUALIFIED_OTHER_TYPE_NAME); - - assertNotNull(testTypeClassRef); - assertNotNull(otherTestTypeClassRef); - - assertEquals(otherTestJavaPersistentType, otherTestTypeClassRef.getJavaPersistentType()); - assertNotSame(testJavaPersistentType, testTypeClassRef.getJavaPersistentType()); - } - - public void testUpdateExcludeUnlistedClasses() throws Exception { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // 1 - initial value is default - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.excludesUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 2 - set value, context changed - xmlPersistenceUnit.setExcludeUnlistedClasses(Boolean.TRUE); - - assertEquals(Boolean.TRUE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertTrue(persistenceUnit.excludesUnlistedClasses()); - assertEquals(Boolean.TRUE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - xmlPersistenceUnit.setExcludeUnlistedClasses(Boolean.FALSE); - - assertEquals(Boolean.FALSE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.excludesUnlistedClasses()); - assertEquals(Boolean.FALSE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 3 - unset value, context changed - xmlPersistenceUnit.setExcludeUnlistedClasses(null); - - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.excludesUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - } - - public void testModifyExcludeUnlistedClasses() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // 1 - initial value is default - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.excludesUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 2 - set value, resource changed - persistenceUnit.setSpecifiedExcludeUnlistedClasses(Boolean.TRUE); - - assertEquals(Boolean.TRUE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertTrue(persistenceUnit.excludesUnlistedClasses()); - assertEquals(Boolean.TRUE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - persistenceUnit.setSpecifiedExcludeUnlistedClasses(Boolean.FALSE); - - assertEquals(Boolean.FALSE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.excludesUnlistedClasses()); - assertEquals(Boolean.FALSE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 3 - set context to default, resource unset - persistenceUnit.setSpecifiedExcludeUnlistedClasses(null); - - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.excludesUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - } - - public void testUpdateProperties1() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test there are none initially - assertNull(xmlPersistenceUnit.getProperties()); - assertEquals(0, persistenceUnit.propertiesSize()); - - // add "properties", test that there's no real change to context - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - assertEquals(0, persistenceUnit.propertiesSize()); - - // add property, test that it's added to context - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("foo"); - xmlProperty.setValue("bar"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(1, persistenceUnit.propertiesSize()); - - // add another ... - xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("FOO"); - xmlProperty.setValue("BAR"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(2, persistenceUnit.propertiesSize()); - } - - public void testUpdateProperties2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two properties and test that there are two existing in xml and context - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("foo"); - xmlProperty.setValue("bar"); - xmlProperties.getProperties().add(xmlProperty); - xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("FOO"); - xmlProperty.setValue("BAR"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, persistenceUnit.propertiesSize()); - - // remove property from xml, test that it's removed from context - xmlProperty = xmlProperties.getProperties().get(0); - xmlProperties.getProperties().remove(xmlProperty); - - assertEquals(1, persistenceUnit.propertiesSize()); - - // remove another one ... - xmlProperty = xmlProperties.getProperties().get(0); - xmlProperties.getProperties().remove(xmlProperty); - - assertEquals(0, persistenceUnit.propertiesSize()); - } - - public void testModifyProperties1() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test there are none initially - assertNull(xmlPersistenceUnit.getProperties()); - assertEquals(0, persistenceUnit.propertiesSize()); - - // add property, test that it's added to resource - persistenceUnit.addProperty().setName("foo"); - - assertNotNull(xmlPersistenceUnit.getProperties()); - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals("foo", xmlPersistenceUnit.getProperties().getProperties().get(0).getName()); - - // add another ... - persistenceUnit.addProperty().setName("bar"); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals("foo", xmlPersistenceUnit.getProperties().getProperties().get(0).getName()); - assertEquals("bar", xmlPersistenceUnit.getProperties().getProperties().get(1).getName()); - - // add another testing order - persistenceUnit.addProperty(0).setName("baz"); - - assertEquals(3, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals("baz", xmlPersistenceUnit.getProperties().getProperties().get(0).getName()); - assertEquals("foo", xmlPersistenceUnit.getProperties().getProperties().get(1).getName()); - assertEquals("bar", xmlPersistenceUnit.getProperties().getProperties().get(2).getName()); - } - - public void testModifyProperties2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two properties and test that there are two existing in xml and context - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("foo"); - xmlProperty.setValue("bar"); - xmlProperties.getProperties().add(xmlProperty); - xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("FOO"); - xmlProperty.setValue("BAR"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, persistenceUnit.propertiesSize()); - - // remove property from context, test that it's removed from resource - persistenceUnit.removeProperty("foo"); - - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - - // remove another one. test that properties object is nulled - persistenceUnit.removeProperty("FOO", "BAR"); - - assertNull(xmlPersistenceUnit.getProperties()); - } - - public void testModifyProperties3() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two properties and test that there are two existing in xml and context - persistenceUnit.setProperty("foo", "bar", false); - persistenceUnit.setProperty("FOO", "BAR", false); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, persistenceUnit.propertiesSize()); - - // remove property from context, test that it's removed from resource - persistenceUnit.removeProperty("foo", "bar"); - - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - - // remove another one, test that properties object is nulled - persistenceUnit.removeProperty("FOO"); - - assertNull(xmlPersistenceUnit.getProperties()); - } - - public void testModifyProperties4() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two properties and test that there are two existing in xml and context - persistenceUnit.setProperty("foo", "bar", false); - persistenceUnit.setProperty("FOO", "BAR", false); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, persistenceUnit.propertiesSize()); - - // modify a property, test its value - persistenceUnit.setProperty("foo", "", false); - assertEquals("", persistenceUnit.getProperty("foo").getValue()); - - persistenceUnit.setProperty("foo", "BAR", false); - assertEquals("BAR", persistenceUnit.getProperty("foo").getValue()); - - // remove property from context, test that it's removed from resource - persistenceUnit.removeProperty("FOO"); - assertNull(persistenceUnit.getProperty("FOO")); - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - - // remove by setting value to null, test that properties object is nulled - persistenceUnit.setProperty("notExist", null, false); - assertNull(persistenceUnit.getProperty("notExist")); - - persistenceUnit.setProperty("foo", null, false); - assertNull(persistenceUnit.getProperty("foo")); - assertNull(xmlPersistenceUnit.getProperties()); - } - - public void testModifyProperties5() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // testing duplicate keys, add four properties and test that there are four existing in xml and context - persistenceUnit.setProperty("FOO", "BAR", false); - persistenceUnit.setProperty("foo", "bar 3", true); - persistenceUnit.setProperty("foo", "bar 2", true); - persistenceUnit.setProperty("foo", "bar 1", true); - - assertEquals(4, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(4, persistenceUnit.propertiesSize()); - - // remove a property, test that there are four existing in xml and context - persistenceUnit.removeProperty("foo", "bar 1"); - assertEquals(3, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(3, persistenceUnit.propertiesSize()); - } - - public void testAccessProperty() { - PersistenceUnit persistenceUnit = getPersistenceUnit(); - - // add two properties and try to access it. - persistenceUnit.setProperty("foo", "bar", false); - persistenceUnit.setProperty("FOO", "BAR", false); - - PersistenceUnit.Property property = persistenceUnit.getProperty("foo"); - assertNotNull(property); - assertEquals("bar", property.getValue()); - assertNotNull(persistenceUnit.getProperty("FOO")); - assertEquals("BAR", persistenceUnit.getProperty("FOO").getValue()); - assertNull(persistenceUnit.getProperty("notExist")); - } - - private PersistenceUnit.Property persistenceUnitFirstProperty() { - return getPersistenceUnit().properties().next(); - } - - public void testUpdatePropertyName() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - - // add property for testing - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperties.getProperties().add(xmlProperty); - - // test that names are initially equal - assertEquals(xmlProperty.getName(), persistenceUnitFirstProperty().getName()); - - // set name to different name, test equality - xmlProperty.setName("newName"); - - assertEquals(xmlProperty.getName(), persistenceUnitFirstProperty().getName()); - - // set name to empty string, test equality - xmlProperty.setName(""); - - assertEquals(xmlProperty.getName(), persistenceUnitFirstProperty().getName()); - - // set name back to non-null, test equality - xmlProperty.setName("newName"); - - assertEquals(xmlProperty.getName(), persistenceUnitFirstProperty().getName()); - } - - public void testUpdatePropertyValue() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - - // add property for testing - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperties.getProperties().add(xmlProperty); - - // test that values are initially equal - assertEquals(xmlProperty.getValue(), persistenceUnitFirstProperty().getValue()); - - // set value to different value, test equality - xmlProperty.setValue("newValue"); - - assertEquals(xmlProperty.getValue(), persistenceUnitFirstProperty().getValue()); - - // set value to empty string, test equality - xmlProperty.setValue(""); - - assertEquals(xmlProperty.getValue(), persistenceUnitFirstProperty().getValue()); - - // set value to null, test equality - xmlProperty.setValue(null); - - assertEquals(xmlProperty.getValue(), persistenceUnitFirstProperty().getValue()); - - // set value back to non-null, test equality - xmlProperty.setValue("newValue"); - - assertEquals(xmlProperty.getValue(), persistenceUnitFirstProperty().getValue()); - } - - public void testGetDefaultAccess() throws Exception { - addXmlMappingFileRef(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - createOrm2XmlFile(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - ListIterator mappingFileRefs = getPersistenceUnit().mappingFileRefs(); - OrmXml ormMappingFile = (OrmXml) mappingFileRefs.next().getMappingFile(); - OrmXml orm2MappingFile = (OrmXml) mappingFileRefs.next().getMappingFile(); - - assertEquals(null, persistenceUnit.getDefaultAccess()); - - ormMappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, persistenceUnit.getDefaultAccess()); - - ormMappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnit.getDefaultAccess()); - - ormMappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertFalse(ormMappingFile.getRoot().getPersistenceUnitMetadata().resourceExists()); - assertEquals(null, persistenceUnit.getDefaultAccess()); - - orm2MappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnit.getDefaultAccess()); - } - - public void testGetDefaultSchema() throws Exception { - addXmlMappingFileRef(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - createOrm2XmlFile(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - ListIterator mappingFileRefs = getPersistenceUnit().mappingFileRefs(); - OrmXml ormMappingFile = (OrmXml) mappingFileRefs.next().getMappingFile(); - OrmXml orm2MappingFile = (OrmXml) mappingFileRefs.next().getMappingFile(); - - assertEquals(null, persistenceUnit.getDefaultSchema()); - - ormMappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", persistenceUnit.getDefaultSchema()); - - ormMappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertFalse(ormMappingFile.getRoot().getPersistenceUnitMetadata().resourceExists()); - assertEquals(null, persistenceUnit.getDefaultSchema()); - - orm2MappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("BAR"); - assertEquals("BAR", persistenceUnit.getDefaultSchema()); - } - - public void testGetDefaultCatalog() throws Exception { - addXmlMappingFileRef(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - createOrm2XmlFile(); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - ListIterator mappingFileRefs = getPersistenceUnit().mappingFileRefs(); - OrmXml ormMappingFile = (OrmXml) mappingFileRefs.next().getMappingFile(); - OrmXml orm2MappingFile = (OrmXml) mappingFileRefs.next().getMappingFile(); - - assertEquals(null, persistenceUnit.getDefaultCatalog()); - - ormMappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", persistenceUnit.getDefaultCatalog()); - - ormMappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertFalse(ormMappingFile.getRoot().getPersistenceUnitMetadata().resourceExists()); - assertEquals(null, persistenceUnit.getDefaultCatalog()); - - orm2MappingFile.getRoot().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("BAR"); - assertEquals("BAR", persistenceUnit.getDefaultCatalog()); - } - - protected void createOrm2XmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, "orm2.xml"); - config.getDefaultOperation().execute(null, null); - - addXmlMappingFileRef("META-INF/orm2.xml"); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestOtherTypeEntity() throws Exception { - return this.createTestType(PACKAGE_NAME, OTHER_TYPE_NAME + ".java", OTHER_TYPE_NAME, new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createTestEntityWithPersistentInnerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append(" public static class " + INNER_CLASS_NAME + " {}").append(CR); - } - }); - } - - public void testPersistentType() throws Exception { - getJpaProject().setDiscoversAnnotatedClasses(false); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - createTestEntity(); - - //persistentType not listed in persistence.xml and discoverAnnotatedClasses is false - //still find the persistentType because of changes for bug 190317 - assertFalse(getJpaProject().discoversAnnotatedClasses()); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - //test persistentType not listed in persistence.xml, discover annotated classes set to true - getJpaProject().setDiscoversAnnotatedClasses(true); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - //test persistentType list as class in persistence.xml - getJpaProject().setDiscoversAnnotatedClasses(false); - XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - classRef.setJavaClass(FULLY_QUALIFIED_TYPE_NAME); - getXmlPersistenceUnit().getClasses().add(classRef); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - - //test persistentType from orm.xml file that is specified in the persistence.xml - addXmlMappingFileRef(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - assertNotNull(persistenceUnit.getPersistentType("model.Foo")); - assertEquals(ormPersistentType, persistenceUnit.getPersistentType("model.Foo")); - - //test persistentType from orm.xml file that is implied(not specified) in the persistence.xml - getXmlPersistenceUnit().getMappingFiles().remove(0); - assertNotNull(persistenceUnit.getPersistentType("model.Foo")); - } - -//TODO -// String getDefaultSchema(); -// String getDefaultCatalog(); -// AccessType getDefaultAccess(); -// boolean getDefaultCascadePersist(); - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceXmlTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceXmlTests.java deleted file mode 100644 index 5590ac256c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceXmlTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -@SuppressWarnings("nls") -public class PersistenceXmlTests extends ContextModelTestCase -{ - public PersistenceXmlTests(String name) { - super(name); - } - - protected PersistenceXml getPersistenceXml() { - return getRootContextNode().getPersistenceXml(); - } - - public void testUpdateAddPersistence() throws Exception { - assertEquals(2, getJpaProject().jpaFilesSize()); - JpaXmlResource prm = getPersistenceXmlResource(); - prm.getContents().clear(); - prm.save(null); - - //the ContentType of the persistence.xml file is no longer persistence, so the jpa file is removed - assertNull(getPersistenceXml()); - assertEquals(1, getJpaProject().jpaFilesSize()); //should only be the orm.xml file - - XmlPersistence xmlPersistence = PersistenceFactory.eINSTANCE.createXmlPersistence(); - xmlPersistence.setVersion("1.0"); - prm.getContents().add(xmlPersistence); - prm.save(null); - - assertNotNull(getPersistenceXml().getPersistence()); - assertEquals(2, getJpaProject().jpaFilesSize()); - } - - public void testUpdateRemovePersistence() throws Exception { - JpaXmlResource prm = getPersistenceXmlResource(); - - assertNotNull(getPersistenceXml().getPersistence()); - - prm.getContents().clear(); - assertNull(getPersistenceXml()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/RootContextNodeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/RootContextNodeTests.java deleted file mode 100644 index 5b753bbfff..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/RootContextNodeTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.internal.operations.PersistenceFileCreationDataModelProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class RootContextNodeTests extends ContextModelTestCase -{ - public RootContextNodeTests(String name) { - super(name); - } - - public void testUpdateAddPersistenceXml() throws Exception { - deleteResource(getPersistenceXmlResource()); - JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContextNode(); - - assertFalse(getPersistenceXmlResource().fileExists()); - assertNull(baseJpaContent.getPersistenceXml()); - - IDataModel config = - DataModelFactory.createDataModel(new PersistenceFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.getDefaultOperation().execute(null, null); - - assertNotNull(baseJpaContent.getPersistenceXml()); - } - - public void testUpdateRemovePersistenceXml() throws Exception { - JpaXmlResource pr = getPersistenceXmlResource(); - JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContextNode(); - - assertNotNull(baseJpaContent.getPersistenceXml()); - - deleteResource(pr); - - assertNull(baseJpaContent.getPersistenceXml()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java deleted file mode 100644 index 37cbcc66da..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/Generic2_0ContextModelTestCase.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context; - -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.platform.GenericPlatform; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public abstract class Generic2_0ContextModelTestCase extends ContextModelTestCase -{ - protected Generic2_0ContextModelTestCase(String name) { - super(name); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_2_0.getVersionString()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_2_0); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java deleted file mode 100644 index a35c3192ab..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/Generic2_0JavaContextModelTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class Generic2_0JavaContextModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(Generic2_0JavaContextModelTests.class.getPackage().getName()); - suite.addTestSuite(GenericJavaAssociationOverride2_0Tests.class); - suite.addTestSuite(GenericJavaCascade2_0Tests.class); - suite.addTestSuite(GenericJavaCollectionTable2_0Tests.class); - suite.addTestSuite(GenericJavaElementCollectionMapping2_0Tests.class); - suite.addTestSuite(GenericJavaEntity2_0Tests.class); - suite.addTestSuite(GenericJavaEmbeddedMapping2_0Tests.class); - suite.addTestSuite(GenericJavaManyToManyMapping2_0Tests.class); - suite.addTestSuite(GenericJavaManyToOneMapping2_0Tests.class); - suite.addTestSuite(GenericJavaOneToManyMapping2_0Tests.class); - suite.addTestSuite(GenericJavaOneToOneMapping2_0Tests.class); - suite.addTestSuite(GenericJavaPersistentAttribute2_0Tests.class); - suite.addTestSuite(GenericJavaPersistentType2_0Tests.class); - suite.addTestSuite(GenericJavaSequenceGenerator2_0Tests.class); - return suite; - } - - private Generic2_0JavaContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java deleted file mode 100644 index afb99689e3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaAssociationOverride2_0Tests.java +++ /dev/null @@ -1,580 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.VirtualJoinTable; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.core.jpa2.context.OverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaAssociationOverride2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE_NAME"; - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(CR); - sb.append(" private AnnotationTestTypeChild address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany"); - sb.append(CR); - sb.append(" private java.util.Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public GenericJavaAssociationOverride2_0Tests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next(); - javaAssociationOverride = ((VirtualAssociationOverride) javaAssociationOverride).convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - - //set name in the resource model, verify context model updated - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - //set name to null in the resource model - associationOverrideResource.setName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(0, overrideContainer.specifiedOverridesSize()); - assertNull(associationOverrideResource.getName()); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, overrideContainer.specifiedOverridesSize()); - javaAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - assertFalse(overrideContainer.specifiedOverrides().hasNext()); - assertFalse(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).hasNext()); - } - - public void testModifyName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - AssociationOverride specifiedAssociationOverride = virtualAssociationOverride.convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", specifiedAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - - //set name in the context model, verify resource model modified - specifiedAssociationOverride.setName("foo"); - assertEquals("foo", specifiedAssociationOverride.getName()); - assertEquals("foo", associationOverrideResource.getName()); - - //set name to null in the context model - specifiedAssociationOverride.setName(null); - assertNull(specifiedAssociationOverride.getName()); - associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - assertNull(associationOverrideResource.getName()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedOverride = overrideContainer.virtualOverrides().next().convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - JoinColumn joinColumn = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - ListIterator joinColumns = (ListIterator) joiningStrategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = (ListIterator) joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next().convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = javaAssociationOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(3, associationOverrideResource.joinColumnsSize()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, associationOverrideResource.joinColumnsSize()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, associationOverrideResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next().convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = javaAssociationOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = (ListIterator) joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = (ListIterator) joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaVirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - JavaAssociationOverride specifiedAssociationOverride = virtualAssociationOverride.convertToSpecified(); - JavaJoinColumnRelationshipStrategy joiningStrategy = specifiedAssociationOverride.getRelationship().getJoinColumnStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - JoinColumn joinColumn = joinColumns.next(); - assertEquals("address_id", joinColumn.getSpecifiedName()); - assertEquals("id", joinColumn.getSpecifiedReferencedColumnName()); - - associationOverrideResource.addJoinColumn(0); - associationOverrideResource.addJoinColumn(1); - associationOverrideResource.addJoinColumn(2); - - associationOverrideResource.joinColumnAt(0).setName("FOO"); - associationOverrideResource.joinColumnAt(1).setName("BAR"); - associationOverrideResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("address_id", joinColumns.next().getName()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joiningStrategy.specifiedJoinColumns().hasNext()); - } - - public void testGetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals("FOO", specifiedAssociationOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - specifiedAssociationOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("FOO", associationOverrideResource.getName()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", associationOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next(); - assertTrue(associationOverride.isVirtual()); - } - - - public void testSetJoinTableName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next(); - javaAssociationOverride = ((VirtualAssociationOverride) javaAssociationOverride).convertToSpecified(); - ((OverrideRelationship2_0) javaAssociationOverride.getRelationship()).setStrategyToJoinTable(); - JoinTableRelationshipStrategy joiningStrategy = ((OverrideRelationship2_0) javaAssociationOverride.getRelationship()).getJoinTableStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverride2_0Annotation associationOverrideResource = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - JoinTable joinTable = joiningStrategy.getJoinTable(); - joinTable.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideResource.getJoinTable().getName()); - } - - public void testUpdateJoinTable() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next(); - javaAssociationOverride = ((VirtualAssociationOverride) javaAssociationOverride).convertToSpecified(); - ((OverrideRelationship2_0) javaAssociationOverride.getRelationship()).setStrategyToJoinTable(); - JoinTableRelationshipStrategy joiningStrategy = ((OverrideRelationship2_0) javaAssociationOverride.getRelationship()).getJoinTableStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverride2_0Annotation associationOverrideResource = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.getJoinTable().setName("MY_JOIN_TABLE"); - getJpaProject().synchronizeContextModel(); - assertEquals("MY_JOIN_TABLE", joiningStrategy.getJoinTable().getSpecifiedName()); - - associationOverrideResource.getJoinTable().addJoinColumn(0); - associationOverrideResource.getJoinTable().addJoinColumn(1); - associationOverrideResource.getJoinTable().addJoinColumn(2); - - associationOverrideResource.getJoinTable().joinColumnAt(0).setName("FOO"); - associationOverrideResource.getJoinTable().joinColumnAt(1).setName("BAR"); - associationOverrideResource.getJoinTable().joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator joinColumns = (ListIterator) joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = (ListIterator) joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.getJoinTable().removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joiningStrategy.getJoinTable().specifiedJoinColumns().hasNext()); - } - - public void testDefaultJoinTableName() throws Exception { - createTestMappedSuperclassManyToMany(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ReadOnlyAssociationOverride javaAssociationOverride = overrideContainer.virtualOverrides().next(); - VirtualOverrideRelationship2_0 rel = (VirtualOverrideRelationship2_0) javaAssociationOverride.getRelationship(); - VirtualJoinTable joinTable = rel.getJoinTableStrategy().getJoinTable(); - - assertEquals("AnnotationTestTypeChild_AnnotationTestTypeChild", joinTable.getName()); - - - getJavaEntity().getTable().setSpecifiedName("FOO"); - assertEquals("FOO_FOO", joinTable.getName()); - - PersistentType mappedSuperclass = getJavaEntity().getPersistentType().getSuperPersistentType(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) mappedSuperclass.getAttributeNamed("address").getMapping(); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("BAR"); - - assertEquals("BAR", joinTable.getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java deleted file mode 100644 index e73c5c4de4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCascade2_0Tests.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.java.JavaCascade2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.OneToOne2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaCascade2_0Tests - extends Generic2_0ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - - public GenericJavaCascade2_0Tests(String name) { - super(name); - } - - - public void testUpdateCascadeDetach() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation annotation = (OneToOne2_0Annotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping2_0 mapping = (JavaOneToOneMapping2_0) persistentAttribute.getMapping(); - JavaCascade2_0 cascade = (JavaCascade2_0) mapping.getCascade(); - - assertFalse(cascade.isDetach()); - assertFalse(annotation.isCascadeDetach()); - - //set detach in the resource model, verify context model updated - annotation.setCascadeDetach(true); - getJpaProject().synchronizeContextModel(); - assertTrue(annotation.isCascadeDetach()); - assertTrue(cascade.isDetach()); - - //set detach to false in the resource model - annotation.setCascadeDetach(false); - getJpaProject().synchronizeContextModel(); - assertFalse(annotation.isCascadeDetach()); - assertFalse(cascade.isDetach()); - } - - public void testModifyCascadeDetach() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation annotation = (OneToOne2_0Annotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping2_0 mapping = (JavaOneToOneMapping2_0) persistentAttribute.getMapping(); - JavaCascade2_0 cascade = (JavaCascade2_0) mapping.getCascade(); - - assertFalse(cascade.isDetach()); - assertFalse(annotation.isCascadeDetach()); - - //set detach in the context model, verify resource model updated - cascade.setDetach(true); - assertTrue(annotation.isCascadeDetach()); - assertTrue(cascade.isDetach()); - - //set detach to false in the context model - cascade.setDetach(false); - assertFalse(annotation.isCascadeDetach()); - assertFalse(cascade.isDetach()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java deleted file mode 100644 index 4f116cbc15..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaCollectionTable2_0Tests.java +++ /dev/null @@ -1,722 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.jpa2.context.CollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaCollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.CollectionTable2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaCollectionTable2_0Tests extends Generic2_0ContextModelTestCase -{ - public GenericJavaCollectionTable2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection"); - } - }); - } - - private ICompilationUnit createTestEntityWithValidElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - sb.append(" private Collection projects;").append(CR); - } - }); - } - - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable); - - - //set name in the resource model, verify context model updated - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedName()); - assertEquals("FOO", resourceCollectionTable.getName()); - - //set name to null in the resource model - resourceCollectionTable.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable.getName()); - - resourceCollectionTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedName()); - assertEquals("FOO", resourceCollectionTable.getName()); - - attributeResource.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable3 = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable3); - - //set name in the context model, verify resource model modified - collectionTable.setSpecifiedName("foo"); - resourceCollectionTable3 = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedName()); - assertEquals("foo", resourceCollectionTable3.getName()); - - //set name to null in the context model - collectionTable.setSpecifiedName(null); - assertNull(collectionTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultName() throws Exception { - createTestEntityWithValidElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - - //add the collection table annotation, verify default collection table name is the same - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); - assertNotNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - - //set the entity name, verify default collection table name updates - getJavaEntity().setSpecifiedName("Foo"); - assertEquals("Foo_projects", collectionTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable); - - - //set schema in the resource model, verify context model updated - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceCollectionTable.getSchema()); - - //set schema to null in the resource model - resourceCollectionTable.setSchema(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable.getSchema()); - - resourceCollectionTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceCollectionTable.getSchema()); - - attributeResource.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedSchema() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable); - - //set schema in the context model, verify resource model modified - collectionTable.setSpecifiedSchema("foo"); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedSchema()); - assertEquals("foo", resourceCollectionTable.getSchema()); - - //set schema to null in the context model - collectionTable.setSpecifiedSchema(null); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable); - - - //set catalog in the resource model, verify context model updated - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceCollectionTable.getCatalog()); - - //set catalog to null in the resource model - resourceCollectionTable.setCatalog(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable.getCatalog()); - - resourceCollectionTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceCollectionTable.getCatalog()); - - attributeResource.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedCatalog() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable); - - //set catalog in the context model, verify resource model modified - collectionTable.setSpecifiedCatalog("foo"); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedCatalog()); - assertEquals("foo", resourceCollectionTable.getCatalog()); - - //set catalog to null in the context model - collectionTable.setSpecifiedCatalog(null); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JoinColumn joinColumn = collectionTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = collectionTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = collectionTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - ListIterator joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.joinColumnsSize()); - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.joinColumnsSize()); - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - - collectionTable.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - - collectionTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - joinTableResource.addJoinColumn(0); - joinTableResource.addJoinColumn(1); - joinTableResource.addJoinColumn(2); - - joinTableResource.joinColumnAt(0).setName("FOO"); - joinTableResource.joinColumnAt(1).setName("BAR"); - joinTableResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(collectionTable.specifiedJoinColumns().hasNext()); - } - - public void testGetDefaultJoinColumn() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(0, collectionTable.specifiedJoinColumnsSize()); - - collectionTable.addSpecifiedJoinColumn(0); - assertEquals(1, collectionTable.specifiedJoinColumnsSize()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, collectionTable.specifiedJoinColumnsSize()); - } - - public void testUniqueConstraints() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - ListIterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = collectionTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(0, collectionTable.uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, collectionTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - ListIterator uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - ListIterator uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - collectionTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - collectionTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - collectionTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - - collectionTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - collectionTable.moveUniqueConstraint(0, 1); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - joinTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - joinTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - - ListIterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java deleted file mode 100644 index abddec9560..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaElementCollectionMapping2_0Tests.java +++ /dev/null @@ -1,2077 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaElementCollectionMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - public static final String EMBEDDABLE_TYPE_NAME = "Address"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericEmbeddableElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericBasicElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithNonGenericElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddablePropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - private void createSelfReferentialElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.List elementCollection;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public GenericJavaElementCollectionMapping2_0Tests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollectionAnnotation = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollectionAnnotation.getTargetClass()); - - //set target class in the resource model, verify context model updated - elementCollectionAnnotation.setTargetClass("newTargetClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("newTargetClass", elementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollectionAnnotation.getTargetClass()); - - //set target class to null in the resource model - elementCollectionAnnotation.setTargetClass(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollectionAnnotation.getTargetClass()); - } - - public void testModifySpecifiedTargetClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedTargetClass("newTargetClass"); - assertEquals("newTargetClass", elementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the context model - elementCollectionMapping.setSpecifiedTargetClass(null); - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - public void testDefaultTargetClass() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Embeddable, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassNonGenericCollection() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassGenericCollection() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassNonGenericMap() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassGenericMap() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testTargetClass() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getTargetClass()); - - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertEquals("foo", elementCollectionMapping.getTargetClass()); - - elementCollectionMapping.setSpecifiedTargetClass(null); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getTargetClass()); - } - - protected Embeddable getResolvedTargetEmbeddable(ElementCollectionMapping2_0 mapping) { - return (Embeddable) ReflectionTools.executeMethod(mapping, "getResolvedTargetEmbeddable"); - } - - public void testResolvedTargetEmbeddable() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //target embeddable not in the persistence unit - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - //add target embeddable to the persistence unit, now target embeddable should resolve - createTestTargetEmbeddableAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - - elementCollectionMapping.setSpecifiedTargetClass(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - - elementCollectionMapping.setSpecifiedTargetClass(null); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - } - - public void testResolvedTargetEmbeddableWithBasicType() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //target is a basic type, so resolved target embeddable is null - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the resource model, verify context model updated - elementCollection.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the resource model - elementCollection.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, elementCollection.getFetch()); - - elementCollectionMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the context model - elementCollectionMapping.setSpecifiedFetch(null); - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testGetValueTypeEmbeddable() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeNone() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.NO_TYPE, elementCollectionMapping.getValueType()); - - elementCollectionMapping.setSpecifiedTargetClass("Address"); - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeBasic() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKey", elementCollectionMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", elementCollectionMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKeyAnnotation.getName()); - - //set mapKey to null in the context model - elementCollectionMapping.setSpecifiedMapKey(null); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKeyAnnotation.getName()); - elementCollectionMapping.setNoMapKey(true); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping2_0 = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Iterator mapKeyNames = - elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping2_0 = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Iterator mapKeyNames = elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - elementCollectionMapping2_0.setSpecifiedTargetClass("Address"); - mapKeyNames = elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - elementCollectionMapping2_0.setSpecifiedTargetClass("String"); - mapKeyNames = elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClass); - - //set mapKey name in the resource model, verify context model updated - mapKeyClass.setValue("myMapKeyClass"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKeyClass", elementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClass.getValue()); - - //set mapKey name to null in the resource model - mapKeyClass.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClass.getValue()); - - mapKeyClass.setValue("myMapKeyClass"); - attributeResource.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", elementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - elementCollectionMapping.setSpecifiedMapKeyClass(null); - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", elementCollectionMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", elementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", elementCollectionMapping.getMapKeyClass()); - - elementCollectionMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", elementCollectionMapping.getMapKeyClass()); - - elementCollectionMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", elementCollectionMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) elementCollectionMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - } - - public void testGetValueColumn() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getValueColumn().getSpecifiedName()); - assertEquals("id", elementCollectionMapping.getValueColumn().getName()); - assertEquals(TYPE_NAME + "_id", elementCollectionMapping.getValueColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", elementCollectionMapping.getValueColumn().getSpecifiedName()); - assertEquals("foo", elementCollectionMapping.getValueColumn().getName()); - assertEquals("id", elementCollectionMapping.getValueColumn().getDefaultName()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("addresses", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_addresses", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("addresses", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_addresses", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(6, attributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(6, attributeOverrideContainer.overridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state.name"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME_ + "State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualOverrides().next().getName()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = (Iterator) attributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.name", virtualAttributeOverrides.next().getName()); - assertEquals("state.abbr", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType persistentType = specifiedClassRefs.next().getJavaPersistentType(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentType.getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - ReadOnlyAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - assertEquals(false, virtualAttributeOverrides.hasNext()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("state").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = (ListIterator) nestedAttributeOverrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("abbr", virtualAttributeOverride.getName()); - - PersistentType statePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping abbrMapping = (BasicMapping) statePersistentType.getAttributeNamed("abbr").getMapping(); - abbrMapping.getColumn().setSpecifiedName("BLAH"); - abbrMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - abbrMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - abbrMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - abbrMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - abbrMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - abbrMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.state) attribute override to verify it is getting settings from the specified column on State.abbr - virtualAttributeOverride = ((EmbeddedMapping) addressPersistentType.getAttributeNamed("state").getMapping()).getAttributeOverrideContainer().getOverrideNamed("abbr"); - assertEquals("abbr", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - } - - public void testGetMapKeyColumn() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", elementCollectionMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_addresses", elementCollectionMapping.getMapKeyColumn().getTable());//collection table name - - elementCollectionMapping.getCollectionTable().setSpecifiedName("MY_COLLECTION_TABLE"); - assertEquals("MY_COLLECTION_TABLE", elementCollectionMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", elementCollectionMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", elementCollectionMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", elementCollectionMapping.getMapKeyColumn().getDefaultName()); - } - - public void testMapKeyValueSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - ListIterator specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - - - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("parcelNumber", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - classRefs.next(); - Embeddable propertyInfoEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping parcelNumberMapping = (BasicMapping) propertyInfoEmbeddable.getPersistentType().getAttributeNamed("parcelNumber").getMapping(); - parcelNumberMapping.getColumn().setSpecifiedName("FOO1"); - parcelNumberMapping.getColumn().setSpecifiedTable("BAR1"); - parcelNumberMapping.getColumn().setColumnDefinition("COLUMN_DEF1"); - parcelNumberMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - parcelNumberMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - parcelNumberMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - parcelNumberMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("FOO1", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR1", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF1", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - parcelNumberMapping.getColumn().setSpecifiedName(null); - parcelNumberMapping.getColumn().setSpecifiedTable(null); - parcelNumberMapping.getColumn().setColumnDefinition(null); - parcelNumberMapping.getColumn().setSpecifiedInsertable(null); - parcelNumberMapping.getColumn().setSpecifiedUpdatable(null); - parcelNumberMapping.getColumn().setSpecifiedUnique(null); - parcelNumberMapping.getColumn().setSpecifiedNullable(null); - parcelNumberMapping.getColumn().setSpecifiedLength(null); - parcelNumberMapping.getColumn().setSpecifiedPrecision(null); - parcelNumberMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("parcelNumber", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("value.parcelNumber"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, valueAttributeOverrideContainer.specifiedOverridesSize()); - assertEquals(0, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, valueAttributeOverrideContainer.specifiedOverridesSize()); - assertEquals(1, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.overridesSize()); - assertEquals(3, valueAttributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(5, mapKeyAttributeOverrideContainer.overridesSize()); - assertEquals(5, valueAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, mapKeyAttributeOverrideContainer.overridesSize()); - assertEquals(6, valueAttributeOverrideContainer.overridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(3, valueAttributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(3, valueAttributeOverrideContainer.virtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.city"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.parcelNumber"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(2, valueAttributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.name"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, valueAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME_ + "PropertyInfo"); - addXmlClassRef(PACKAGE_NAME_ + "State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - valueOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyOverrideContainer.virtualOverrides().next().convertToSpecified(); - valueOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - Iterator overrideAnnotations = resourceAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - valueOverrideContainer.specifiedOverrides().next().convertToVirtual(); - mapKeyOverrideContainer.specifiedOverrides().next().convertToVirtual(); - overrideAnnotations = resourceAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - assertEquals("parcelNumber", valueOverrideContainer.virtualOverrides().next().getName()); - assertEquals(2, valueOverrideContainer.virtualOverridesSize()); - assertEquals("city", mapKeyOverrideContainer.virtualOverrides().next().getName()); - assertEquals(3, mapKeyOverrideContainer.virtualOverridesSize()); - - valueOverrideContainer.specifiedOverrides().next().convertToVirtual(); - mapKeyOverrideContainer.specifiedOverrides().next().convertToVirtual(); - overrideAnnotations = resourceAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(overrideAnnotations.hasNext()); - - Iterator virtualAttributeOverrides = (ListIterator) valueOverrideContainer.virtualOverrides(); - assertEquals("parcelNumber", virtualAttributeOverrides.next().getName()); - assertEquals("size", virtualAttributeOverrides.next().getName()); - assertEquals("tax", virtualAttributeOverrides.next().getName()); - assertEquals(3, valueOverrideContainer.virtualOverridesSize()); - - virtualAttributeOverrides = (ListIterator) mapKeyOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.name", virtualAttributeOverrides.next().getName()); - assertEquals("state.abbr", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyOverrideContainer.virtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - valueAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - valueAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - ListIterator specifiedOverrides = (ListIterator) valueAttributeOverrideContainer.specifiedOverrides(); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertEquals("size", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = (ListIterator) mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourcePersistentType resourceType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - - resourceAttribute.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - this.getJpaProject().synchronizeContextModel(); - getJpaProject().synchronizeContextModel(); - - Iterator overrideAnnotations = resourceAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - specifiedOverrides = (ListIterator) valueAttributeOverrideContainer.specifiedOverrides(); - assertEquals("size", specifiedOverrides.next().getName()); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = (ListIterator) mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - - resourceAttribute.moveAnnotation(3, 2, AttributeOverridesAnnotation.ANNOTATION_NAME); - this.getJpaProject().synchronizeContextModel(); - getJpaProject().synchronizeContextModel(); - - overrideAnnotations = resourceAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("value.size", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) overrideAnnotations.next()).getName()); - assertFalse(overrideAnnotations.hasNext()); - - specifiedOverrides = (ListIterator) valueAttributeOverrideContainer.specifiedOverrides(); - assertEquals("size", specifiedOverrides.next().getName()); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = (ListIterator) mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } - - public void testSelfReferentialElementCollection() throws Exception { - createSelfReferentialElementCollection(); - addXmlClassRef(PACKAGE_NAME + ".Foo"); - - //If there is a StackOverflowError you will not be able to get the mapping - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("elementCollection").getMapping(); - assertFalse(elementCollectionMapping.allOverridableAttributeMappingNames().hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java deleted file mode 100644 index dd0372e687..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEmbeddedMapping2_0Tests.java +++ /dev/null @@ -1,1550 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAssociationOverride; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.VirtualJoinColumn; -import org.eclipse.jpt.core.context.VirtualJoinColumnRelationship; -import org.eclipse.jpt.core.context.VirtualJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.VirtualJoinTable; -import org.eclipse.jpt.core.context.VirtualJoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaEmbeddedMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDED, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded").append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - private void createAddressEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Address {"); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - public GenericJavaEmbeddedMapping2_0Tests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((JavaEmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().overrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof JavaEmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testDefaultEmbeddedMappingGenericEmbeddable() throws Exception { - createTestEntityWithDefaultEmbeddedMapping(); - createTestGenericEmbeddable(); - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Embeddable1"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbeddable"); - assertNotNull(persistentAttribute.getMapping()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - private void createTestEntityWithDefaultEmbeddedMapping() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 { ").append(CR); - sb.append("private Embeddable1 myEmbeddable;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericEmbeddable() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class Embeddable1 {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Embeddable1.java", sourceWriter); - } - - private void createSelfReferentialEmbedded() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Foo embedded;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().getAttributeNamed("myEmbedded"); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualOverrides().next().getName()); - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - ListIterator specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) resourceAttribute.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) resourceAttribute.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) resourceAttribute.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - resourceAttribute.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - resourceAttribute.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - resourceAttribute.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - resourceAttribute.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - assertNull(resourceAttribute.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - VirtualJoinColumnRelationshipStrategy joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - VirtualJoinColumn virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("address_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaPersistentType javaEmbeddable = classRefs.next().getJavaPersistentType(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) javaEmbeddable.getAttributeNamed("address").getMapping(); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertNull(resourceAttribute.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals("MY_JOIN_COLUMN", joiningStrategy.joinColumns().next().getName()); - - - assertNull(resourceAttribute.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) resourceAttribute.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) resourceAttribute.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.overridesSize()); - - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) resourceAttribute.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, overrideContainer.overridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - Iterator associationOverrides = resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("addresses", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - Iterator associationOverrides = resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("addresses", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - assertEquals(2, CollectionTools.size(resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - Iterator associationOverrideResources = resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("addresses", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("addresses", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - associationOverrideResources = resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - - assertNull(resourceAttribute.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - Iterator javaAssociationOverrides = resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("addresses", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - javaAssociationOverrides = resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("addresses", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("addresses", associationOverrides.next().getName()); - - javaAssociationOverrides = resourceAttribute.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("addresses", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - ((AssociationOverrideAnnotation) resourceAttribute.addAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AssociationOverrideAnnotation) resourceAttribute.addAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AssociationOverrideAnnotation) resourceAttribute.addAnnotation(2, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceAttribute.moveAnnotation(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceAttribute.moveAnnotation(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceAttribute.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceAttribute.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - resourceAttribute.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - ReadOnlyAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - - public void testVirtualAssociationOverrideJoinTableDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - assertNull(resourceAttribute.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = CollectionTools.get(overrideContainer.virtualOverrides(), 1); - VirtualJoinTableRelationshipStrategy joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - VirtualJoinTable joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals("AnnotationTestType_Address", joinTable.getName()); - assertEquals(1, joinTable.joinColumnsSize()); - VirtualJoinColumn virtualJoinColumn = joinTable.joinColumns().next(); - assertEquals("AnnotationTestType_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - VirtualJoinColumn virtualInverseJoinColumn = joinTable.inverseJoinColumns().next(); - assertEquals("addresses_id", virtualInverseJoinColumn.getName()); - assertEquals("id", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualInverseJoinColumn.getTable()); - assertEquals(null, virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(true, virtualInverseJoinColumn.isInsertable()); - assertEquals(true, virtualInverseJoinColumn.isUpdatable()); - assertEquals(false, virtualInverseJoinColumn.isUnique()); - assertEquals(true, virtualInverseJoinColumn.isNullable()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaPersistentType javaEmbeddable = classRefs.next().getJavaPersistentType(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) javaEmbeddable.getAttributeNamed("addresses").getMapping(); - JoinTableRelationshipStrategy joinTableStrategy = oneToManyMapping.getRelationship().getJoinTableStrategy(); - joinTableStrategy.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = joinTableStrategy.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - JoinColumn inverseJoinColumn = joinTableStrategy.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("MY_INVERSE_JOIN_COLUMN"); - inverseJoinColumn.setSpecifiedReferencedColumnName("MY_INVERSE_REFERENCE_COLUMN"); - inverseJoinColumn.setSpecifiedTable("INVERSE_BAR"); - inverseJoinColumn.setColumnDefinition("INVERSE_COLUMN_DEF"); - inverseJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUnique(Boolean.TRUE); - inverseJoinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertNull(resourceAttribute.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = CollectionTools.get(overrideContainer.virtualOverrides(), 1); - joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals(1, joinTable.joinColumnsSize()); - virtualJoinColumn = joinTable.joinColumns().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - virtualInverseJoinColumn = joinTable.inverseJoinColumns().next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - assertEquals("INVERSE_COLUMN_DEF", virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(false, virtualInverseJoinColumn.isInsertable()); - assertEquals(false, virtualInverseJoinColumn.isUpdatable()); - assertEquals(true, virtualInverseJoinColumn.isUnique()); - assertEquals(false, virtualInverseJoinColumn.isNullable()); - - - assertNull(resourceAttribute.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(5, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - JavaEmbeddedMapping nestedEmbeddedMapping = (JavaEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - JavaAttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = nestedAttributeOverrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((JavaEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((JavaEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((JavaEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - virtualAttributeOverride = (VirtualAttributeOverride) ((JavaEmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testSelfReferentialEmbeddedMapping() throws Exception { - createSelfReferentialEmbedded(); - addXmlClassRef(PACKAGE_NAME + ".Foo"); - - //If there is a StackOverflowError you will not be able to get the mapping - JavaEmbeddedMapping2_0 embeddedMapping = (JavaEmbeddedMapping2_0) getJavaPersistentType().getAttributeNamed("embedded").getMapping(); - assertFalse(embeddedMapping.allOverridableAttributeMappingNames().hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java deleted file mode 100644 index e36917e92f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaEntity2_0Tests.java +++ /dev/null @@ -1,2069 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.core.jpa2.context.LockModeType2_0; -import org.eclipse.jpt.core.jpa2.context.NamedQuery2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.Cacheable2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.NamedQuery2_0Annotation; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaEntity2_0Tests extends Generic2_0ContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public GenericJavaEntity2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestMappedSuperclassCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - private void createTestMappedSuperclassCustomerWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEntityLongTimeCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("LongTimeCustomer extends Customer "); - sb.append("{}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "LongTimeCustomer.java", sourceWriter); - } - - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@AssociationOverride(name=\"a\", joinTable=@JoinTable)"); - } - }); - } - - - private LockModeType2_0 lockModeOf(NamedQuery2_0Annotation resourceQuery) { - return resourceQuery == null ? null : LockModeType2_0.fromJavaResourceModel(resourceQuery.getLockMode()); - } - - public void testAddNamedQuery2_0() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = this.getJavaEntity(); - JavaResourcePersistentType typeResource = this.getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(0); - namedQuery1.setName("FOO"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - Iterator javaNamedQueries = typeResource.annotations( - NamedQueryAnnotation.ANNOTATION_NAME, - NamedQueriesAnnotation.ANNOTATION_NAME); - NamedQuery2_0Annotation queryAnnotation = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("FOO", queryAnnotation.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(queryAnnotation)); - - NamedQuery2_0 namedQuery2 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.READ); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - queryAnnotation = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", queryAnnotation.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(queryAnnotation)); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - - NamedQuery2_0 namedQuery3 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - namedQuery3.setSpecifiedLockMode(LockModeType2_0.WRITE); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - queryAnnotation = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAZ", queryAnnotation.getName()); - assertEquals(LockModeType2_0.WRITE, this.lockModeOf(queryAnnotation)); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - - ListIterator namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery1, namedQueries.next()); - - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("foo"); - } - - public void testRemoveNamedQuery2_0() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.READ); - - NamedQuery2_0 namedQuery2 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(2); - namedQuery2.setName("BAZ"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - Iterator javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - NamedQuery2_0Annotation annotation1 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", annotation1.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(annotation1)); - - NamedQuery2_0Annotation annotation2 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAZ", annotation2.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation2)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - annotation2 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAZ", annotation2.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation2)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testMoveNamedQuery2_0() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) entity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - - entity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator namedQueries = entity.getQueryContainer().namedQueries(); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - NamedQuery2_0Annotation annotation1 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", annotation1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation1)); - assertEquals("BAZ", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - annotation1 = (NamedQuery2_0Annotation) javaNamedQueries.next(); - assertEquals("BAR", annotation1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(annotation1)); - assertEquals("FOO", ((NamedQuery2_0Annotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedQueries2_0() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - - ((NamedQuery2_0Annotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQuery2_0Annotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - NamedQuery2_0Annotation annotation1 = (NamedQuery2_0Annotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - annotation1.setName("BAZ"); - annotation1.setLockMode(org.eclipse.jpt.core.jpa2.resource.java.LockModeType_2_0.OPTIMISTIC); - getJpaProject().synchronizeContextModel(); - - ListIterator namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - NamedQuery2_0 namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAR", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().queriesSize()); - - typeResource.moveAnnotation(2, 0, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.moveAnnotation(0, 1, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - namedQuery1 = (NamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - } - - public void testNamedQueries2_0Size() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getQueryContainer().namedQueriesSize()); - - ((NamedQuery2_0Annotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQuery2_0Annotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedQuery2_0Annotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - this.getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().namedQueriesSize()); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) getJavaPersistentType().getMapping(); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAssociations = abstractEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributeNames = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertEquals("foo", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - ListIterator specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testVirtualAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - JavaEntity superclass = (JavaEntity) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, overrideContainer.overridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(3, CollectionTools.size(typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - Iterator attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - Iterator attributeOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - attributeOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrideResources.hasNext()); - attributeOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaAttributeOverrides)); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("name", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("name", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - } -// - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AttributeOverrideAnnotation) typeResource.addAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(2, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = (ListIterator) overrideContainer.virtualOverrides(); - JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - - public void testOverridableAssociations() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().overridableAssociationNames(); - assertFalse(overridableAssociations.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociationNames = getJavaEntity().overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -// //TODO add all mapping types to the mapped superclass to test which ones are overridable - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociationNames = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociationNames.next()); - assertEquals("address2", overridableAssociationNames.next()); - assertEquals("address3", overridableAssociationNames.next()); - assertEquals("address4", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AssociationOverrideContainer overrideContainer = javaEntity.getAssociationOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - - //MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - //BasicMapping idMapping = (BasicMapping) mappedSuperclass.persistentType().attributeNamed("id").getMapping(); - //idMapping.getColumn().setSpecifiedName("FOO"); - //idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - //idMapping.getColumn().setSpecifiedName(null); - //idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, overrideContainer.overridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(2, CollectionTools.size(typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - Iterator associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedOverride(1, 0); - Iterator associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address2", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("address2", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address2", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AssociationOverrideAnnotation) typeResource.addAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(2, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - JavaVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AttributeOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAttributeOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AttributeOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AssociationOverrideContainer associationOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, associationOverrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = (ListIterator) associationOverrideContainer.virtualOverrides(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testNestedVirtualAssociationOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AssociationOverrideContainer associationOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, associationOverrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = (ListIterator) associationOverrideContainer.virtualOverrides(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testSetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheable.setSpecifiedCacheable(null); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testGetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - getJavaPersistentType().getResourcePersistentType().addAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheableAnnotation.setValue(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheableAnnotation.setValue(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(true)", cu); - - cacheableAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - getJavaPersistentType().getResourcePersistentType().removeAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testIsDefaultCacheable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - assertEquals(SharedCacheMode.UNSPECIFIED, persistenceUnit2_0.getSharedCacheMode()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testInheritedIsDefaultCacheable() throws Exception { - createTestEntity(); - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity().getParentEntity()).getCacheable(); - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } - - //This is a test for bug 301892 - public void testAssociationOverrideJoinTableUpdate() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAssociationOverride associationOverride = getJavaEntity().getAssociationOverrideContainer().specifiedOverrides().next(); - assertEquals("a", associationOverride.getName()); - - AssociationOverride2_0Annotation annotation = (AssociationOverride2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA.ASSOCIATION_OVERRIDE); - annotation.getJoinTable().setName("FOO"); - annotation.getJoinTable().addInverseJoinColumn(0).setName("BAR"); - - getJpaProject().synchronizeContextModel(); - - associationOverride = getJavaEntity().getAssociationOverrideContainer().specifiedOverrides().next(); - assertEquals("a", associationOverride.getName()); - JoinTable joinTable = ((JavaOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("BAR", joinTable.inverseJoinColumns().next().getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java deleted file mode 100644 index a87ea29007..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToManyMapping2_0Tests.java +++ /dev/null @@ -1,1218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.context.ManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaManyToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaManyToManyMapping2_0Tests(String name) { - super(name); - } - - - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Collection employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private String address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityPropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employees", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employees", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKey(null); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKey.getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping2_0 = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator mapKeyNames = - manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employees", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping2_0 = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator mapKeyNames = manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - manyToManyMapping2_0.setSpecifiedTargetEntity("Address"); - mapKeyNames = manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employees", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - manyToManyMapping2_0.setSpecifiedTargetEntity("String"); - mapKeyNames = manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClassAnnotation = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClassAnnotation); - - //set mapKey name in the resource model, verify context model updated - mapKeyClassAnnotation.setValue("myMapKeyClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("myMapKeyClass", manyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClassAnnotation.getValue()); - - //set mapKey name to null in the resource model - mapKeyClassAnnotation.setValue(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClassAnnotation.getValue()); - - mapKeyClassAnnotation.setValue("myMapKeyClass"); - attributeResource.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", manyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", manyToManyMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", manyToManyMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", manyToManyMapping.getMapKeyClass()); - - manyToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", manyToManyMapping.getMapKeyClass()); - - manyToManyMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", manyToManyMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - addXmlClassRef(PACKAGE_NAME + ".PrintQueue"); - addXmlClassRef(PACKAGE_NAME + ".PrintJob"); - JavaPersistentType printQueuePersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintQueue"); - ManyToManyMapping jobsMapping = (ManyToManyMapping) printQueuePersistentType.getAttributeNamed("jobs").getMapping(); - JavaPersistentType printJobPersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ManyToManyMapping queuesMapping = (ManyToManyMapping) printJobPersistentType.getAttributeNamed("queues").getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - OrderColumn2_0 jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(null, jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); //the join table name - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - OrderColumn2_0 queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(null, queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - jobsOrderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderColumn.setSpecifiedName("BAR"); - assertEquals("BAR", queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - assertEquals("MY_TABLE_PrintQueue", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printQueuePersistentType.getMapping()).getTable().setSpecifiedName("OTHER_TABLE"); - assertEquals("MY_TABLE_OTHER_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_OTHER_TABLE", queuesOrderColumn.getTable()); - - queuesMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_JOIN_TABLE", queuesOrderColumn.getTable()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany(mappedBy=\"queues\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List queues;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testGetMapKeyColumn() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", manyToManyMapping.getMapKeyColumn().getTable());//join table name - - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnMappedByStrategy() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - manyToManyMapping.getRelationship().setStrategyToMappedBy(); - manyToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("employees"); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address_" + TYPE_NAME, manyToManyMapping.getMapKeyColumn().getTable());//join table name of owning many-to-many - - PersistentType persistentType = getPersistenceUnit().getPersistentType("test.Address"); - ManyToManyMapping owningManyToManyMapping = (ManyToManyMapping) persistentType.getAttributeNamed("employees").getMapping(); - ((JoinTableRelationshipStrategy) owningManyToManyMapping.getRelationship().getStrategy()).getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnJoinTableStrategy() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", manyToManyMapping.getMapKeyColumn().getTable());//join table name - - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - - public void testMapKeySpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = mapKeyAttributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.foo", virtualAttributeOverrides.next().getName()); - assertEquals("state.address", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - ListIterator specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java deleted file mode 100644 index 74e66f1c77..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0Tests.java +++ /dev/null @@ -1,419 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.ManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedIdentity2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapsId2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaManyToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaManyToOneMapping2_0Tests(String name) { - super(name); - } - - - private ICompilationUnit createTestEntityWithManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithIdDerivedIdentity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - annotation.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - annotation.setValue("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceAttribute.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - assertNotNull(annotation); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceAttribute.addAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceAttribute.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceAttribute.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaIdMapping); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaManyToOneMapping2_0); - - contextAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaBasicMapping); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping2_0 mapping = (ManyToOneMapping2_0) contextAttribute.getMapping(); - ManyToOneRelationship2_0 rel = (ManyToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping2_0 mapping = (ManyToOneMapping2_0) contextAttribute.getMapping(); - ManyToOneRelationship2_0 rel = (ManyToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java deleted file mode 100644 index 712a2c06e2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToManyMapping2_0Tests.java +++ /dev/null @@ -1,1526 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnRelationship; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToManyRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.OneToMany2_0Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaOneToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaOneToManyMapping2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToManyMappingOrphanRemovalSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(orphanRemoval=false)").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private AnnotationTestType employee;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private String address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityPropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employee", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employee", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - private JavaOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) { - return ((JavaOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval(); - } - - public void testDefaultOneToManyGetDefaultOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToManyMapping).isDefaultOrphanRemoval()); - } - - public void testSpecifiedOneToManyGetDefaultOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToManyMapping).isDefaultOrphanRemoval()); - } - - public void testGetOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertEquals(false, mappingsOrphanRemoval.isOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(true, mappingsOrphanRemoval.isOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - oneToMany.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToManyMappingOrphanRemovalSpecified(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testSetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - - assertEquals(Boolean.TRUE, oneToMany.getOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_MANY)); // .getElement); - } - - public void testSetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - - assertEquals(Boolean.TRUE, oneToMany.getOrphanRemoval()); - - oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_MANY)); - - oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - } - - public void testGetSpecifiedOrphanRemovalUpdatesFromResourceModelChange() throws Exception { - this.createTestEntityWithValidOneToManyMapping(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - oneToMany.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - oneToMany.setOrphanRemoval(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertSame(oneToManyMapping, persistentAttribute.getMapping()); - - oneToMany.setOrphanRemoval(Boolean.FALSE); - attributeResource.setPrimaryAnnotation(null, EmptyIterable.instance()); - getJpaProject().synchronizeContextModel(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKeyAnnotation.getName()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKey(null); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKeyAnnotation.getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping2_0 = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - Iterator mapKeyNames = - oneToManyMapping2_0.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employee", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping2_0 = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - Iterator mapKeyNames = oneToManyMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - oneToManyMapping2_0.setSpecifiedTargetEntity("Address"); - mapKeyNames = oneToManyMapping2_0.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employee", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - oneToManyMapping2_0.setSpecifiedTargetEntity("String"); - mapKeyNames = oneToManyMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClassAnnotation = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClassAnnotation); - - //set mapKey name in the resource model, verify context model updated - mapKeyClassAnnotation.setValue("myMapKeyClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("myMapKeyClass", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClassAnnotation.getValue()); - - //set mapKey name to null in the resource model - mapKeyClassAnnotation.setValue(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClassAnnotation.getValue()); - - mapKeyClassAnnotation.setValue("myMapKeyClass"); - attributeResource.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", oneToManyMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", oneToManyMapping.getMapKeyClass()); - - oneToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", oneToManyMapping.getMapKeyClass()); - - oneToManyMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", oneToManyMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - addXmlClassRef(PACKAGE_NAME + ".PrintQueue"); - addXmlClassRef(PACKAGE_NAME + ".PrintJob"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) getJavaPersistentType().getAttributeNamed("jobs").getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - JavaPersistentType printJobPersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - - assertEquals("MY_TABLE", orderColumn.getTable()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @OneToMany(mappedBy=\"queue\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private PrintQueue queue;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testGetMapKeyColumnMappedByStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - oneToManyMapping.getRelationship().setStrategyToMappedBy(); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("employee"); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//owing entity table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnJoinTableStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", oneToManyMapping.getMapKeyColumn().getTable());//join table name - - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testTargetForeignKeyJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - JoinColumn joinColumn = ((JoinColumnRelationship) oneToManyMapping.getRelationship()).getJoinColumnStrategy().specifiedJoinColumns().next(); - - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("Address", joinColumn.getDefaultTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - joinColumn.setSpecifiedName("FOO"); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - } - - //target foreign key case - public void testGetMapKeyColumnJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getDefaultTable()); - } - - //target foreign key case - public void testOrderColumnDefaultsJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - ((Orderable2_0) oneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = ((Orderable2_0) oneToManyMapping.getOrderable()).getOrderColumn(); - - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("Address", orderColumn.getTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); - OneToManyRelationship2_0 rel = (OneToManyRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); - OneToManyRelationship2_0 rel = (OneToManyRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testMapKeySpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = mapKeyAttributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.foo", virtualAttributeOverrides.next().getName()); - assertEquals("state.address", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - ListIterator specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java deleted file mode 100644 index b97c4f8a4d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0Tests.java +++ /dev/null @@ -1,884 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedIdentity2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapsId2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.OneToOne2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaOneToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericJavaOneToOneMapping2_0Tests(String name) { - super(name); - } - - - private void createTestEntity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private Address address;"); - sb.append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithIdDerivedIdentity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(orphanRemoval=false)"); - sb.append(CR); - sb.append(" private Address address;"); - sb.append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - annotation.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - annotation.setValue("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceAttribute.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - assertNotNull(annotation); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceAttribute.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceAttribute.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceAttribute.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - JavaDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - - ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertFalse(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertFalse(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - private JavaOrphanRemovable2_0 getOrphanRemovalOf(OneToOneMapping2_0 oneToOneMapping) { - return ((JavaOrphanRemovalHolder2_0) oneToOneMapping).getOrphanRemoval(); - } - - public void testDefaultOneToOneGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToOneMapping).isDefaultOrphanRemoval()); - } - - public void testSpecifiedOneToOneGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToOneMapping).isDefaultOrphanRemoval()); - } - - public void testGetOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertEquals(false, mappingsOrphanRemoval.isOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(true, mappingsOrphanRemoval.isOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - oneToOne.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - - assertEquals(Boolean.FALSE, this.getOrphanRemovalOf(oneToOneMapping).getSpecifiedOrphanRemoval()); - } - - public void testSetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - - assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_ONE)); // .getElement); - } - - public void testSetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - - assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); - - oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_ONE)); - } - - public void testGetSpecifiedOrphanRemovalUpdatesFromResourceModelChange() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - oneToOne.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - oneToOne.setOrphanRemoval(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertSame(oneToOneMapping, persistentAttribute.getMapping()); - - oneToOne.setOrphanRemoval(Boolean.FALSE); - attributeResource.setPrimaryAnnotation(null, EmptyIterable.instance()); - getJpaProject().synchronizeContextModel(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 mapping = (OneToOneMapping2_0) contextAttribute.getMapping(); - OneToOneRelationship2_0 rel = (OneToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 mapping = (OneToOneMapping2_0) contextAttribute.getMapping(); - OneToOneRelationship2_0 rel = (OneToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java deleted file mode 100644 index d357fef7b7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0Tests.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaPersistentAttribute2_0Tests extends Generic2_0ContextModelTestCase -{ - private ICompilationUnit createTestEntityForDerivedId() throws Exception { - return createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntitySpecifiedAccessField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.BASIC, JPA.TRANSIENT, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.FIELD)"); - } - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("transient"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createTestEntitySpecifiedAccessProperty() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.BASIC, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Access(AccessType.FIELD)"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public GenericJavaPersistentAttribute2_0Tests(String name) { - super(name); - } - - public void testGetAccessField() throws Exception { - createTestEntitySpecifiedAccessField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute namePersistentAttribute = getJavaPersistentType().getAttributeNamed("name"); - assertEquals(AccessType.FIELD, namePersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, namePersistentAttribute.getDefaultAccess()); - assertEquals(null, namePersistentAttribute.getSpecifiedAccess()); - - PersistentAttribute idPersistentAttribute = getJavaPersistentType().getAttributeNamed("id"); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, idPersistentAttribute.getMappingKey()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getDefaultAccess()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getSpecifiedAccess()); - } - - public void testGetAccessProperty() throws Exception { - createTestEntitySpecifiedAccessProperty(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute namePersistentAttribute = getJavaPersistentType().getAttributeNamed("name"); - assertEquals(AccessType.FIELD, namePersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, namePersistentAttribute.getDefaultAccess()); - assertEquals(AccessType.FIELD, namePersistentAttribute.getSpecifiedAccess()); - - PersistentAttribute idPersistentAttribute = getJavaPersistentType().getAttributeNamed("id"); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, idPersistentAttribute.getMappingKey()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, idPersistentAttribute.getDefaultAccess()); - assertEquals(null, idPersistentAttribute.getSpecifiedAccess()); - } - - public void testDerivedIdMappingInitialization() throws Exception { - createTestEntityForDerivedId(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaPersistentAttribute id = getJavaPersistentType().getAttributeNamed("id"); - assertEquals(id.getMappingKey(), MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - - id.getResourcePersistentAttribute().addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - id.getResourcePersistentAttribute().addAnnotation(JPA.ONE_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(id.getResourcePersistentAttribute().getAnnotation(JPA.ID)); - - id.getResourcePersistentAttribute().removeAnnotation(JPA.ONE_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - id.getResourcePersistentAttribute().addAnnotation(JPA.MANY_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(id.getResourcePersistentAttribute().getAnnotation(JPA.ID)); - - id.getResourcePersistentAttribute().removeAnnotation(JPA.MANY_TO_ONE); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - id.getResourcePersistentAttribute().setPrimaryAnnotation(null, EmptyIterable.instance()); - getJpaProject().synchronizeContextModel(); - assertEquals(id.getMappingKey(), MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java deleted file mode 100644 index fd2ad579ac..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaPersistentType2_0Tests.java +++ /dev/null @@ -1,853 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IField; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericJavaPersistentType2_0Tests extends Generic2_0ContextModelTestCase -{ - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldAndMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Access(AccessType.PROPERTY)"); - } - - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedPropertyFieldSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createTestSubType() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createTestSubTypeWithFieldAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeWithMethodAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - }); - } - - private ICompilationUnit createTestSubTypePersistentExtendsNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild2.java", "AnnotationTestTypeChild2", new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends AnnotationTestTypeChild "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public GenericJavaPersistentType2_0Tests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, getJavaPersistentType().getName()); - } - - public void testGetAccessNothingAnnotated() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - } - - public void testAccessFieldAndMethodAnnotated() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessFieldAnnotatedPropertySpecified() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("name", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMapping().getKey()); - - assertFalse(attributes.hasNext()); - } - - public void testAccessPropertyAnnotatedFieldSpecified() throws Exception { - createTestEntityAnnotatedPropertyFieldSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("name", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - assertFalse(attributes.hasNext()); - - attributes = getJavaPersistentType().attributes(); - attributes.next().getResourcePersistentAttribute().setPrimaryAnnotation(TransientAnnotation.ANNOTATION_NAME, EmptyIterable.instance()); - attributes = getJavaPersistentType().attributes(); - javaPersistentAttribute = attributes.next(); - - javaPersistentAttribute = attributes.next(); - assertEquals("name", javaPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - javaPersistentAttribute = attributes.next(); - assertEquals("id", javaPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - assertFalse(attributes.hasNext()); - } - - public void testAccessInheritance() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance2() throws Exception { - createTestEntityAnnotatedField(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessInheritance3() throws Exception { - createTestEntityAnnotatedField(); - createTestSubTypeWithMethodAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance4() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inherited class having annotations set wins over the default access set on persistence-unit-defaults - public void testAccessInheritancePersistenceUnitDefaultAccess() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlNoAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception { - //xml access set to property, field annotations, JavaPersistentType access is field - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception { - //xml access set to field, property annotations, JavaPersistentType access is property - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inheritance wins over entity-mappings specified access - public void testAccessXmlEntityMappingsAccessWithInheritance() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childEntityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - - createTestEntityAnnotatedMethod(); - createTestSubType(); - JavaPersistentType childJavaPersistentType = childEntityPersistentType.getJavaPersistentType(); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, entityPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.PROPERTY, childJavaPersistentType.getAccess()); - } - - public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception { - //xml access set to property, java has field annotations so the access should be field - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - } - - public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception { - //xml access not set, metadata complete set. JavaPersistentType access is property because properties are annotated - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testSuperPersistentType() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testSuperPersistentType2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - //super is not added to the getPersistenceUnit, but it should still be found - //as the superPersistentType because of impliedClassRefs and changes for bug 190317 - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType javaPersistentType = classRefs.next().getJavaPersistentType(); - - assertNotNull(javaPersistentType.getSuperPersistentType()); - } - - //Entity extends Non-Entity extends Entity - public void testSuperPersistentType3() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testInheritanceHierarchy() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testInheritanceHierarchy2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testGetMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testMappingKeyNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setPrimaryAnnotation(EmbeddableAnnotation.ANNOTATION_NAME, EmptyIterable.instance()); - this.getJpaProject().synchronizeContextModel(); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setPrimaryAnnotation(EntityAnnotation.ANNOTATION_NAME, EmptyIterable.instance()); - this.getJpaProject().synchronizeContextModel(); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testIsMapped() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaPersistentType().isMapped()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertFalse(getJavaPersistentType().isMapped()); - } - - public void testAttributes() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Iterator attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributes2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertEquals("name", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributesSize() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(1, getJavaPersistentType().attributesSize()); - } - - public void testAttributesSize2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, getJavaPersistentType().attributesSize()); - } - - public void testAttributeNamed() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("id"); - - assertEquals("id", attribute.getName()); - assertNull(getJavaPersistentType().getAttributeNamed("name")); - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testAttributeNamed2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("name"); - - assertEquals("name", attribute.getName()); - - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testRenameAttribute() throws Exception { - ICompilationUnit testType = createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute idAttribute = attributes.next(); - JavaPersistentAttribute nameAttribute = attributes.next(); - - - assertEquals("id", idAttribute.getName()); - assertEquals("name", nameAttribute.getName()); - - IField idField = testType.findPrimaryType().getField("id"); - idField.rename("id2", false, null); - - attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute nameAttribute2 = attributes.next(); - JavaPersistentAttribute id2Attribute = attributes.next(); - - assertNotSame(idAttribute, id2Attribute); - assertEquals("id2", id2Attribute.getName()); - assertEquals(nameAttribute, nameAttribute2); - assertEquals("name", nameAttribute2.getName()); - assertFalse(attributes.hasNext()); - } - - public void testSuperPersistentTypeGeneric() throws Exception { - createTestGenericEntity(); - createTestGenericMappedSuperclass(); - - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Entity2"); - - JavaPersistentType javaPersistentType = getJavaPersistentType(); - assertEquals("test.Entity1", javaPersistentType.getName()); - assertNotNull(javaPersistentType.getSuperPersistentType()); - - assertEquals("test.Entity2", javaPersistentType.getSuperPersistentType().getName()); - } - - private void createTestGenericEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 "); - sb.append("extends Entity2 {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericMappedSuperclass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class Entity2 {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity2.java", sourceWriter); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java deleted file mode 100644 index b335819b45..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/java/GenericJavaSequenceGenerator2_0Tests.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.jpa2.context.SequenceGenerator2_0; -import org.eclipse.jpt.core.jpa2.resource.java.SequenceGenerator2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -/** - * GenericJavaSequenceGenerator2_0Tests - */ -@SuppressWarnings("nls") -public class GenericJavaSequenceGenerator2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String SEQUENCE_GENERATOR_NAME = "TEST_SEQUENCE_GENERATOR"; - - public GenericJavaSequenceGenerator2_0Tests(String name) { - super(name); - } - - // ********** catalog ********** - - public void testGetCatalog() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getCatalog()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - annotation.setCatalog("testCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("testCatalog", sequenceGenerator.getCatalog()); - assertEquals("testCatalog", sequenceGenerator.getSpecifiedCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getDefaultCatalog()); - - sequenceGenerator.setSpecifiedCatalog("testCatalog"); - - assertNull(sequenceGenerator.getDefaultCatalog()); - assertEquals("testCatalog", sequenceGenerator.getSpecifiedCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - sequenceGenerator.setSpecifiedCatalog("testCatalog"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals("testCatalog", annotation.getCatalog()); - - sequenceGenerator.setSpecifiedCatalog(null); - assertNull(annotation.getCatalog()); - } - - // ********** schema ********** - - public void testGetSchema() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) this.getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getSchema()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - annotation.setSchema("testSchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("testSchema", sequenceGenerator.getSchema()); - assertEquals("testSchema", sequenceGenerator.getSpecifiedSchema()); - } - - public void testGetDefaultSchema() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getDefaultSchema()); - - sequenceGenerator.setSpecifiedSchema("testSchema"); - - assertNull(sequenceGenerator.getDefaultSchema()); - assertEquals("testSchema", sequenceGenerator.getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntityWithSequenceGenerator(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - IdMapping idMapping = (IdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - assertNull(sequenceGenerator.getDefaultSchema()); - - this.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", sequenceGenerator.getDefaultSchema()); - - this.getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", sequenceGenerator.getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", sequenceGenerator.getDefaultSchema()); - - this.getEntityMappings().removePersistentType(0); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - assertEquals("FOO", sequenceGenerator.getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - this.createTestEntityWithSequenceGenerator(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) idMapping.getGeneratorContainer().getSequenceGenerator(); - - sequenceGenerator.setSpecifiedSchema("testSchema"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGenerator2_0Annotation annotation = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals("testSchema", annotation.getSchema()); - - sequenceGenerator.setSpecifiedSchema(null); - assertNull(annotation.getSchema()); - } - - // ********** utility ********** - - protected ICompilationUnit createTestEntityWithSequenceGenerator() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SEQUENCE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@SequenceGenerator(name=\"" + SEQUENCE_GENERATOR_NAME + "\")"); - } - }); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java deleted file mode 100644 index 7f838c690f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/Generic2_0OrmContextModelTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class Generic2_0OrmContextModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(Generic2_0OrmContextModelTests.class.getPackage().getName()); - suite.addTestSuite(GenericOrmAssociationOverride2_0Tests.class); - suite.addTestSuite(GenericOrmCascade2_0Tests.class); - suite.addTestSuite(GenericOrmCollectionTable2_0Tests.class); - suite.addTestSuite(GenericOrmElementCollectionMapping2_0Tests.class); - suite.addTestSuite(GenericOrmEntity2_0Tests.class); - suite.addTestSuite(GenericOrmEmbeddedMapping2_0Tests.class); - suite.addTestSuite(GenericOrmManyToManyMapping2_0Tests.class); - suite.addTestSuite(GenericOrmManyToOneMapping2_0Tests.class); - suite.addTestSuite(GenericOrmOneToManyMapping2_0Tests.class); - suite.addTestSuite(GenericOrmOneToOneMapping2_0Tests.class); - suite.addTestSuite(GenericOrmPersistentAttribute2_0Tests.class); - suite.addTestSuite(GenericOrmPersistentType2_0Tests.class); - suite.addTestSuite(GenericOrmSequenceGenerator2_0Tests.class); - return suite; - } - - private Generic2_0OrmContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java deleted file mode 100644 index 973122f74e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmAssociationOverride2_0Tests.java +++ /dev/null @@ -1,534 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAssociationOverride; -import org.eclipse.jpt.core.context.VirtualJoinTable; -import org.eclipse.jpt.core.context.VirtualJoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.core.jpa2.context.OverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOverrideRelationship2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmAssociationOverride2_0Tests extends Generic2_0ContextModelTestCase -{ - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(CR); - sb.append(" private AnnotationTestTypeChild address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany"); - sb.append(CR); - sb.append(" private java.util.Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public GenericOrmAssociationOverride2_0Tests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride ormVirtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormVirtualAssociationOverride.getName()); - - ormVirtualAssociationOverride.convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = overrideContainer.specifiedOverrides().next(); - - assertEquals("address", ormAssociationOverride.getName()); - assertEquals("address", xmlAssociationOverride.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - assertFalse(entityResource.getAssociationOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - //set name to null in the resource model - xmlAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(overrideContainer.specifiedOverrides().hasNext()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - - assertEquals("address", specifiedAssociationOverride.getName()); - assertEquals("address", xmlAssociationOverride.getName()); - assertTrue(overrideContainer.overrides().hasNext()); - assertFalse(entityResource.getAssociationOverrides().isEmpty()); - - //set name in the context model, verify resource model modified - specifiedAssociationOverride.setName("foo"); - assertEquals("foo", specifiedAssociationOverride.getName()); - assertEquals("foo", xmlAssociationOverride.getName()); - - //set name to null in the context model - specifiedAssociationOverride.setName(null); - assertNull(specifiedAssociationOverride.getName()); - xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - assertNull(xmlAssociationOverride.getName()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - OrmAssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - OrmJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - - JoinColumn joinColumn = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - JoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - JoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - AssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - JoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - assertEquals(1, xmlAssociationOverride.getJoinColumns().size()); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, xmlAssociationOverride.getJoinColumns().size()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, xmlAssociationOverride.getJoinColumns().size()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, xmlAssociationOverride.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - OrmAssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - OrmJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, xmlAssociationOverride.getJoinColumns().size()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride ormAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", ormAssociationOverride.getName()); - - OrmAssociationOverride specifiedOverride = ormAssociationOverride.convertToSpecified(); - OrmJoinColumnRelationshipStrategy joiningStrategy = specifiedOverride.getRelationship().getJoinColumnStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - ListIterator joinColumns = joiningStrategy.specifiedJoinColumns(); - JoinColumn joinColumn = joinColumns.next(); - assertEquals("address_id", joinColumn.getSpecifiedName()); - assertEquals("id", joinColumn.getSpecifiedReferencedColumnName()); - - xmlAssociationOverride.getJoinColumns().add(0, OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinColumns().add(1, OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinColumns().add(2, OrmFactory.eINSTANCE.createXmlJoinColumn()); - - xmlAssociationOverride.getJoinColumns().get(0).setName("FOO"); - xmlAssociationOverride.getJoinColumns().get(1).setName("BAR"); - xmlAssociationOverride.getJoinColumns().get(2).setName("BAZ"); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(2, 0); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(0, 1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(0); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("address_id", joinColumns.next().getName()); - - xmlAssociationOverride.getJoinColumns().remove(0); - assertFalse(joiningStrategy.specifiedJoinColumns().hasNext()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals("AnnotationTestTypeChild", ormEntity.getName()); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next(); - assertTrue(associationOverride.isVirtual()); - } - - - public void testSetJoinTableName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - OrmVirtualAssociationOverride virtualOverride = overrideContainer.virtualOverrides().next(); - OrmAssociationOverride associationOverride = virtualOverride.convertToSpecified(); - ((OverrideRelationship2_0) associationOverride.getRelationship()).setStrategyToJoinTable(); - JoinTableRelationshipStrategy joiningStrategy = ((OverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - - JoinTable joinTable = joiningStrategy.getJoinTable(); - joinTable.setSpecifiedName("FOO"); - - assertEquals("FOO", xmlAssociationOverride.getJoinTable().getName()); - } - - public void testUpdateJoinTable() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - OrmVirtualAssociationOverride virtualOverride = overrideContainer.virtualOverrides().next(); - OrmAssociationOverride associationOverride = virtualOverride.convertToSpecified(); - ((OrmOverrideRelationship2_0) associationOverride.getRelationship()).setStrategyToJoinTable(); - OrmJoinTableRelationshipStrategy joiningStrategy = ((OrmOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - xmlAssociationOverride.getJoinTable().setName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", joiningStrategy.getJoinTable().getSpecifiedName()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinTable().getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - xmlAssociationOverride.getJoinTable().getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().get(0).setName("FOO"); - xmlAssociationOverride.getJoinTable().getJoinColumns().get(1).setName("BAR"); - xmlAssociationOverride.getJoinTable().getJoinColumns().get(2).setName("BAZ"); - - ListIterator joinColumns = joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().move(2, 0); - joinColumns = joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().move(0, 1); - joinColumns = joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().remove(1); - joinColumns = joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().remove(1); - joinColumns = joiningStrategy.getJoinTable().specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinTable().getJoinColumns().remove(0); - assertFalse(joiningStrategy.getJoinTable().specifiedJoinColumns().hasNext()); - } - - public void testDefaultJoinTableName() throws Exception { - createTestMappedSuperclassManyToMany(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ReadOnlyAssociationOverride associationOverride = overrideContainer.virtualOverrides().next(); - VirtualJoinTableRelationshipStrategy joiningStrategy = ((VirtualOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - - VirtualJoinTable joinTable = joiningStrategy.getJoinTable(); - - assertEquals("AnnotationTestTypeChild_AnnotationTestTypeChild", joinTable.getName()); - - - ormEntity.getTable().setSpecifiedName("FOO"); - assertEquals("FOO_FOO", joinTable.getName()); - - PersistentType mappedSuperclass = ormPersistentType.getSuperPersistentType(); - ((OrmReadOnlyPersistentAttribute) mappedSuperclass.getAttributeNamed("address")).convertToSpecified(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) mappedSuperclass.getAttributeNamed("address").getMapping(); - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("BAR"); - assertEquals("BAR", manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java deleted file mode 100644 index 2c02873e67..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCascade2_0Tests.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmCascade2_0Tests extends Generic2_0ContextModelTestCase -{ - public GenericOrmCascade2_0Tests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testUpdateCascadeDetach() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade2_0 cascade = (Cascade2_0) ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isDetach()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeType()); - assertEquals(false, cascade.isDetach()); - assertNotNull(oneToOne.getCascade()); - - //set detach in the resource model, verify context model updated - oneToOne.getCascade().setCascadeDetach(true); - assertEquals(true, cascade.isDetach()); - assertEquals(true, oneToOne.getCascade().isCascadeDetach()); - - //set detach to false in the resource model - oneToOne.getCascade().setCascadeDetach(false); - assertEquals(false, cascade.isDetach()); - assertEquals(false, oneToOne.getCascade().isCascadeDetach()); - } - - public void testModifyCascadeDetach() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade2_0 cascade = (Cascade2_0) ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isDetach()); - assertNull(oneToOne.getCascade()); - - //set detach in the context model, verify resource model updated - cascade.setDetach(true); - assertEquals(true, cascade.isDetach()); - assertEquals(true, oneToOne.getCascade().isCascadeDetach()); - - //set detach to false in the context model - cascade.setDetach(false); - assertEquals(false, cascade.isDetach()); - assertNull(oneToOne.getCascade()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java deleted file mode 100644 index 79e9eade43..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmCollectionTable2_0Tests.java +++ /dev/null @@ -1,753 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.core.jpa2.context.CollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaCollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlCollectionTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlElementCollection_2_0; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmCollectionTable2_0Tests extends Generic2_0ContextModelTestCase -{ - public GenericOrmCollectionTable2_0Tests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityWithValidElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - sb.append(" private Collection projects;").append(CR); - sb.append("@Id").append(CR); - } - }); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = elementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - - - //set name in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setName("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedName()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getName()); - - //set name to null in the resource model - resourceElementCollection.getCollectionTable().setName(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable().getName()); - - resourceElementCollection.getCollectionTable().setName("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedName()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getName()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = elementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set name in the context model, verify resource model modified - ormCollectionTable.setSpecifiedName("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedName()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getName()); - - //set name to null in the context model - ormCollectionTable.setSpecifiedName(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testVirtualCollectionTable() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(TYPE_NAME + "_projects", virtualCollectionTable.getName()); - assertNull(virtualCollectionTable.getSpecifiedCatalog()); - assertNull(virtualCollectionTable.getSpecifiedSchema()); - assertEquals(0, virtualCollectionTable.specifiedJoinColumnsSize()); - JoinColumn virtualJoinColumn = virtualCollectionTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_id", virtualJoinColumn.getDefaultName()); - assertEquals("id", virtualJoinColumn.getDefaultReferencedColumnName()); - - JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) javaPersistentAttribute.getMapping(); - JavaCollectionTable2_0 javaCollectionTable = javaElementCollectionMapping.getCollectionTable(); - javaCollectionTable.setSpecifiedName("FOO"); - javaCollectionTable.setSpecifiedCatalog("CATALOG"); - javaCollectionTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaCollectionTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - - assertEquals("FOO", virtualCollectionTable.getSpecifiedName()); - assertEquals("CATALOG", virtualCollectionTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualCollectionTable.getSpecifiedSchema()); - assertEquals(1, virtualCollectionTable.specifiedJoinColumnsSize()); - virtualJoinColumn = virtualCollectionTable.specifiedJoinColumns().next(); - assertEquals("NAME", virtualJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", virtualJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "projects"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - assertEquals(TYPE_NAME + "_projects", ormCollectionTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).setSpecifiedName("Foo"); - assertEquals("Foo_projects", ormCollectionTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).setSpecifiedName("Bar"); - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove element collection mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("projects"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute2.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - assertTrue(ormPersistentAttribute2.isVirtual()); - assertEquals("JAVA_COLLECTION_TABLE", virtualCollectionTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - javaElementCollectionMapping.getCollectionTable().setSpecifiedName(null); - assertEquals("Bar_projects", virtualCollectionTable.getName()); - assertEquals("Bar_projects", virtualCollectionTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set schema in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setSchema("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getSchema()); - - //set Schema to null in the resource model - resourceElementCollection.getCollectionTable().setSchema(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable().getSchema()); - - resourceElementCollection.getCollectionTable().setSchema("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getSchema()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Schema in the context model, verify resource model modified - ormCollectionTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedSchema()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getSchema()); - - //set Schema to null in the context model - ormCollectionTable.setSpecifiedSchema(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Catalog in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setCatalog("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getCatalog()); - - //set Catalog to null in the resource model - resourceElementCollection.getCollectionTable().setCatalog(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable().getCatalog()); - - resourceElementCollection.getCollectionTable().setCatalog("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getCatalog()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Catalog in the context model, verify resource model modified - ormCollectionTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getCatalog()); - - //set Catalog to null in the context model - ormCollectionTable.setSpecifiedCatalog(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - OrmJoinColumn joinColumn = ormCollectionTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormCollectionTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormCollectionTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - - ListIterator joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - ormCollectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormCollectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormCollectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals(3, resourceCollectionTable.getJoinColumns().size()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(2, resourceCollectionTable.getJoinColumns().size()); - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(1, resourceCollectionTable.getJoinColumns().size()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(0).getName()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, resourceCollectionTable.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - ormCollectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormCollectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormCollectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals(3, resourceCollectionTable.getJoinColumns().size()); - - - ormCollectionTable.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - - - ormCollectionTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - } - - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - resourceCollectionTable.getJoinColumns().get(0).setName("FOO"); - resourceCollectionTable.getJoinColumns().get(1).setName("BAR"); - resourceCollectionTable.getJoinColumns().get(2).setName("BAZ"); - - ListIterator joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().move(2, 0); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().move(0, 1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(0); - assertFalse(ormCollectionTable.specifiedJoinColumns().hasNext()); - } - - public void testUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ListIterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - assertEquals(0, ormCollectionTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormCollectionTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = resourceCollectionTable.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = resourceCollectionTable.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, resourceCollectionTable.getUniqueConstraints().size()); - - ormCollectionTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormCollectionTable.removeUniqueConstraint(1); - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormCollectionTable.removeUniqueConstraint(0); - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, resourceCollectionTable.getUniqueConstraints().size()); - - - ormCollectionTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormCollectionTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(0); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.attributes().next(); - assertTrue(virtualAttribute.isVirtual()); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) virtualAttribute.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - - ListIterator uniqueConstraints = (ListIterator) virtualCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping2_0 = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 javaCollectionTable = javaElementCollectionMapping2_0.getCollectionTable(); - - javaCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = (ListIterator) virtualCollectionTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - virtualAttribute.convertToSpecified(); - - virtualElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentType.attributes().next().getMapping(); - assertEquals(0, virtualElementCollectionMapping.getCollectionTable().uniqueConstraintsSize()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java deleted file mode 100644 index 5ce5814cf4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmElementCollectionMapping2_0Tests.java +++ /dev/null @@ -1,1459 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVirtualAttributeOverride; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlElementCollection; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlElementCollection_2_0; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmElementCollectionMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public GenericOrmElementCollectionMapping2_0Tests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityWithElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection(targetClass=String.class, fetch=FetchType.EAGER)"); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.FETCH_TYPE, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithNonGenericElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericBasicElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createSelfReferentialElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.List elementCollection;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertEquals("oneToOneMapping", ormElementCollectionMapping.getName()); - assertEquals("oneToOneMapping", elementCollection.getName()); - - //set name in the resource model, verify context model updated - elementCollection.setName("newName"); - assertEquals("newName", ormElementCollectionMapping.getName()); - assertEquals("newName", elementCollection.getName()); - - //set name to null in the resource model - elementCollection.setName(null); - assertNull(ormElementCollectionMapping.getName()); - assertNull(elementCollection.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertEquals("oneToOneMapping", ormElementCollectionMapping.getName()); - assertEquals("oneToOneMapping", elementCollection.getName()); - - //set name in the context model, verify resource model updated - ormElementCollectionMapping.setName("newName"); - assertEquals("newName", ormElementCollectionMapping.getName()); - assertEquals("newName", elementCollection.getName()); - - //set name to null in the context model - ormElementCollectionMapping.setName(null); - assertNull(ormElementCollectionMapping.getName()); - assertNull(elementCollection.getName()); - } - - public void testMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormElementCollectionMapping.getName()); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", virtualElementCollectionMapping.getName()); - assertEquals(FetchType.EAGER, virtualElementCollectionMapping.getSpecifiedFetch()); - assertEquals("String", virtualElementCollectionMapping.getSpecifiedTargetClass()); - - ormPersistentAttribute = ormPersistentAttribute.convertToSpecified(); - OrmElementCollectionMapping2_0 specifiedElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", specifiedElementCollectionMapping.getName()); - assertEquals(null, specifiedElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, specifiedElementCollectionMapping.getDefaultFetch()); - assertEquals(null, specifiedElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals(PACKAGE_NAME + ".Address", specifiedElementCollectionMapping.getDefaultTargetClass()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.convertToSpecified(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormElementCollectionMapping.getName()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormElementCollectionMapping.getName()); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - - public void testMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the resource model, verify context model updated - elementCollection.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the resource model - elementCollection.setFetch(null); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, elementCollection.getFetch()); - assertEquals(FetchType.EAGER, ormElementCollectionMapping.getSpecifiedFetch()); - - ormElementCollectionMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, elementCollection.getFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormElementCollectionMapping.setSpecifiedFetch(null); - assertNull(elementCollection.getFetch()); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedTargetClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the resource model, verify context model updated - elementCollection.setTargetClass("newTargetClass"); - assertEquals("newTargetClass", ormElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the resource model - elementCollection.setTargetClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - public void testModifySpecifiedTargetClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedTargetClass("newTargetClass"); - assertEquals("newTargetClass", ormElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the context model - ormElementCollectionMapping.setSpecifiedTargetClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - - public void testGetValueTypeEmbeddable() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeEntity() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeNone() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.NO_TYPE, elementCollectionMapping.getValueType()); - - elementCollectionMapping.setSpecifiedTargetClass("test.Address"); - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeBasic() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualElementCollectionMapping.getSpecifiedMapKey()); - assertNull(virtualElementCollectionMapping.getMapKey()); - assertFalse(virtualElementCollectionMapping.isPkMapKey()); - assertFalse(virtualElementCollectionMapping.isCustomMapKey()); - assertTrue(virtualElementCollectionMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setPkMapKey(true); - assertEquals(null, virtualElementCollectionMapping.getMapKey());//no primary key on an embeddable - assertTrue(virtualElementCollectionMapping.isPkMapKey()); - assertFalse(virtualElementCollectionMapping.isCustomMapKey()); - assertFalse(virtualElementCollectionMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setCustomMapKey(true); - javaElementCollectionMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualElementCollectionMapping.getSpecifiedMapKey()); - assertEquals("city", virtualElementCollectionMapping.getMapKey()); - assertFalse(virtualElementCollectionMapping.isPkMapKey()); - assertTrue(virtualElementCollectionMapping.isCustomMapKey()); - assertFalse(virtualElementCollectionMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany xmlOneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(xmlOneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", xmlOneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertTrue(ormOneToManyMapping.isPkMapKey()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaElementCollectionMapping.setSpecifiedTargetClass("test.Address"); - mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - virtualElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - virtualElementCollectionMapping.setSpecifiedTargetClass("test.Address"); - mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - virtualElementCollectionMapping.setSpecifiedTargetClass("String"); - mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - elementCollection.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNotNull(elementCollection.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - elementCollection.getMapKeyClass().setClassName("String"); - assertEquals("String", ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", elementCollection.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - elementCollection.getMapKeyClass().setClassName(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass().getClassName()); - - elementCollection.getMapKeyClass().setClassName("String"); - elementCollection.setMapKeyClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertEquals("java.lang.String", virtualElementCollectionMapping.getMapKeyClass()); - assertNull(virtualElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualElementCollectionMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", virtualElementCollectionMapping.getMapKeyClass()); - assertEquals("Integer", virtualElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualElementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", elementCollection.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormElementCollectionMapping.setSpecifiedMapKeyClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = (Orderable2_0) elementCollectionMapping.getOrderable(); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = (Orderable2_0) elementCollectionMapping.getOrderable(); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaElementCollectionMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 virtualCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute2.getMapping(); - orderable = (Orderable2_0) virtualCollectionMapping.getOrderable(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(false, orderable.isNoOrdering()); - assertEquals(TYPE_NAME + "_addresses", orderable.getOrderColumn().getTable()); - assertEquals("addresses_ORDER", orderable.getOrderColumn().getName()); - - ((Orderable2_0) javaElementCollectionMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_addresses", orderable.getOrderColumn().getTable()); - assertEquals("FOO", orderable.getOrderColumn().getName()); - } - - public void testVirtualValueColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attrubte in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getValueColumn(); - assertEquals("addresses", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getValueColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getValueColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getValueColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getValueColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getValueColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getValueColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", virtualColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, virtualColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), virtualColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), virtualColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), virtualColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmElementCollectionMapping2_0 addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - OrmColumn ormColumn = addressesVirtualMapping.getValueColumn(); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getValueColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getValueColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getValueColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getValueColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getValueColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getValueColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualValueColumnTable() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getValueColumn(); - - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //entity table should have no affect on the collection table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //set Column table element in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - assertEquals("JAVA_COLLECTION_TABLE", virtualColumn.getTable()); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - virtualColumn = addressesVirtualMapping.getValueColumn(); - assertNull(virtualColumn.getSpecifiedTable()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getDefaultTable()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - elementCollectionResource.getAttributeOverrides().get(0).setName("FOO"); - elementCollectionResource.getAttributeOverrides().get(1).setName("BAR"); - elementCollectionResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, elementCollectionResource.getAttributeOverrides().size()); - - attributeOverrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", elementCollectionResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", elementCollectionResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getAttributeOverrides().get(2).getName()); - - - attributeOverrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", elementCollectionResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", elementCollectionResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - elementCollectionResource.getAttributeOverrides().get(0).setName("FOO"); - elementCollectionResource.getAttributeOverrides().get(1).setName("BAR"); - elementCollectionResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().move(2, 0); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().move(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(0); - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - } - - public void testElementCollectionMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - - assertEquals("foo", ormElementCollectionMapping.getName()); - - - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - assertFalse(attributeOverrideContainer.virtualOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType persistentType3 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmReadOnlyPersistentAttribute ormPersistentAttribute = persistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - ListIterator specifiedAttributeOverrides = (ListIterator) attributeOverrideContainer.specifiedOverrides(); - ReadOnlyAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - ListIterator virtualOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - attributeOverride = virtualOverrides.next(); - assertEquals("state.name", attributeOverride.getName()); - attributeOverride = virtualOverrides.next(); - assertEquals("state.abbr", attributeOverride.getName()); - attributeOverride = virtualOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - Column javaAttributeOverrideColumn = javaElementCollectionMapping.getValueAttributeOverrideContainer().specifiedOverrides().next().getColumn(); - - javaAttributeOverrideColumn.setSpecifiedName("FOO_COLUMN"); - javaAttributeOverrideColumn.setSpecifiedTable("FOO_TABLE"); - javaAttributeOverrideColumn.setColumnDefinition("COLUMN_DEF"); - javaAttributeOverrideColumn.setSpecifiedInsertable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUnique(Boolean.TRUE); - javaAttributeOverrideColumn.setSpecifiedNullable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedLength(Integer.valueOf(5)); - javaAttributeOverrideColumn.setSpecifiedPrecision(Integer.valueOf(6)); - javaAttributeOverrideColumn.setSpecifiedScale(Integer.valueOf(7)); - - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType3.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - specifiedAttributeOverrides = (ListIterator) attributeOverrideContainer.specifiedOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", attributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, attributeOverride.getColumn().isInsertable()); - assertEquals(false, attributeOverride.getColumn().isUpdatable()); - assertEquals(true, attributeOverride.getColumn().isUnique()); - assertEquals(false, attributeOverride.getColumn().isNullable()); - assertEquals(5, attributeOverride.getColumn().getLength()); - assertEquals(6, attributeOverride.getColumn().getPrecision()); - assertEquals(7, attributeOverride.getColumn().getScale()); - - virtualOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - attributeOverride = virtualOverrides.next(); - assertEquals("state.name", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualOverrides.next(); - assertEquals("state.abbr", attributeOverride.getName()); - attributeOverride = virtualOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("addresses").convertToSpecified(); - elementCollectionMapping = (OrmElementCollectionMapping2_0) persistentType.getAttributeNamed("addresses").getMapping(); - attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualOverride.getName()); - assertEquals("MY_STATE_COLUMN", virtualOverride.getColumn().getName()); - assertEquals(TYPE_NAME + "_addresses", virtualOverride.getColumn().getTable()); - assertEquals(null, virtualOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualOverride.getColumn().isInsertable()); - assertEquals(true, virtualOverride.getColumn().isUpdatable()); - assertEquals(false, virtualOverride.getColumn().isUnique()); - assertEquals(true, virtualOverride.getColumn().isNullable()); - assertEquals(255, virtualOverride.getColumn().getLength()); - assertEquals(0, virtualOverride.getColumn().getPrecision()); - assertEquals(0, virtualOverride.getColumn().getScale()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualOverride.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualOverride.getColumn().getDefaultTable()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals("city", attributeOverrideContainer.specifiedOverrides().next().getName()); - virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", virtualColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, virtualColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), virtualColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), virtualColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), virtualColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmElementCollectionMapping2_0 addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //entity table should have no affect on the collection table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //set Column table element in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - assertEquals("JAVA_COLLECTION_TABLE", virtualColumn.getTable()); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - assertNull(virtualColumn.getSpecifiedTable()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getDefaultTable()); - } - - public void testSelfReferentialElementCollectionMapping() throws Exception { - createSelfReferentialElementCollection(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Foo"); - - ElementCollectionMapping2_0 mapping = (ElementCollectionMapping2_0) persistentType.getAttributeNamed("elementCollection").getMapping(); - assertFalse(mapping.allOverridableAttributeMappingNames().hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java deleted file mode 100644 index a73636d180..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEmbeddedMapping2_0Tests.java +++ /dev/null @@ -1,1734 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.context.ReadOnlyJoinColumn; -import org.eclipse.jpt.core.context.ReadOnlyJoinTable; -import org.eclipse.jpt.core.context.ReadOnlyJoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.VirtualJoinColumn; -import org.eclipse.jpt.core.context.VirtualJoinColumnRelationship; -import org.eclipse.jpt.core.context.VirtualJoinColumnRelationshipStrategy; -import org.eclipse.jpt.core.context.VirtualJoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaReadOnlyAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.core.jpa2.context.EmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.ReadOnlyOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.VirtualOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmEmbeddedMapping2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmEmbeddedMapping2_0Tests extends Generic2_0ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - private static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - private static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - public GenericOrmEmbeddedMapping2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityEmbeddedMappingAttributeOverrides() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDED, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded").append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - private void createAddressEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Address {"); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Column(name=\"A_STATE\")").append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress2() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - private void createSelfReferentialEmbedded() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Foo embedded;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// OrmAttributeOverride attributeOverride = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride.setName("FOO"); -// -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// OrmAttributeOverride attributeOverride2 = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride2.setName("BAR"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// OrmAttributeOverride attributeOverride3 = ormEmbeddedMapping.addSpecifiedAttributeOverride(1); -// attributeOverride3.setName("BAZ"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// ormEmbeddedMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedResource.getAttributeOverrides().size()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedResource.getAttributeOverrides().size()); -// } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedResource.getAttributeOverrides().size()); - - attributeOverrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - - - attributeOverrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(2, 0); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(0); - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormEmbeddedMapping.getAttributeOverrideContainer(); - - assertEquals("foo", ormEmbeddedMapping.getName()); - - - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - assertFalse(attributeOverrideContainer.virtualOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmReadOnlyPersistentAttribute ormPersistentAttribute = persistentType.getAttributeNamed("address"); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - ListIterator specifiedAttributeOverrides = (ListIterator) attributeOverrideContainer.specifiedOverrides(); - ReadOnlyAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaEmbeddedMapping javaEmbeddedMapping = (JavaEmbeddedMapping) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - Column javaAttributeOverrideColumn = javaEmbeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next().getColumn(); - - javaAttributeOverrideColumn.setSpecifiedName("FOO_COLUMN"); - javaAttributeOverrideColumn.setSpecifiedTable("FOO_TABLE"); - javaAttributeOverrideColumn.setColumnDefinition("COLUMN_DEF"); - javaAttributeOverrideColumn.setSpecifiedInsertable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUnique(Boolean.TRUE); - javaAttributeOverrideColumn.setSpecifiedNullable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedLength(Integer.valueOf(5)); - javaAttributeOverrideColumn.setSpecifiedPrecision(Integer.valueOf(6)); - javaAttributeOverrideColumn.setSpecifiedScale(Integer.valueOf(7)); - - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType2.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - specifiedAttributeOverrides = (ListIterator) attributeOverrideContainer.specifiedOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", attributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, attributeOverride.getColumn().isInsertable()); - assertEquals(false, attributeOverride.getColumn().isUpdatable()); - assertEquals(true, attributeOverride.getColumn().isUnique()); - assertEquals(false, attributeOverride.getColumn().isNullable()); - assertEquals(5, attributeOverride.getColumn().getLength()); - assertEquals(6, attributeOverride.getColumn().getPrecision()); - assertEquals(7, attributeOverride.getColumn().getScale()); - - virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").convertToSpecified(); - embeddedMapping = (OrmEmbeddedMapping) persistentType.getAttributeNamed("address").getMapping(); - attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - ReadOnlyAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualOverride.getName()); - assertEquals("city", virtualOverride.getColumn().getName()); - assertEquals(TYPE_NAME, virtualOverride.getColumn().getTable()); - assertEquals(null, virtualOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualOverride.getColumn().isInsertable()); - assertEquals(true, virtualOverride.getColumn().isUpdatable()); - assertEquals(false, virtualOverride.getColumn().isUnique()); - assertEquals(true, virtualOverride.getColumn().isNullable()); - assertEquals(255, virtualOverride.getColumn().getLength()); - assertEquals(0, virtualOverride.getColumn().getPrecision()); - assertEquals(0, virtualOverride.getColumn().getScale()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualOverride.getName()); - assertEquals("MY_STATE_COLUMN", virtualOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, virtualOverride.getColumn().getDefaultTable()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals("id", attributeOverrideContainer.specifiedOverrides().next().getName()); - virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - EmbeddedMapping virtualEmbeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - AttributeOverrideContainer attributeOverrideContainer = virtualEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals("address", virtualEmbeddedMapping.getName()); - - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - ListIterator specifiedAttributeOverrides = (ListIterator) attributeOverrideContainer.specifiedOverrides(); - - ReadOnlyAttributeOverride override = specifiedAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, override.getName()); - ReadOnlyColumn column = override.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getSpecifiedName()); - - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - override = virtualAttributeOverrides.next(); - assertEquals("id", override.getName()); - column = override.getColumn(); - assertEquals("id", column.getName()); - - override = virtualAttributeOverrides.next(); - assertEquals("state", override.getName()); - column = override.getColumn(); - assertEquals("A_STATE", column.getName()); - - override = virtualAttributeOverrides.next(); - assertEquals("zip", override.getName()); - column = override.getColumn(); - assertEquals("zip", column.getName()); - - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - EmbeddedMapping virtualEmbeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", virtualEmbeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator ormAttributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedMapping.getName()); - - assertEquals(0, ormEmbeddedMapping.getAttributeOverrideContainer().specifiedOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator ormAttributeOverrides = ormEmbeddedMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - - - public void testEmbeddedMorphToIdMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToEmbeddedIdMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedIdMapping) ormPersistentAttribute.getMapping()).getAttributeOverrideContainer().specifiedOverrides().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedMappingAttributeOverrides(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - AttributeOverride attributeOverride = embeddedMapping.getAttributeOverrideContainer().specifiedOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - - OrmAssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - ListIterator specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - //add an annotation to the resource model and verify the context model is updated - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(associationOverride); - associationOverride.setName("FOO"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(1, associationOverride); - associationOverride.setName("BAR"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(0, associationOverride); - associationOverride.setName("BAZ"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - embeddedResource.getAssociationOverrides().move(1, 0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - embeddedResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - VirtualJoinColumnRelationshipStrategy joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - VirtualJoinColumn virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("address_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - - JavaPersistentType javaEmbeddable = getPersistenceUnit().specifiedClassRefs().next().getJavaPersistentType(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) javaEmbeddable.getAttributeNamed("address").getMapping(); - JoinColumn joinColumn = oneToOneMapping.getRelationship().getJoinColumnStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - joiningStrategy = ((VirtualJoinColumnRelationship) virtualAssociationOverride.getRelationship()).getJoinColumnStrategy(); - assertEquals("address", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals("MY_JOIN_COLUMN", joiningStrategy.joinColumns().next().getName()); - - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - //add an annotation to the resource model and verify the context model is updated - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(associationOverride); - associationOverride.setName("FOO"); - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(0, associationOverride); - associationOverride.setName("BAR"); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.overridesSize()); - - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(associationOverride); - associationOverride.setName("bar"); - assertEquals(3, overrideContainer.overridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("address", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", embeddedResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals(1, embeddedResource.getAssociationOverrides().size()); - - Iterator associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("addresses", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - assertEquals(0, embeddedResource.getAssociationOverrides().size()); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - assertEquals(2, embeddedResource.getAssociationOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("addresses", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", embeddedResource.getAssociationOverrides().get(1).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("addresses", associationOverrides.next().getName()); - - assertEquals("address", embeddedResource.getAssociationOverrides().get(0).getName()); - assertEquals("addresses", embeddedResource.getAssociationOverrides().get(1).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - XmlEmbedded embeddedResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - XmlAssociationOverride associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(0, associationOverride); - associationOverride.setName("FOO"); - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(1, associationOverride); - associationOverride.setName("BAR"); - associationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - embeddedResource.getAssociationOverrides().add(2, associationOverride); - associationOverride.setName("BAZ"); - - ListIterator associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().move(2, 0); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().move(0, 1); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(1); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(1); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - embeddedResource.getAssociationOverrides().remove(0); - associationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideJoinTableDefaults() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - createAddressEntity(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME_ + "Address"); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "myEmbedded"); - OrmEmbeddedMapping2_0 embeddedMapping = (OrmEmbeddedMapping2_0) ormPersistentAttribute.getMapping(); - AssociationOverrideContainer overrideContainer = embeddedMapping.getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = CollectionTools.get(overrideContainer.virtualOverrides(), 1); - VirtualJoinTableRelationshipStrategy joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - ReadOnlyJoinTable joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals("AnnotationTestType_Address", joinTable.getName()); - assertEquals(1, joinTable.joinColumnsSize()); - ReadOnlyJoinColumn virtualJoinColumn = joinTable.joinColumns().next(); - assertEquals("AnnotationTestType_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - ReadOnlyJoinColumn virtualInverseJoinColumn = joinTable.inverseJoinColumns().next(); - assertEquals("addresses_id", virtualInverseJoinColumn.getName()); - assertEquals("id", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("AnnotationTestType_Address", virtualInverseJoinColumn.getTable()); - assertEquals(null, virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(true, virtualInverseJoinColumn.isInsertable()); - assertEquals(true, virtualInverseJoinColumn.isUpdatable()); - assertEquals(false, virtualInverseJoinColumn.isUnique()); - assertEquals(true, virtualInverseJoinColumn.isNullable()); - - JavaPersistentType javaEmbeddable = getPersistenceUnit().specifiedClassRefs().next().getJavaPersistentType(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) javaEmbeddable.getAttributeNamed("addresses").getMapping(); - JoinTableRelationshipStrategy joinTableStrategy = oneToManyMapping.getRelationship().getJoinTableStrategy(); - joinTableStrategy.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = joinTableStrategy.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - JoinColumn inverseJoinColumn = joinTableStrategy.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("MY_INVERSE_JOIN_COLUMN"); - inverseJoinColumn.setSpecifiedReferencedColumnName("MY_INVERSE_REFERENCE_COLUMN"); - inverseJoinColumn.setSpecifiedTable("INVERSE_BAR"); - inverseJoinColumn.setColumnDefinition("INVERSE_COLUMN_DEF"); - inverseJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - inverseJoinColumn.setSpecifiedUnique(Boolean.TRUE); - inverseJoinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = CollectionTools.get(overrideContainer.virtualOverrides(), 1); - joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals(1, joinTable.joinColumnsSize()); - virtualJoinColumn = joinTable.joinColumns().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - virtualInverseJoinColumn = joinTable.inverseJoinColumns().next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - assertEquals("INVERSE_COLUMN_DEF", virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(false, virtualInverseJoinColumn.isInsertable()); - assertEquals(false, virtualInverseJoinColumn.isUpdatable()); - assertEquals(true, virtualInverseJoinColumn.isUnique()); - assertEquals(false, virtualInverseJoinColumn.isNullable()); - - - //add the java association override and make sure the settings are not used in determining the association override defaults in the specified orm embedded mapping - JavaEmbeddedMapping2_0 javaEmbeddedMapping = (JavaEmbeddedMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - ListIterator javaAssociationOverrides = javaEmbeddedMapping.getAssociationOverrideContainer().overrides(); - javaAssociationOverrides.next(); - JavaAssociationOverride javaAssociationOverride = ((JavaVirtualAssociationOverride) javaAssociationOverrides.next()).convertToSpecified(); - assertEquals("addresses", javaAssociationOverride.getName()); - JavaJoinTable javaJoinTable = ((JavaOverrideRelationship2_0) javaAssociationOverride.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("JAVA_FOO"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("JAVA_JOIN_COLUMN_NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("JAVA_JOIN_COLUMN_REFERENCED_NAME"); - JavaJoinColumn javaInverseJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - javaInverseJoinColumn.setSpecifiedName("JAVA_INVERSE_JOIN_COLUMN_NAME"); - javaInverseJoinColumn.setSpecifiedReferencedColumnName("JAVA_INVERSE_JOIN_COLUMN_REFERENCED_NAME"); - - - - assertEquals(2, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = CollectionTools.get(overrideContainer.virtualOverrides(), 1); - joiningStrategy = ((VirtualOverrideRelationship2_0) virtualAssociationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = joiningStrategy.getJoinTable(); - assertEquals("addresses", virtualAssociationOverride.getName()); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals(1, joinTable.joinColumnsSize()); - virtualJoinColumn = joinTable.joinColumns().next(); - - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - virtualInverseJoinColumn = joinTable.inverseJoinColumns().next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - assertEquals("INVERSE_COLUMN_DEF", virtualInverseJoinColumn.getColumnDefinition()); - assertEquals(false, virtualInverseJoinColumn.isInsertable()); - assertEquals(false, virtualInverseJoinColumn.isUpdatable()); - assertEquals(true, virtualInverseJoinColumn.isUnique()); - assertEquals(false, virtualInverseJoinColumn.isNullable()); - - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - - ormPersistentAttribute.convertToVirtual(); - EmbeddedMapping2_0 virtualEmbeddedMapping = (EmbeddedMapping2_0) ormPersistentType.getAttributeNamed("myEmbedded").getMapping(); - overrideContainer = virtualEmbeddedMapping.getAssociationOverrideContainer(); - AssociationOverride associationOverride = overrideContainer.specifiedOverrides().next(); - assertEquals("addresses", associationOverride.getName()); - ReadOnlyJoinTableRelationshipStrategy strategy = ((ReadOnlyOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy(); - joinTable = strategy.getJoinTable(); - assertEquals("JAVA_FOO", joinTable.getName()); - assertEquals(2, joinTable.joinColumnsSize()); - ListIterator joinColumns = (ListIterator) joinTable.joinColumns(); - virtualJoinColumn = joinColumns.next(); - assertEquals("JAVA_JOIN_COLUMN_NAME", virtualJoinColumn.getName()); - assertEquals("JAVA_JOIN_COLUMN_REFERENCED_NAME", virtualJoinColumn.getReferencedColumnName()); - assertEquals("JAVA_FOO", virtualJoinColumn.getTable()); - virtualJoinColumn = joinColumns.next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - - assertEquals(2, joinTable.inverseJoinColumnsSize()); - ListIterator inverseJoinColumns = (ListIterator) joinTable.inverseJoinColumns(); - virtualInverseJoinColumn = inverseJoinColumns.next(); - assertEquals("JAVA_INVERSE_JOIN_COLUMN_NAME", virtualInverseJoinColumn.getName()); - assertEquals("JAVA_INVERSE_JOIN_COLUMN_REFERENCED_NAME", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("JAVA_FOO", virtualInverseJoinColumn.getTable()); - virtualInverseJoinColumn = inverseJoinColumns.next(); - assertEquals("MY_INVERSE_JOIN_COLUMN", virtualInverseJoinColumn.getName()); - assertEquals("MY_INVERSE_REFERENCE_COLUMN", virtualInverseJoinColumn.getReferencedColumnName()); - assertEquals("INVERSE_BAR", virtualInverseJoinColumn.getTable()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress2(); - createTestEmbeddableZipCode(); - - OrmPersistentType customerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - customerPersistentType.getAttributeNamed("address").convertToSpecified(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(5, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("Customer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = (ListIterator) nestedAttributeOverrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - virtualAttributeOverride = (VirtualAttributeOverride) ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getOverrideNamed("zipCode.plusfour"); - assertEquals("zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testSelfReferentialEmbeddedMapping() throws Exception { - createSelfReferentialEmbedded(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Foo"); - - EmbeddedMapping2_0 embeddedMapping = (EmbeddedMapping2_0) persistentType.getAttributeNamed("embedded").getMapping(); - assertFalse(embeddedMapping.allOverridableAttributeMappingNames().hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java deleted file mode 100644 index d80f2b7fb9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmEntity2_0Tests.java +++ /dev/null @@ -1,1972 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmVirtualAttributeOverride; -import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.core.jpa2.context.LockModeType2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOverrideRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmNamedQuery2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlAssociationOverride_2_0; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmEntity2_0Tests extends Generic2_0ContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public GenericOrmEntity2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestMappedSuperclassCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - private void createTestMappedSuperclassCustomerWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEntityLongTimeCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("LongTimeCustomer extends Customer "); - sb.append("{}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "LongTimeCustomer.java", sourceWriter); - } - - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - private LockModeType2_0 lockModeOf(XmlNamedQuery resourceQuery) { - return resourceQuery == null ? null : LockModeType2_0.fromOrmResourceModel(resourceQuery.getLockMode()); - } - - public void testAddNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - OrmNamedQuery2_0 namedQuery = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(0); - namedQuery.setName("FOO"); - namedQuery.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - XmlNamedQuery resourceQuery = entityResource.getNamedQueries().get(0); - assertEquals("FOO", resourceQuery.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(resourceQuery)); - - OrmNamedQuery2_0 namedQuery2 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.READ); - - resourceQuery = entityResource.getNamedQueries().get(0); - assertEquals("BAR", resourceQuery.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(resourceQuery)); - assertEquals("FOO", entityResource.getNamedQueries().get(1).getName()); - - OrmNamedQuery2_0 namedQuery3 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - namedQuery3.setSpecifiedLockMode(LockModeType2_0.WRITE); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - resourceQuery = entityResource.getNamedQueries().get(1); - assertEquals("BAZ", resourceQuery.getName()); - assertEquals(LockModeType2_0.WRITE, this.lockModeOf(resourceQuery)); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - ListIterator namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedQuery(0).setName("FOO"); - OrmNamedQuery2_0 namedQuery1 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.READ); - - OrmNamedQuery2_0 namedQuery2 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(2); - namedQuery2.setName("BAZ"); - namedQuery2.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(2, entityResource.getNamedQueries().size()); - XmlNamedQuery xmlQuery0 = entityResource.getNamedQueries().get(0); - assertEquals("BAR", xmlQuery0.getName()); - assertEquals(LockModeType2_0.READ, this.lockModeOf(xmlQuery0)); - - XmlNamedQuery xmlQuery1 = entityResource.getNamedQueries().get(1); - assertEquals("BAZ", xmlQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery1)); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(1, entityResource.getNamedQueries().size()); - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - xmlQuery0 = entityResource.getNamedQueries().get(0); - assertEquals("BAZ", xmlQuery0.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery0)); - - ormEntity.getQueryContainer().removeNamedQuery(0); - assertEquals(0, entityResource.getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.getQueryContainer().addNamedQuery(0).setName("FOO"); - OrmNamedQuery2_0 namedQuery1 = (OrmNamedQuery2_0) ormEntity.getQueryContainer().addNamedQuery(1); - namedQuery1.setName("BAR"); - namedQuery1.setSpecifiedLockMode(LockModeType2_0.OPTIMISTIC); - ormEntity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - - ormEntity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator namedQueries = ormEntity.getQueryContainer().namedQueries(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - XmlNamedQuery xmlQuery0 = entityResource.getNamedQueries().get(0); - assertEquals("BAR", xmlQuery0.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery0)); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - - ormEntity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAR", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - XmlNamedQuery xmlQuery1 = entityResource.getNamedQueries().get(1); - assertEquals("BAR", xmlQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, this.lockModeOf(xmlQuery1)); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, ormEntity.getPersistenceUnit().queriesSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().get(0).setName("FOO"); - entityResource.getNamedQueries().get(1).setName("BAR"); - XmlNamedQuery xmlQuery = entityResource.getNamedQueries().get(2); - xmlQuery.setName("BAZ"); - xmlQuery.setLockMode(org.eclipse.jpt.core.resource.orm.v2_0.LockModeType_2_0.OPTIMISTIC); - - ListIterator namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - OrmNamedQuery2_0 namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedQueries().move(2, 0); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().move(0, 1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.getQueryContainer().namedQueries(); - namedQuery1 = (OrmNamedQuery2_0) namedQueries.next(); - assertEquals("BAZ", namedQuery1.getName()); - assertEquals(LockModeType2_0.OPTIMISTIC, namedQuery1.getLockMode()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, ormEntity.getPersistenceUnit().queriesSize()); - - entityResource.getNamedQueries().remove(0); - assertFalse(ormEntity.getQueryContainer().namedQueries().hasNext()); - assertEquals(0, ormEntity.getPersistenceUnit().queriesSize()); - } - - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributes = entity.overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = entity.overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributeNames = entity.overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = entity.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributes = ormEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - OrmEntity abstractEntity = (OrmEntity) ormEntity.getParentEntity(); - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociations = ormEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - OrmEntity abstractEntity = (OrmEntity) ormEntity.getParentEntity(); - overridableAssociations = abstractEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } -//TODO -// public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { -// createTestMappedSuperclass(); -// createTestSubType(); -// addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); -// getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// Iterator overridableAttributes = getJavaEntity().allOverridableAttributes(); -// assertEquals("id", overridableAttributes.next().getName()); -// assertEquals("name", overridableAttributes.next().getName()); -// assertEquals("foo", overridableAttributes.next().getName()); -// assertFalse(overridableAttributes.hasNext()); -// } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributeNames = ormEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertEquals("foo", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().add(1, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("BAZ"); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().move(1, 0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testDefaultAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) ormEntity.getPersistentType().getSuperPersistentType().getMapping(); - - mappedSuperclass.getPersistentType().getAttributeNamed("id").convertToSpecified(); - BasicMapping idMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testDefaultAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - OrmEntity superclass = (OrmEntity) ormEntity.getParentEntity(); - - superclass.getPersistentType().getAttributeNamed("id").convertToSpecified(); - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("BAR"); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testDefaultAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("bar"); - assertEquals(4, overrideContainer.overridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("id", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("name", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getAttributeOverrides().size()); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("foo", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - - Iterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - assertEquals("foo", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals(1, entityResource.getAttributeOverrides().size()); - - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - assertEquals(0, entityResource.getAttributeOverrides().size()); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals(3, entityResource.getAttributeOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("foo", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(2).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - assertEquals("foo", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("name", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().add(1, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().add(2, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(2, 0); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(0, 1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociationNames = entity.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -// //TODO add all mapping types to the mapped superclass to test which ones are overridable - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociationNames = ormEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociationNames.next()); - assertEquals("address2", overridableAssociationNames.next()); - assertEquals("address3", overridableAssociationNames.next()); - assertEquals("address4", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociations() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociations = ormEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - XmlAssociationOverride xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(0, xmlAssociationOverride); - xmlAssociationOverride.setName("FOO"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(1, xmlAssociationOverride); - xmlAssociationOverride.setName("BAR"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(0, xmlAssociationOverride); - xmlAssociationOverride.setName("BAZ"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - entityResource.getAssociationOverrides().move(1, 0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testDefaultAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(FULLY_QUALIFIED_SUB_TYPE_NAME, entityResource.getClassName()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - -// -// //MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); -// //BasicMapping idMapping = (BasicMapping) mappedSuperclass.persistentType().attributeNamed("id").getMapping(); -// //idMapping.getColumn().setSpecifiedName("FOO"); -// //idMapping.getColumn().setSpecifiedTable("BAR"); -// -// assertEquals(SUB_TYPE_NAME, entityResource.getName()); -// assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); -// assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - -// //idMapping.getColumn().setSpecifiedName(null); -// //idMapping.getColumn().setSpecifiedTable(null); -// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -// assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); -// assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - //add to the resource model and verify the context model is updated - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("BAR"); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testDefaultAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("bar"); - assertEquals(5, overrideContainer.overridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("address", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address2", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, entityResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, entityResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(2, entityResource.getAssociationOverrides().size()); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals(1, entityResource.getAssociationOverrides().size()); - - Iterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - assertEquals(0, entityResource.getAssociationOverrides().size()); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(2, entityResource.getAssociationOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", entityResource.getAssociationOverrides().get(1).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("address2", associationOverrides.next().getName()); - - assertEquals("address", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address2", entityResource.getAssociationOverrides().get(1).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().add(1, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().add(2, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(2, 0); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAttributeOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - OrmAttributeOverride specifiedAttributeOverride = ((OrmVirtualAttributeOverride) ((OrmEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - public void testNestedVirtualAttributeOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - OrmPersistentType customerPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAttributeOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - OrmAttributeOverride specifiedAttributeOverride = ((OrmVirtualAttributeOverride) ((OrmEmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAssociationOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testNestedVirtualAssociationOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAssociationOverrideContainer overrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, overrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testSetSpecifiedCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, entityResource.getCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, entityResource.getCacheable()); - - cacheable.setSpecifiedCacheable(null); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - } - - public void testGetSpecifiedCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - - entityResource.setCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, entityResource.getCacheable()); - - entityResource.setCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, entityResource.getCacheable()); - - entityResource.setCacheable(null); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - } - - public void testIsDefaultCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - assertEquals(SharedCacheMode.UNSPECIFIED, persistenceUnit2_0.getSharedCacheMode()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromSuperType() throws Exception { - createTestEntity(); - createTestSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subOrmPersistentType.getMapping()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromJava() throws Exception { - createTestEntity(); - createTestSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subOrmPersistentType.getMapping()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - - Cacheable2_0 javaCacheable = ((CacheableHolder2_0) ormPersistentType.getJavaPersistentType().getMapping()).getCacheable(); - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = (PersistenceUnit2_0) getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - //This is a test for bug 301892 - public void testAssociationOverrideJoinTableUpdate() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity resourceEntity = getXmlEntityMappings().getEntities().get(0); - - XmlAssociationOverride_2_0 resourceAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - resourceEntity.getAssociationOverrides().add((XmlAssociationOverride) resourceAssociationOverride); - ((XmlAssociationOverride) resourceAssociationOverride).setName("a"); - - OrmAssociationOverride associationOverride = entity.getAssociationOverrideContainer().specifiedOverrides().next(); - assertEquals("a", associationOverride.getName()); - - XmlJoinTable resourceJoinTable = OrmFactory.eINSTANCE.createXmlJoinTable(); - resourceAssociationOverride.setJoinTable(resourceJoinTable); - resourceJoinTable.setName("FOO"); - XmlJoinColumn resourceJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumn(); - resourceJoinTable.getInverseJoinColumns().add(resourceJoinColumn); - resourceJoinColumn.setName("BAR"); - - associationOverride = entity.getAssociationOverrideContainer().specifiedOverrides().next(); - assertEquals("a", associationOverride.getName()); - JoinTable joinTable = ((OrmOverrideRelationship2_0) associationOverride.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("BAR", joinTable.inverseJoinColumns().next().getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java deleted file mode 100644 index 655f7cd03a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java +++ /dev/null @@ -1,939 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmManyToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmManyToManyMapping2_0Tests(String name) { - super(name); - } - - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNotNull(manyToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKey().setName(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey().getName()); - - manyToMany.getMapKey().setName("myMapKey"); - manyToMany.setMapKey(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualManyToManyMapping.getSpecifiedMapKey()); - assertNull(virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertTrue(virtualManyToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setPkMapKey(true); - assertEquals("id", virtualManyToManyMapping.getMapKey()); - assertTrue(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setCustomMapKey(true); - javaManyToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualManyToManyMapping.getSpecifiedMapKey()); - assertEquals("city", virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertTrue(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany xmlManyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(xmlManyToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", xmlManyToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setSpecifiedMapKey(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(xmlManyToMany.getMapKey().getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - - Iterator mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - virtualManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - virtualManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - virtualManyToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNotNull(manyToMany.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKeyClass().setClassName("String"); - assertEquals("String", ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", manyToMany.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKeyClass().setClassName(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass().getClassName()); - - manyToMany.getMapKeyClass().setClassName("String"); - manyToMany.setMapKeyClass(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping2_0 virtualManyToManyMapping = (ManyToManyMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertEquals("java.lang.String", virtualManyToManyMapping.getMapKeyClass()); - assertNull(virtualManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualManyToManyMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", virtualManyToManyMapping.getMapKeyClass()); - assertEquals("Integer", virtualManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualManyToManyMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", manyToMany.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType printQueuePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - OrmPersistentAttribute jobsPersistentAttribute = printQueuePersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmManyToManyMapping jobsMapping = (OrmManyToManyMapping) jobsPersistentAttribute.getMapping(); - jobsMapping.getRelationship().setStrategyToMappedBy(); - jobsMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("queues"); - - OrmPersistentType printJobPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute queuesPersistentAttribute = printJobPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "queues"); - OrmManyToManyMapping queuesMapping = (OrmManyToManyMapping) queuesPersistentAttribute.getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - OrderColumn2_0 jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - OrderColumn2_0 queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - - jobsOrderable.setOrderColumnOrdering(true); - jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(null, jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderable.setOrderColumnOrdering(true); - queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(null, queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - jobsOrderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderColumn.setSpecifiedName("BAR"); - assertEquals("BAR", queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - assertEquals("MY_TABLE_PrintQueue", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printQueuePersistentType.getMapping()).getTable().setSpecifiedName("OTHER_TABLE"); - assertEquals("MY_TABLE_OTHER_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_OTHER_TABLE", queuesOrderColumn.getTable()); - - queuesMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_JOIN_TABLE", queuesOrderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType printQueuePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - OrmPersistentAttribute jobsPersistentAttribute = printQueuePersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmManyToManyMapping jobsMapping = (OrmManyToManyMapping) jobsPersistentAttribute.getMapping(); - - OrmPersistentType printJobPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute queuesPersistentAttribute = printJobPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "queues"); - OrmManyToManyMapping queuesMapping = (OrmManyToManyMapping) queuesPersistentAttribute.getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - JavaManyToManyMapping javaJobsManyToManyMapping = (JavaManyToManyMapping) jobsPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaJobsManyToManyMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - jobsPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute jobsPersistentAttribute2 = printQueuePersistentType.getAttributeNamed("jobs"); - ManyToManyMapping virtualJobsMapping = (ManyToManyMapping) jobsPersistentAttribute2.getMapping(); - jobsOrderable = ((Orderable2_0) virtualJobsMapping.getOrderable()); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(false, jobsOrderable.isNoOrdering()); - assertEquals("PrintJob_PrintQueue", jobsOrderable.getOrderColumn().getTable()); - assertEquals("jobs_ORDER", jobsOrderable.getOrderColumn().getName()); - queuesPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute queuesPersistentAttribute2 = printJobPersistentType.getAttributeNamed("queues"); - ManyToManyMapping virtualQueuesMapping = (ManyToManyMapping) queuesPersistentAttribute2.getMapping(); - queuesOrderable = ((Orderable2_0) virtualQueuesMapping.getOrderable()); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(false, queuesOrderable.isNoOrdering()); - assertEquals("PrintJob_PrintQueue", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - - ((Orderable2_0) javaJobsManyToManyMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals("PrintJob_PrintQueue", jobsOrderable.getOrderColumn().getTable()); - assertEquals("FOO", jobsOrderable.getOrderColumn().getName()); - assertEquals("PrintJob_PrintQueue", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - - JavaManyToManyMapping javaQueuesManyToManyMapping = (JavaManyToManyMapping) queuesPersistentAttribute.getJavaPersistentAttribute().getMapping(); - javaQueuesManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JOIN_TABLE"); - assertEquals("JOIN_TABLE", jobsOrderable.getOrderColumn().getTable()); - assertEquals("FOO", jobsOrderable.getOrderColumn().getName()); - assertEquals("JOIN_TABLE", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany(mappedBy=\"queues\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List queues;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - ManyToManyMapping2_0 addressesVirtualMapping = (ManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", ormColumn.getName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertTrue(ormColumn.isInsertable()); - assertTrue(ormColumn.isUpdatable()); - assertTrue(ormColumn.isNullable()); - assertFalse(ormColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getScale()); - - //set Column annotation in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaManyToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", ormColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), ormColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmManyToManyMapping2_0 addressesVirtualMapping = (OrmManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaManyToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ManyToManyMapping2_0 addressesVirtualMapping = (ManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column column = addressesVirtualMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_Address", column.getTable()); - - //entity table changes the join table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE_Address", column.getTable()); - - //set Column table element in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - assertEquals("JAVA_JOIN_TABLE", column.getTable()); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", column.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - column = addressesVirtualMapping.getMapKeyColumn(); - assertNull(column.getSpecifiedTable()); - assertEquals("ORM_TABLE_Address", column.getDefaultTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) virtualAttribute.getMapping(); - assertEquals("address", virtualManyToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualManyToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) virtualManyToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(virtualManyToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - OrmReadOnlyPersistentAttribute ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch()); - assertEquals("test.Address", ormManyToManyMapping.getTargetEntity()); - assertNull(ormManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) ormManyToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java deleted file mode 100644 index f8949c5f54..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java +++ /dev/null @@ -1,674 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedIdentity2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlDerivedId_2_0; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapsId_2_0; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmManyToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmManyToOneMapping2_0Tests(String name) { - super(name); - } - - - private void createTestEntityWithIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEntityWithManyToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId("foo"); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(Boolean.TRUE); - assertNotNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute contextAttribute = (OrmPersistentAttribute) contextType.getAttributeNamed("manyToOne"); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - - XmlManyToOne resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - resourceManyToOne.setMapsId("foo"); - assertNull(resourceManyToOne.getId()); - assertFalse(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceManyToOne.getMapsId()); - assertEquals("foo", ((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - XmlOneToOne resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - assertNull(resourceOneToOne.getId()); - assertFalse(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceOneToOne.getMapsId()); - assertEquals("foo", ((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - assertNull(resourceManyToOne.getId()); - assertFalse(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceManyToOne.getMapsId()); - assertEquals("foo", ((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidManyToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - JavaManyToOneMapping2_0 javaManyToOneMapping = ((JavaManyToOneMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping()); - ManyToOneMapping2_0 virtualManyToOneMapping = (ManyToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - JoinTable virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, virtualJoinTable.getSpecifiedName()); - - createTestTargetEntityAddress(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - assertEquals(TYPE_NAME + "_Address", virtualJoinTable.getName()); - assertNull(virtualJoinTable.getSpecifiedCatalog()); - assertNull(virtualJoinTable.getSpecifiedSchema()); - assertEquals(0, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(0, virtualJoinTable.specifiedInverseJoinColumnsSize()); - JoinColumn virtualJoinColumn = virtualJoinTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_Address", virtualJoinColumn.getDefaultTable()); - assertEquals(TYPE_NAME + "_id", virtualJoinColumn.getDefaultName()); - assertEquals("id", virtualJoinColumn.getDefaultReferencedColumnName()); - JoinColumn virtualInverseJoinColumn = virtualJoinTable.getDefaultInverseJoinColumn(); - assertEquals(TYPE_NAME + "_Address", virtualInverseJoinColumn.getDefaultTable()); - assertEquals("address_id", virtualInverseJoinColumn.getDefaultName()); - assertEquals("id", virtualInverseJoinColumn.getDefaultReferencedColumnName()); - - JavaJoinTable javaJoinTable = ((JavaManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", virtualJoinTable.getSpecifiedName()); - assertEquals("CATALOG", virtualJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualJoinTable.getSpecifiedSchema()); - assertEquals(1, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(1, virtualJoinTable.specifiedInverseJoinColumnsSize()); - virtualJoinColumn = virtualJoinTable.specifiedJoinColumns().next(); - assertEquals("NAME", virtualJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", virtualJoinColumn.getSpecifiedReferencedColumnName()); - virtualInverseJoinColumn = virtualJoinTable.specifiedInverseJoinColumns().next(); - assertEquals("INVERSE_NAME", virtualInverseJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", virtualInverseJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidManyToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - OrmManyToOneMapping2_0 ormManyToOneMapping = (OrmManyToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((ManyToOneRelationship2_0) ormManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - OrmJoinTable ormJoinTable = ((OrmManyToOneRelationship2_0) ormManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTestTargetEntityAddress(); - OrmPersistentType targetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - JavaManyToOneMapping2_0 javaManyToOneMapping = (JavaManyToOneMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("address").getMapping(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - ManyToOneMapping2_0 virtualManyToOneMapping = (ManyToOneMapping2_0) virtualPersistentAttribute.getMapping(); - JoinTable virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertTrue(virtualPersistentAttribute.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", virtualJoinTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().removeStrategy(); - virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(virtualJoinTable); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - virtualJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(virtualJoinTable.getSpecifiedName()); - assertEquals("BAR_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", virtualJoinTable.getDefaultName()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmManyToOneRelationship2_0 rel = (OrmManyToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmManyToOneRelationship2_0 rel = (OrmManyToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToOneMapping virtualManyToOneMapping = (ManyToOneMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualManyToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualManyToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualManyToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualManyToOneMapping.getSpecifiedTargetEntity()); - - JoinColumn virtualJoinColumn = virtualManyToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", virtualJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", virtualJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, virtualJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", virtualJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", virtualJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) virtualManyToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - OrmPersistentAttribute ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch()); - assertEquals(true, ormManyToOneMapping.isDefaultOptional()); - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - Cascade2_0 cascade = (Cascade2_0) ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java deleted file mode 100644 index 62d47e4888..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java +++ /dev/null @@ -1,1230 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToManyRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.OrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmOneToManyMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmOneToManyMapping2_0Tests(String name) { - super(name); - } - - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityWithValidOneToManyMapping() throws Exception { - this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.name"); - assertEquals("name", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.name", attributeNames.next()); - assertEquals("state.abbr", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.name"); - assertEquals("name", stateFooMapping.getName()); - } - private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) { - return ((OrmOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval(); - } - - public void testUpdateSpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToManyMapping); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToManyResource.getOrphanRemoval()); - - //set enumerated in the resource model, verify context model updated - oneToManyResource.setOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval()); - - oneToManyResource.setOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval()); - } - - public void testModifySpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToManyMapping); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToManyResource.getOrphanRemoval()); - - //set enumerated in the context model, verify resource model updated - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval()); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval()); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToManyMapping.getMapKey()); - assertFalse(oneToManyMapping.isPkMapKey()); - assertFalse(oneToManyMapping.isCustomMapKey()); - assertTrue(oneToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setPkMapKey(true); - assertEquals("id", oneToManyMapping.getMapKey()); - assertTrue(oneToManyMapping.isPkMapKey()); - assertFalse(oneToManyMapping.isCustomMapKey()); - assertFalse(oneToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setCustomMapKey(true); - javaOneToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("city", oneToManyMapping.getMapKey()); - assertFalse(oneToManyMapping.isPkMapKey()); - assertTrue(oneToManyMapping.isCustomMapKey()); - assertFalse(oneToManyMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = oneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = oneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = oneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = oneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = oneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = oneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNotNull(oneToMany.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKeyClass().setClassName("String"); - assertEquals("String", ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", oneToMany.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKeyClass().setClassName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass().getClassName()); - - oneToMany.getMapKeyClass().setClassName("String"); - oneToMany.setMapKeyClass(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertEquals("java.lang.String", oneToManyMapping.getMapKeyClass()); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", oneToManyMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", oneToManyMapping.getMapKeyClass()); - assertEquals("Integer", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", oneToMany.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmOneToManyMapping oneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - oneToManyMapping.getRelationship().setStrategyToMappedBy(); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("queue"); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - OrmPersistentType printJobPersistentType = (OrmPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - - assertEquals("MY_TABLE", orderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaOneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("jobs"); - oneToManyMapping = (OneToManyMapping) ormPersistentAttribute2.getMapping(); - orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(false, orderable.isNoOrdering()); - assertEquals("PrintJob", orderable.getOrderColumn().getTable()); - assertEquals("jobs_ORDER", orderable.getOrderColumn().getName()); - - ((Orderable2_0) javaOneToManyMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals("PrintJob", orderable.getOrderColumn().getTable()); - assertEquals("FOO", orderable.getOrderColumn().getName()); - } - - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @OneToMany(mappedBy=\"queue\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private PrintQueue queue;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 virtualAddressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = virtualAddressesMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_Address", virtualColumn.getTable()); - assertNull(virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaOneToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getName()); - assertEquals("FOO_TABLE", virtualColumn.getTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertFalse(virtualColumn.isInsertable()); - assertFalse(virtualColumn.isUpdatable()); - assertFalse(virtualColumn.isNullable()); - assertTrue(virtualColumn.isUnique()); - assertEquals(45, virtualColumn.getLength()); - assertEquals(46, virtualColumn.getPrecision()); - assertEquals(47, virtualColumn.getScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmOneToManyMapping2_0 addressesVirtualMapping = (OrmOneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaOneToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - OneToManyMapping2_0 virtualAddressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = virtualAddressesMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_Address", virtualColumn.getTable()); - assertNull(virtualColumn.getSpecifiedTable()); - - //entity table changes the join table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE_Address", virtualColumn.getTable()); - - //set Column table element in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - assertEquals("JAVA_JOIN_TABLE", virtualColumn.getTable()); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - OneToManyMapping2_0 specifiedAddressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column specifiedColumn = specifiedAddressesMapping.getMapKeyColumn(); - assertNull(specifiedColumn.getSpecifiedTable()); - assertEquals("ORM_TABLE_Address", specifiedColumn.getDefaultTable()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); - OrmOneToManyMapping2_0 contextMapping = (OrmOneToManyMapping2_0) contextAttribute.getMapping(); - OrmOneToManyRelationship2_0 rel = (OrmOneToManyRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); - OrmOneToManyMapping2_0 contextMapping = (OrmOneToManyMapping2_0) contextAttribute.getMapping(); - OrmOneToManyRelationship2_0 rel = (OrmOneToManyRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testTargetForeignKeyJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - OneToManyRelationship2_0 rr = (OneToManyRelationship2_0) javaOneToManyMapping.getRelationship(); - rr.setStrategyToJoinColumn(); - - JoinColumn joinColumn = rr.getJoinColumnStrategy().joinColumns().next(); - assertTrue(persistentAttribute.isVirtual()); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("Address", joinColumn.getDefaultTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - oneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - rr = (OneToManyRelationship2_0) oneToManyMapping.getRelationship(); - assertFalse(rr.strategyIsJoinColumn()); - - rr.setStrategyToJoinColumn(); - joinColumn = rr.getJoinColumnStrategy().specifiedJoinColumns().next(); - assertFalse(persistentAttribute.isVirtual()); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - joinColumn.setSpecifiedName("FOO"); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - } - - //target foreign key case - public void testGetMapKeyColumnJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - OneToManyRelationship2_0 rr = (OneToManyRelationship2_0) javaOneToManyMapping.getRelationship(); - rr.setStrategyToJoinColumn(); - - assertTrue(persistentAttribute.isVirtual()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getDefaultTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - oneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - rr = (OneToManyRelationship2_0) oneToManyMapping.getRelationship(); - assertFalse(rr.strategyIsJoinColumn()); - - rr.setStrategyToJoinColumn(); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - oneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("FOO", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getDefaultTable()); - } - - //target foreign key case - public void testOrderColumnDefaultsJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - OneToManyRelationship2_0 rr = (OneToManyRelationship2_0) javaOneToManyMapping.getRelationship(); - rr.setStrategyToJoinColumn(); - ((Orderable2_0) javaOneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = ((Orderable2_0) oneToManyMapping.getOrderable()).getOrderColumn(); - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals("Address", orderColumn.getTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - oneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - rr = (OneToManyRelationship2_0) oneToManyMapping.getRelationship(); - assertFalse(rr.strategyIsJoinColumn()); - - rr.setStrategyToJoinColumn(); - assertFalse(((Orderable2_0) oneToManyMapping.getOrderable()).isOrderColumnOrdering()); - ((Orderable2_0) oneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - orderColumn = ((Orderable2_0) oneToManyMapping.getOrderable()).getOrderColumn(); - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualOneToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) virtualOneToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(virtualOneToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertTrue(((OrphanRemovalHolder2_0) virtualOneToManyMapping).getOrphanRemoval().isOrphanRemoval()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch()); - assertEquals("test.Address", ormOneToManyMapping.getTargetEntity()); - assertNull(ormOneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) ormOneToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToManyMapping).getOrphanRemoval().isOrphanRemoval()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java deleted file mode 100644 index 5c02b1c0b2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java +++ /dev/null @@ -1,991 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.OrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedIdentity2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlDerivedId_2_0; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapsId_2_0; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmOneToOneMapping2_0Tests - extends Generic2_0ContextModelTestCase -{ - public GenericOrmOneToOneMapping2_0Tests(String name) { - super(name); - } - - - private void createTestEntityWithIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private void createTestEntityWithOneToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testUpdateId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(""); - assertEquals("", resourceMapping.getMapsId()); - assertEquals("", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testUpdatePredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(Boolean.TRUE); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId("foo"); - assertNotNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setId(null); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testSetPredominantDerivedIdentityStrategy() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmDerivedIdentity2_0 derivedIdentity = contextMapping.getDerivedIdentity(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setIdDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNotNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setMapsIdDerivedIdentityStrategy(); - assertNotNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertTrue(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesNullDerivedIdentityStrategy()); - - derivedIdentity.setNullDerivedIdentityStrategy(); - assertNull(resourceMapping.getMapsId()); - assertNull(resourceMapping.getId()); - assertFalse(derivedIdentity.usesMapsIdDerivedIdentityStrategy()); - assertFalse(derivedIdentity.usesIdDerivedIdentityStrategy()); - assertTrue(derivedIdentity.usesNullDerivedIdentityStrategy()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute contextAttribute = (OrmPersistentAttribute) contextType.getAttributeNamed("oneToOne"); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - - XmlOneToOne resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - resourceOneToOne.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceOneToOne.getId()); - assertTrue(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceOneToOne.getMapsId()); - assertNull(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - XmlManyToOne resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - assertEquals(Boolean.TRUE, resourceManyToOne.getId()); - assertTrue(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceManyToOne.getMapsId()); - assertNull(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - assertEquals(Boolean.TRUE, resourceOneToOne.getId()); - assertTrue(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceOneToOne.getMapsId()); - assertNull(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToOneMapping2_0 oneToOneMapping) { - return ((OrmOrphanRemovalHolder2_0) oneToOneMapping).getOrphanRemoval(); - } - - public void testUpdateSpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToOneMapping); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToOneResource.getOrphanRemoval()); - - //set enumerated in the resource model, verify context model updated - oneToOneResource.setOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.TRUE, oneToOneResource.getOrphanRemoval()); - - oneToOneResource.setOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.FALSE, oneToOneResource.getOrphanRemoval()); - } - - public void testModifySpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToOneMapping); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToOneResource.getOrphanRemoval()); - - //set enumerated in the context model, verify resource model updated - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneResource.getOrphanRemoval()); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneResource.getOrphanRemoval()); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidOneToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - JavaOneToOneMapping2_0 javaOneToOneMapping = ((JavaOneToOneMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping()); - JavaOneToOneMapping2_0 virtualOneToOneMapping = (JavaOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - JoinTable virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, virtualJoinTable.getSpecifiedName()); - - createTestTargetEntityAddress(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - assertNull(virtualJoinTable.getSpecifiedName()); - assertEquals(TYPE_NAME + "_Address", virtualJoinTable.getDefaultName()); - assertNull(virtualJoinTable.getSpecifiedCatalog()); - assertNull(virtualJoinTable.getSpecifiedSchema()); - assertEquals(0, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(0, virtualJoinTable.specifiedInverseJoinColumnsSize()); - JoinColumn ormJoinColumn = virtualJoinTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_Address", ormJoinColumn.getDefaultTable()); - assertEquals(TYPE_NAME + "_id", ormJoinColumn.getDefaultName()); - assertEquals("id", ormJoinColumn.getDefaultReferencedColumnName()); - JoinColumn inverseOrmJoinColumn = virtualJoinTable.getDefaultInverseJoinColumn(); - assertEquals(TYPE_NAME + "_Address", inverseOrmJoinColumn.getDefaultTable()); - assertEquals("address_id", inverseOrmJoinColumn.getDefaultName()); - assertEquals("id", inverseOrmJoinColumn.getDefaultReferencedColumnName()); - - JavaJoinTable javaJoinTable = ((JavaOneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", virtualJoinTable.getSpecifiedName()); - assertEquals("CATALOG", virtualJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualJoinTable.getSpecifiedSchema()); - assertEquals(1, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(1, virtualJoinTable.specifiedInverseJoinColumnsSize()); - ormJoinColumn = virtualJoinTable.specifiedJoinColumns().next(); - assertEquals("NAME", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); - inverseOrmJoinColumn = virtualJoinTable.specifiedInverseJoinColumns().next(); - assertEquals("INVERSE_NAME", inverseOrmJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", inverseOrmJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidOneToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((OneToOneRelationship2_0) ormOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - OrmJoinTable ormJoinTable = ((OrmOneToOneRelationship2_0) ormOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTestTargetEntityAddress(); - OrmPersistentType targetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - JavaOneToOneMapping2_0 javaOneToOneMapping = (JavaOneToOneMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("address").getMapping(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute virtualAttribute = ormPersistentType.getAttributeNamed("address"); - OneToOneMapping2_0 virtualOneToOneMapping = (OneToOneMapping2_0) virtualAttribute.getMapping(); - JoinTable virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertTrue(virtualAttribute.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", virtualJoinTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().removeStrategy(); - virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(virtualJoinTable); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("BAR_FOO", virtualJoinTable.getName()); - assertNull(virtualJoinTable.getSpecifiedName()); - assertEquals("BAR_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", virtualJoinTable.getDefaultName()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmOneToOneRelationship2_0 rel = (OrmOneToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmOneToOneRelationship2_0 rel = (OrmOneToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getPrimaryKeyJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OneToOneMapping2_0 virtualOneToOneMapping = (OneToOneMapping2_0) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualOneToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualOneToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToOneMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - JoinColumn virtualJoinColumn = - virtualOneToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", virtualJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", virtualJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, virtualJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", virtualJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", virtualJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) virtualOneToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(((OrphanRemovalHolder2_0) virtualOneToOneMapping).getOrphanRemoval().isOrphanRemoval()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - - OneToOneMapping2_0 ormOneToOneMapping = (OneToOneMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - assertEquals("test.Address", ormOneToOneMapping.getTargetEntity()); - assertNull(ormOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToOneMapping).getOrphanRemoval().isOrphanRemoval()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java deleted file mode 100644 index ba5da6b4cf..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0Tests.java +++ /dev/null @@ -1,550 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmPersistentAttribute2_0Tests - extends Generic2_0ContextModelTestCase -{ - - public GenericOrmPersistentAttribute2_0Tests(String name) { - super(name); - } - - - private ICompilationUnit createTestTypeNullAttributeMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityIdMappingPropertyAccess() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(" private Address address;"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public void testMakeSpecified() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeSpecifiedWithAccess() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertEquals(null, ormPersistentAttribute.getJavaPersistentAttribute().getSpecifiedAccess()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertEquals(null, specifiedOrmPersistentAttribute.getSpecifiedAccess()); - assertEquals(AccessType.PROPERTY, specifiedOrmPersistentAttribute.getAccess()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, specifiedOrmPersistentAttribute.getAccess()); - assertEquals(null, specifiedOrmPersistentAttribute.getSpecifiedAccess()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, specifiedOrmPersistentAttribute.getSpecifiedAccess()); - } - - public void testMakeSpecifiedMappingKey() throws Exception { - createTestTypeNullAttributeMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - //take a virtual mapping with a mapping type and make it specified - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertTrue(ormPersistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - ormPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmOneToOneMapping); - - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(0, ormPersistentType.specifiedAttributesSize()); - - Iterator virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - - ormPersistentType.specifiedAttributes().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - assertEquals("id", ormPersistentType.virtualAttributes().next().getName()); - assertEquals("name", ormPersistentType.specifiedAttributes().next().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("id", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete2() throws Exception { - createTestEntityOneToOneMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } - - public void testGetJavaPersistentAttribute() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - //virtual orm attribute, access type matches java : FIELD, name matches java - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - JavaResourcePersistentAttribute javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isField()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableFields().next(), javaResourcePersistentAttribute); - - - //specified orm attribute, access type matches java : FIELD, name matches java - //javaPersistentAttribute should be == to java context model object - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - - - //virtual orm attribute, java access type FIELD, orm access type PROPERTY, name matches java - //verify the property java resource persistent attribute is used in orm. - ((OrmPersistentAttribute) ormPersistentAttribute).convertToVirtual(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertNotSame(ormPersistentAttribute, ormPersistentType.getAttributeNamed("id")); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isProperty()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableProperties().next(), javaResourcePersistentAttribute); - - - ormPersistentType.setSpecifiedAccess(null);//default access will be field - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - OrmPersistentAttribute ormPersistentAttribute2 = ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute2.getMapping().setName("id2"); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName(null); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName("id"); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - } - - public void testGetJavaPersistentAttributeMixedAccess() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getOwningPersistentType().getAccess()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - - ((OrmPersistentAttribute) ormPersistentAttribute).setSpecifiedAccess(AccessType.FIELD); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - } - - public void testGetAccess() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - } - - public void testGetAccessPropertyInJava() throws Exception { - createTestEntityIdMappingPropertyAccess(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - } - - public void testGetAccessPropertyInJava2() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - - - OrmReadOnlyPersistentAttribute nameOrmPersistentAttribute = ormPersistentType.getAttributeNamed("name"); - JavaPersistentAttribute nameJavaPersistentAttribute = javaPersistentType.getAttributeNamed("name"); - - assertTrue(nameOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getAccess()); - assertTrue(nameOrmPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertEquals(AccessType.FIELD, nameJavaPersistentAttribute.getAccess()); - assertTrue(nameJavaPersistentAttribute.getResourcePersistentAttribute().isField()); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - - nameOrmPersistentAttribute.convertToSpecified(); - nameOrmPersistentAttribute = ormPersistentType.getAttributeNamed("name"); - assertFalse(nameOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertTrue(nameOrmPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertEquals(AccessType.FIELD, nameJavaPersistentAttribute.getAccess()); - assertTrue(nameJavaPersistentAttribute.getResourcePersistentAttribute().isField()); - assertEquals(nameJavaPersistentAttribute, nameOrmPersistentAttribute.getJavaPersistentAttribute()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - - assertFalse(nameOrmPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, nameOrmPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, nameOrmPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.FIELD, nameJavaPersistentAttribute.getAccess()); - assertTrue(nameJavaPersistentAttribute.getResourcePersistentAttribute().isField()); - - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java deleted file mode 100644 index 32f7ca209a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmPersistentType2_0Tests.java +++ /dev/null @@ -1,283 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class GenericOrmPersistentType2_0Tests - extends Generic2_0ContextModelTestCase -{ - - public GenericOrmPersistentType2_0Tests(String name) { - super(name); - } - - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityFieldSpecifiedPropertyAnnotated() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.FIELD)"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createTestEntityPropertySpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - public void testGetAccessWithJavaAnnotations() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - assertEquals(null, javaPersistentType.getSpecifiedAccess()); - - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentAttribute.convertToSpecified(); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - assertEquals(null, javaPersistentType.getSpecifiedAccess()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testGetAccessWithJavaAnnotationsProperty() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - assertEquals(AccessType.PROPERTY, ormPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getSpecifiedAccess()); - - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentAttribute.convertToSpecified(); - assertEquals(AccessType.PROPERTY, ormPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getSpecifiedAccess()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testVirtualAttributes() throws Exception { - createTestEntityAnnotatedFieldPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - virtualAttributes = ormPersistentType.virtualAttributes(); - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - } - - public void testVirtualAttributes2() throws Exception { - createTestEntityPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - virtualAttributes = ormPersistentType.virtualAttributes(); - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("name", ormPersistentAttribute.getName()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); - virtualAttributes = ormPersistentType.virtualAttributes(); - ormPersistentAttribute = virtualAttributes.next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - } - - public void testVirtualAttributes3() throws Exception { - createTestEntityFieldSpecifiedPropertyAnnotated(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - assertEquals(AccessType.PROPERTY, virtualAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - - virtualAttribute.convertToSpecified(); - - virtualAttributes = ormPersistentType.virtualAttributes(); - virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - - - OrmPersistentAttribute specifiedAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedAttribute.getName()); - assertEquals(AccessType.PROPERTY, specifiedAttribute.getSpecifiedAccess()); - - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - virtualAttributes = ormPersistentType.virtualAttributes(); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - assertEquals(AccessType.FIELD, virtualAttribute.getAccess()); - - assertFalse(virtualAttributes.hasNext()); - } - - public void testGetDefaultAccess() throws Exception { - createTestEntityPropertySpecified(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - - javaPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - - javaPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java deleted file mode 100644 index 3853a9d9d8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmSequenceGenerator2_0Tests.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.orm; - -import org.eclipse.jpt.core.jpa2.context.SequenceGenerator2_0; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.tests.internal.jpa2.context.Generic2_0ContextModelTestCase; - -/** - * Generic2_0OrmSequenceGenerator2_0Tests - */ -@SuppressWarnings("nls") -public class GenericOrmSequenceGenerator2_0Tests - extends Generic2_0ContextModelTestCase -{ - - public GenericOrmSequenceGenerator2_0Tests(String name) { - super(name); - } - - // ********** catalog ********** - - public void testUpdateSpecifiedCatalog() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setCatalog("FOO"); - assertEquals("FOO", sequenceGenerator.getSpecifiedCatalog()); - assertEquals("FOO", sequenceGeneratorResource.getCatalog()); - - //set name to null in the resource model - sequenceGeneratorResource.setCatalog(null); - assertNull(sequenceGenerator.getSpecifiedCatalog()); - assertNull(sequenceGeneratorResource.getCatalog()); - } - - public void testModifySpecifiedCatalog() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setSpecifiedCatalog("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getCatalog()); - assertEquals("FOO", sequenceGenerator.getSpecifiedCatalog()); - - //set name to null in the context model - sequenceGenerator.setSpecifiedCatalog(null); - assertNull(sequenceGeneratorResource.getCatalog()); - assertNull(sequenceGenerator.getSpecifiedCatalog()); - } - - // ********** schema ********** - - public void testUpdateSpecifiedSchema() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setSchema("FOO"); - assertEquals("FOO", sequenceGenerator.getSpecifiedSchema()); - assertEquals("FOO", sequenceGeneratorResource.getSchema()); - - //set name to null in the resource model - sequenceGeneratorResource.setSchema(null); - assertNull(sequenceGenerator.getSpecifiedSchema()); - assertNull(sequenceGeneratorResource.getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - SequenceGenerator2_0 sequenceGenerator = (SequenceGenerator2_0) getEntityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = getXmlEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setSpecifiedSchema("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getSchema()); - assertEquals("FOO", sequenceGenerator.getSpecifiedSchema()); - - //set name to null in the context model - sequenceGenerator.setSpecifiedSchema(null); - assertNull(sequenceGeneratorResource.getSchema()); - assertNull(sequenceGenerator.getSpecifiedSchema()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java deleted file mode 100644 index f3d318f518..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0ConnectionTests.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.persistence; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.core.jpa2.context.persistence.connection.JpaConnection2_0; - -/** - * GenericConnection2_0Tests - */ -@SuppressWarnings("nls") -public class Generic2_0ConnectionTests extends Generic2_0PersistenceUnitTests -{ - private JpaConnection2_0 connection; - - public static final String DRIVER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_DRIVER; - public static final String DRIVER_TEST_VALUE = "test"; - public static final String DRIVER_TEST_VALUE_2 = "test_2"; - - public static final String URL_KEY = JpaConnection2_0.PERSISTENCE_JDBC_URL; - public static final String URL_TEST_VALUE = "test"; - public static final String URL_TEST_VALUE_2 = "test_2"; - - public static final String USER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_USER; - public static final String USER_TEST_VALUE = "test"; - public static final String USER_TEST_VALUE_2 = "test_2"; - - public static final String PASSWORD_KEY = JpaConnection2_0.PERSISTENCE_JDBC_PASSWORD; - public static final String PASSWORD_TEST_VALUE = "test"; - public static final String PASSWORD_TEST_VALUE_2 = "test_2"; - - // ********** constructors ********** - public Generic2_0ConnectionTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.connection = (JpaConnection2_0) this.subject.getConnection(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.connection.addPropertyChangeListener(JpaConnection2_0.DRIVER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(JpaConnection2_0.URL_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(JpaConnection2_0.USER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(JpaConnection2_0.PASSWORD_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PersistenceUnit properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 4; // PersistenceUnit properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 1 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes PersistenceUnit properties - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(DRIVER_KEY, DRIVER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(URL_KEY, URL_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(USER_KEY, USER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(PASSWORD_KEY, PASSWORD_TEST_VALUE.toString()); - - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.connection; - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(JpaConnection2_0.DRIVER_PROPERTY)) - modelValue = this.connection.getDriver(); - else if (propertyName.equals(JpaConnection2_0.URL_PROPERTY)) - modelValue = this.connection.getUrl(); - else if (propertyName.equals(JpaConnection2_0.USER_PROPERTY)) - modelValue = this.connection.getUser(); - else if (propertyName.equals(JpaConnection2_0.PASSWORD_PROPERTY)) - modelValue = this.connection.getPassword(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(JpaConnection2_0.DRIVER_PROPERTY)) - this.connection.setDriver((String) newValue); - else if (propertyName.equals(JpaConnection2_0.URL_PROPERTY)) - this.connection.setUrl((String) newValue); - else if (propertyName.equals(JpaConnection2_0.USER_PROPERTY)) - this.connection.setUser((String) newValue); - else if (propertyName.equals(JpaConnection2_0.PASSWORD_PROPERTY)) - this.connection.setPassword((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - // ********** Driver tests ********** - public void testSetDriver() throws Exception { - this.verifyModelInitialized( - DRIVER_KEY, - DRIVER_TEST_VALUE); - this.verifySetProperty( - DRIVER_KEY, - DRIVER_TEST_VALUE, - DRIVER_TEST_VALUE_2); - } - - public void testAddRemoveDriver() throws Exception { - this.verifyAddRemoveProperty( - DRIVER_KEY, - DRIVER_TEST_VALUE, - DRIVER_TEST_VALUE_2); - } - - // ********** Url tests ********** - public void testSetUrl() throws Exception { - this.verifyModelInitialized( - URL_KEY, - URL_TEST_VALUE); - this.verifySetProperty( - URL_KEY, - URL_TEST_VALUE, - URL_TEST_VALUE_2); - } - - public void testAddRemoveUrl() throws Exception { - this.verifyAddRemoveProperty( - URL_KEY, - URL_TEST_VALUE, - URL_TEST_VALUE_2); - } - - // ********** User tests ********** - public void testSetUser() throws Exception { - this.verifyModelInitialized( - USER_KEY, - USER_TEST_VALUE); - this.verifySetProperty( - USER_KEY, - USER_TEST_VALUE, - USER_TEST_VALUE_2); - } - - public void testAddRemoveUser() throws Exception { - this.verifyAddRemoveProperty( - USER_KEY, - USER_TEST_VALUE, - USER_TEST_VALUE_2); - } - - // ********** Password tests ********** - public void testSetPassword() throws Exception { - this.verifyModelInitialized( - PASSWORD_KEY, - PASSWORD_TEST_VALUE); - this.verifySetProperty( - PASSWORD_KEY, - PASSWORD_TEST_VALUE, - PASSWORD_TEST_VALUE_2); - } - - public void testAddRemovePassword() throws Exception { - this.verifyAddRemoveProperty( - PASSWORD_KEY, - PASSWORD_TEST_VALUE, - PASSWORD_TEST_VALUE_2); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java deleted file mode 100644 index 28856ff504..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0OptionsTests.java +++ /dev/null @@ -1,520 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.persistence; - -import java.util.ListIterator; - -import org.eclipse.jpt.common.utility.model.event.ListAddEvent; -import org.eclipse.jpt.common.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.common.utility.model.event.ListClearEvent; -import org.eclipse.jpt.common.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.common.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.core.jpa2.context.persistence.options.JpaOptions2_0; - -/** - * GenericOptions2_0Tests - */ -@SuppressWarnings("nls") -public class Generic2_0OptionsTests extends Generic2_0PersistenceUnitTests -{ - private JpaOptions2_0 options; - private ListChangeEvent prePersistEvent; - private ListChangeEvent preUpdateEvent; - private ListChangeEvent preRemoveEvent; - - public static final String LOCK_TIMEOUT_KEY = JpaOptions2_0.PERSISTENCE_LOCK_TIMEOUT; - public static final Integer LOCK_TIMEOUT_TEST_VALUE = 100; - public static final Integer LOCK_TIMEOUT_TEST_VALUE_2 = 200; - - public static final String QUERY_TIMEOUT_KEY = JpaOptions2_0.PERSISTENCE_QUERY_TIMEOUT; - public static final Integer QUERY_TIMEOUT_TEST_VALUE = 100; - public static final Integer QUERY_TIMEOUT_TEST_VALUE_2 = 200; - - public static final String VALIDATION_GROUP_PRE_PERSIST_KEY = JpaOptions2_0.PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST; - public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE = "test_pre-persist_group"; - public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2 = "test_2_pre-persist_group"; - - public static final String VALIDATION_GROUP_PRE_UPDATE_KEY = JpaOptions2_0.PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE; - public static final String VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE = "test_pre-update_group"; - public static final String VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2 = "test_2_pre-update_group"; - - public static final String VALIDATION_GROUP_PRE_REMOVE_KEY = JpaOptions2_0.PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE; - public static final String VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE = "test_pre-remove_group"; - public static final String VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2 = "test_2_pre-remove_group"; - - // ********** constructors ********** - public Generic2_0OptionsTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.options = (JpaOptions2_0) this.subject.getOptions(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.options.addPropertyChangeListener(JpaOptions2_0.LOCK_TIMEOUT_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, propertyChangeListener); - - ListChangeListener validationGroupListChangeListener = this.buildValidationGroupListChangeListener(); - this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST, validationGroupListChangeListener); - this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST, validationGroupListChangeListener); - this.options.addListChangeListener(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST, validationGroupListChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PersistenceUnit properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 5; // PersistenceUnit properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 1 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes PersistenceUnit properties - this.persistenceUnitSetProperty(LOCK_TIMEOUT_KEY, LOCK_TIMEOUT_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(QUERY_TIMEOUT_KEY, QUERY_TIMEOUT_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.options; - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(JpaOptions2_0.LOCK_TIMEOUT_PROPERTY)) - modelValue = this.options.getLockTimeout(); - else if (propertyName.equals(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY)) - modelValue = this.options.getQueryTimeout(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) { - ListIterator iterator = this.options.validationGroupPrePersists(); - modelValue = this.getFirstElement(iterator); - } - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) { - ListIterator iterator = this.options.validationGroupPreUpdates(); - modelValue = this.getFirstElement(iterator); - } - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) { - ListIterator iterator = this.options.validationGroupPreRemoves(); - modelValue = this.getFirstElement(iterator); - } - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(JpaOptions2_0.LOCK_TIMEOUT_PROPERTY)) - this.options.setLockTimeout((Integer) newValue); - else if (propertyName.equals(JpaOptions2_0.QUERY_TIMEOUT_PROPERTY)) - this.options.setQueryTimeout((Integer) newValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.addValidationGroupPrePersist((String) newValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.addValidationGroupPreUpdate((String) newValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.addValidationGroupPreRemove((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - // ********** LockTimeout tests ********** - public void testSetLockTimeout() throws Exception { - this.verifyModelInitialized( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE); - this.verifySetProperty( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE, - LOCK_TIMEOUT_TEST_VALUE_2); - } - - public void testAddRemoveLockTimeout() throws Exception { - this.verifyAddRemoveProperty( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE, - LOCK_TIMEOUT_TEST_VALUE_2); - } - - // ********** QueryTimeout tests ********** - public void testSetQueryTimeout() throws Exception { - this.verifyModelInitialized( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE); - this.verifySetProperty( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE, - QUERY_TIMEOUT_TEST_VALUE_2); - } - - public void testAddRemoveQueryTimeout() throws Exception { - this.verifyAddRemoveProperty( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE, - QUERY_TIMEOUT_TEST_VALUE_2); - } - - // ********** ValidationGroupPrePersist tests ********** - public void testSetValidationGroupPrePersist() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.verifySetValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPrePersist() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testAddValidationGroupPrePersistCompositeValue() throws Exception { - this.verifyAddCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPrePersistCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - // ********** ValidationGroupPreUpdate tests ********** - public void testSetValidationGroupPreUpdate() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.verifySetValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPreUpdate() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testAddValidationGroupPreUpdateCompositeValue() throws Exception { - this.verifyAddCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPreUpdateCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - // ********** ValidationGroupPreRemove tests ********** - public void testSetValidationGroupPreRemove() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - this.verifySetValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPreRemove() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testAddValidationGroupPreRemoveCompositeValue() throws Exception { - this.verifyAddCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPreRemoveCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - // ********** ValidationGroups list ********** - public void testValidationGroupsList() throws Exception { - this.verifyListEvents( - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2, - JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST); - - this.verifyListEvents( - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2, - JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST); - - this.verifyListEvents( - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2, - JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST); - } - - // ********** override ********** - - @Override - protected void clearEvent() { - super.clearEvent(); - this.prePersistEvent = null; - this.preUpdateEvent = null; - this.preRemoveEvent = null; - } - - // ****** convenience methods ******* - - // ********** verify ValidationGroup property ********** - protected void verifySetValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Replace - this.persistenceUnitSetProperty(key, testValue2, true); - this.propertiesTotal++; - this.verifyPutValidationGroupProperty(propertyName, testValue1); - } - - @SuppressWarnings("unused") - protected void verifyAddRemoveValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - assertTrue(this.validationGroupValueExists(propertyName, (String)testValue1)); - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.getPersistenceUnit().removeProperty(key, (String)testValue1); - assertFalse(this.validationGroupValueExists(propertyName, (String)testValue1)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(key, testValue1, true); - this.verifyPutValidationGroupProperty(propertyName, testValue1); - } - - protected void verifyAddCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - String stringTestValue1 = (String)testValue1; - String stringTestValue2 = (String)testValue2; - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertEquals(this.getValidationGroupSize(propertyName), 1); - this.addValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 2); - - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue2)); - - String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); - assertTrue(propertyValue.indexOf(stringTestValue1) != -1); - assertTrue(propertyValue.indexOf(stringTestValue2) != -1); - } - - protected void verifyRemoveCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - String stringTestValue1 = (String)testValue1; - String stringTestValue2 = (String)testValue2; - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertEquals(this.getValidationGroupSize(propertyName), 1); - this.addValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 2); - - this.removeValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 1); - assertFalse(this.validationGroupValueExists(propertyName, stringTestValue2)); - String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); - assertTrue(propertyValue.indexOf(stringTestValue1) != -1); - assertTrue(propertyValue.indexOf(stringTestValue2) == -1); - - this.removeValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 1); - - this.removeValidationGroupValue(propertyName, stringTestValue1); - assertEquals(this.getValidationGroupSize(propertyName), 0); - assertFalse(this.validationGroupValueExists(propertyName, stringTestValue1)); - - assertNull(this.getPersistenceUnit().getProperty(key)); - } - - protected void verifyListEvents(String propertyName, String testValue, String listName) throws Exception { - // add - this.clearEvent(); - this.addValidationGroupValue(propertyName, testValue); - - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event for the expected property - assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); - - // remove - this.clearEvent(); - - this.removeValidationGroupValue(propertyName, testValue); - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event for the expected property - assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); - } - - protected void verifyPutValidationGroupProperty(String propertyName, Object expectedValue) throws Exception { - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event value - assertTrue(this.validationGroupValueExists(propertyName, (String) expectedValue)); - return; - } - - // ********** internal method ********** - - private ListChangeListener buildValidationGroupListChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsRemoved(ListRemoveEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsReplaced(ListReplaceEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListMoveEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListClearEvent e) { - Generic2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - - Generic2_0OptionsTests.this.validationGroupChanged(e); - } - }; - } - - private void validationGroupChanged(ListChangeEvent e) { - String listName = e.getListName(); - - if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_LIST)) - this.prePersistEvent = e; - else if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_LIST)) - this.preUpdateEvent = e; - else if (listName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_LIST)) - this.preRemoveEvent = e; - else - this.throwUnsupportedOperationException(e); - } - - private void addValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.addValidationGroupPrePersist(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.addValidationGroupPreUpdate(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.addValidationGroupPreRemove(propertyValue); - else - this.throwMissingDefinition("addValidationGroupValue", propertyName); - } - - private void removeValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.removeValidationGroupPrePersist(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.removeValidationGroupPreUpdate(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.removeValidationGroupPreRemove(propertyValue); - else - this.throwMissingDefinition("removeValidationGroupValue", propertyName); - } - - private boolean validationGroupValueExists(String propertyName, String propertyValue) throws NoSuchFieldException { - boolean result = false; - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - result = this.options.validationGroupPrePersistExists(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - result = this.options.validationGroupPreUpdateExists(propertyValue); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - result = this.options.validationGroupPreRemoveExists(propertyValue); - else - this.throwMissingDefinition("verifyValidationGroupValueExists", propertyName); - return result; - } - - private int getValidationGroupSize(String propertyName) throws NoSuchFieldException { - int result = 0; - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - result = this.options.validationGroupPrePersistsSize(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - result = this.options.validationGroupPreUpdatesSize(); - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - result = this.options.validationGroupPreRemovesSize(); - else - this.throwMissingDefinition("verifyValidationGroupSize", propertyName); - return result; - } - - private ListChangeEvent getEventFor(String propertyName) throws NoSuchFieldException { - ListChangeEvent event = null; - if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - event = this.prePersistEvent; - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - event = this.preUpdateEvent; - else if (propertyName.equals(JpaOptions2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - event = this.preRemoveEvent; - else - this.throwMissingDefinition("getEventFor", propertyName); - return event; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java deleted file mode 100644 index 6cbfbf5f5b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceContextModelTests.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.persistence; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class Generic2_0PersistenceContextModelTests - extends TestCase -{ - - public static Test suite() { - TestSuite suite = new TestSuite(Generic2_0ConnectionTests.class.getPackage().getName()); - suite.addTestSuite(Generic2_0OptionsTests.class); - return suite; - } - - private Generic2_0PersistenceContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java deleted file mode 100644 index b718f5b637..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/persistence/Generic2_0PersistenceUnitTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.context.persistence; - -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.platform.GenericPlatform; -import org.eclipse.jpt.core.tests.internal.context.persistence.PersistenceUnitTestCase; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * GenericPersistenceUnit2_0Tests - */ -public abstract class Generic2_0PersistenceUnitTests extends PersistenceUnitTestCase -{ - protected PersistenceUnit2_0 subject; - - protected PropertyValueModel subjectHolder; - - // ********** constructors ********** - protected Generic2_0PersistenceUnitTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject = this.getPersistenceUnit(); - this.subjectHolder = new SimplePropertyValueModel(this.subject); - this.populatePu(); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_2_0.getVersionString()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, GenericPlatform.VERSION_2_0); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - @Override - protected PersistenceUnit2_0 getPersistenceUnit() { - return (PersistenceUnit2_0) super.getPersistenceUnit(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Access2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Access2_0AnnotationTests.java deleted file mode 100644 index cccdbd847b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Access2_0AnnotationTests.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class Access2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public Access2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestAccessOnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createTestAccessOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Access(AccessType.FIELD)"); - } - }); - } - - private ICompilationUnit createTestAccessOnProperty() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ACCESS, JPA2_0.ACCESS_TYPE); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Access(AccessType.PROPERTY)"); - } - }); - } - - public void testGetAccessOnType() throws Exception { - ICompilationUnit cu = this.createTestAccessOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - Access2_0Annotation access = (Access2_0Annotation) typeResource.getAnnotation(JPA2_0.ACCESS); - assertNotNull(access); - assertEquals(AccessType.PROPERTY, access.getValue()); - } - - public void testSetAccessOnType() throws Exception { - ICompilationUnit cu = this.createTestType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - Access2_0Annotation access = (Access2_0Annotation) typeResource.getAnnotation(JPA2_0.ACCESS); - assertNull(access); - - typeResource.addAnnotation(JPA2_0.ACCESS); - assertSourceContains("@Access", cu); - - access = (Access2_0Annotation) typeResource.getAnnotation(JPA2_0.ACCESS); - assertNotNull(access); - - access.setValue(AccessType.FIELD); - assertEquals(AccessType.FIELD, access.getValue()); - assertSourceContains("@Access(FIELD)", cu); - - access.setValue(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, access.getValue()); - assertSourceContains("@Access(PROPERTY)", cu); - - access.setValue(null); - assertSourceDoesNotContain("@Access(", cu); - } - - public void testGetAccessOnField() throws Exception { - ICompilationUnit cu = this.createTestAccessOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableFields().next(); - - Access2_0Annotation access = (Access2_0Annotation) attributeResource.getAnnotation(JPA2_0.ACCESS); - assertNotNull(access); - assertEquals(AccessType.FIELD, access.getValue()); - } - - public void testSetAccessOnField() throws Exception { - ICompilationUnit cu = this.createTestType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableFields().next(); - - Access2_0Annotation access = (Access2_0Annotation) attributeResource.getAnnotation(JPA2_0.ACCESS); - assertNull(access); - - attributeResource.addAnnotation(JPA2_0.ACCESS); - assertSourceContains("@Access", cu); - - access = (Access2_0Annotation) attributeResource.getAnnotation(JPA2_0.ACCESS); - assertNotNull(access); - - access.setValue(AccessType.FIELD); - assertEquals(AccessType.FIELD, access.getValue()); - assertSourceContains("@Access(FIELD)", cu); - - access.setValue(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, access.getValue()); - assertSourceContains("@Access(PROPERTY)", cu); - - access.setValue(null); - assertSourceDoesNotContain("@Access(", cu); - } - - public void testGetAccessOnProperty() throws Exception { - ICompilationUnit cu = this.createTestAccessOnProperty(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableProperties().next(); - - Access2_0Annotation access = (Access2_0Annotation) attributeResource.getAnnotation(JPA2_0.ACCESS); - assertNotNull(access); - assertEquals(AccessType.PROPERTY, access.getValue()); - } - - public void testSetAccessOnProperty() throws Exception { - ICompilationUnit cu = this.createTestType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableProperties().next(); - - Access2_0Annotation access = (Access2_0Annotation) attributeResource.getAnnotation(JPA2_0.ACCESS); - assertNull(access); - - attributeResource.addAnnotation(JPA2_0.ACCESS); - assertSourceContains("@Access", cu); - - access = (Access2_0Annotation) attributeResource.getAnnotation(JPA2_0.ACCESS); - assertNotNull(access); - - access.setValue(AccessType.FIELD); - assertEquals(AccessType.FIELD, access.getValue()); - assertSourceContains("@Access(FIELD)", cu); - - access.setValue(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, access.getValue()); - assertSourceContains("@Access(PROPERTY)", cu); - - access.setValue(null); - assertSourceDoesNotContain("@Access(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverride2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverride2_0Tests.java deleted file mode 100644 index 7bdf3f7cef..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverride2_0Tests.java +++ /dev/null @@ -1,885 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; - -@SuppressWarnings("nls") -public class AssociationOverride2_0Tests extends JavaResourceModel2_0TestCase { - - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE"; - private static final String JOIN_TABLE_NAME = "MY_JOIN_TABLE"; - private static final String CATALOG_NAME = "MY_CATALOG"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - - public AssociationOverride2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestAssociationOverrideOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideOnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn})"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideWithJoinTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"" + JOIN_TABLE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithCatalog() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(catalog = \"" + CATALOG_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithSchema() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(schema = \"" + SCHEMA_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn}))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithInverseJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn}))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName("Foo"); - assertEquals("Foo", associationOverride.getName()); - assertSourceContains("@AssociationOverride(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName(null); - assertNull(associationOverride.getName()); - - assertSourceDoesNotContain("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AssociationOverride", cu); - } - - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(0, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - associationOverride.addJoinColumn(0); - associationOverride.addJoinColumn(1); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverride.addJoinColumn(0).setName("FOO"); - associationOverride.addJoinColumn(1); - associationOverride.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertNull(associationOverride.joinColumnAt(2).getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - associationOverride.addJoinColumn(0).setName("FOO"); - - Iterator joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\"), @JoinColumn})", cu); - - associationOverride.removeJoinColumn(1); - joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - - associationOverride.removeJoinColumn(0); - joinColumns = associationOverride.joinColumns(); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = @JoinColumn)", cu); - - - associationOverride.setName(null); - associationOverride.removeJoinColumn(0); - assertSourceDoesNotContain("@AssociationOverride(", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - associationOverride.moveJoinColumn(2, 0); - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertNull(associationOverride.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")})", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - associationOverride.moveJoinColumn(0, 2); - assertNull(associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertEquals("BAR", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")})", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(2, associationOverride.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn})", cu); - } - - public void testGetNullJoinTable() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertNotNull(associationOverride); - assertNull(joinTable); - } - - public void testJoinTableGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertEquals(JOIN_TABLE_NAME, joinTable.getName()); - } - - public void testJoinTableSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertEquals(JOIN_TABLE_NAME, joinTable.getName()); - - joinTable.setName("Foo"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"Foo\"))", cu); - - joinTable.setName(null); - assertNull(associationOverride.getJoinTable().getName()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable)", cu); - } - - public void testAddJoinTable() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertNull(joinTable); - - associationOverride.addJoinTable(); - joinTable = associationOverride.getJoinTable(); - assertNotNull(joinTable); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable)", cu); - } - - public void testRemoveJoinTable() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertNull(joinTable); - } - - public void testJoinTableGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testJoinTableSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", catalog = \"Foo\"))", cu); - } - - public void testJoinTableSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableGetSchema() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testJoinTableSetSchema() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", schema = \"Foo\"))", cu); - } - - public void testJoinTableSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testJoinTableUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testJoinTableUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testJoinTableAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint}))", cu); - } - - public void testJoinTableRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, table.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(2, table.uniqueConstraintsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))", cu); - - table.removeUniqueConstraint(0); - assertEquals("BAZ", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals(1, table.uniqueConstraintsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"})))", cu); - - table.removeUniqueConstraint(0); - assertEquals(0, table.uniqueConstraintsSize()); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))", cu); - - table.moveUniqueConstraint(2, 0); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"})}))", cu); - } - - public void testJoinTableMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))", cu); - - table.moveUniqueConstraint(0, 2); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})}))", cu); - } - - public void testJoinTableJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(0, table.joinColumnsSize()); - } - - public void testJoinTableJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - - table.addJoinColumn(0); - table.addJoinColumn(1); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testJoinTableJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testJoinTableAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - table.addJoinColumn(0).setName("FOO"); - table.addJoinColumn(1); - table.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - } - - public void testJoinTableRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addJoinColumn(0).setName("FOO"); - - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertEquals("BAR", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - - table.removeJoinColumn(1); - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals(2, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - - table.removeJoinColumn(0); - assertNull(table.joinColumnAt(0).getName()); - assertEquals(1, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = @JoinColumn))", cu); - - - table.removeJoinColumn(0); - assertEquals(0, table.joinColumnsSize()); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - - table.moveJoinColumn(2, 0); - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals("FOO", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testJoinTableMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - - - table.moveJoinColumn(0, 2); - assertNull(table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertEquals("BAR", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")}))", cu); - } - - public void testJoinTableSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn}))", cu); - } - - public void testJoinTableInverseJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(0, table.inverseJoinColumnsSize()); - } - - public void testInverseJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - - table.addInverseJoinColumn(0); - table.addInverseJoinColumn(1); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testJoinTableInverseJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testAddInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - table.addInverseJoinColumn(0).setName("FOO"); - table.addInverseJoinColumn(1); - table.addInverseJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.inverseJoinColumnAt(0).getName()); - assertEquals("FOO", table.inverseJoinColumnAt(1).getName()); - assertNull(table.inverseJoinColumnAt(2).getName()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", inverseJoinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - } - - public void testJoinTableRemoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addInverseJoinColumn(2).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(1); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn(name = \"FOO\")}))", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = @JoinColumn(name = \"FOO\")))", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableMoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addInverseJoinColumn(0).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(2, 0); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn, @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testJoinTableMoveInverseJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addInverseJoinColumn(1).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(0, 2); - inverseJoinColumns = table.inverseJoinColumns(); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn, @JoinColumn(name = \"BAR\"), @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testJoinTableSetInverseJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.inverseJoinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.inverseJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn}))", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverrides2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverrides2_0Tests.java deleted file mode 100644 index 7e16707b06..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/AssociationOverrides2_0Tests.java +++ /dev/null @@ -1,988 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -@SuppressWarnings("nls") -public class AssociationOverrides2_0Tests extends JavaResourceModel2_0TestCase { - - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE"; - private static final String JOIN_TABLE_NAME = "MY_JOIN_TABLE"; - private static final String CATALOG_NAME = "MY_CATALOG"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - - public AssociationOverrides2_0Tests(String name) { - super(name); - } - - private ICompilationUnit createTestAssociationOverrideOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn}))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\"))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideOnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDES, JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideWithJoinTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDES, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"" + JOIN_TABLE_NAME + "\")))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithCatalog() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDES, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(catalog = \"" + CATALOG_NAME + "\")))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithSchema() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDES, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(schema = \"" + SCHEMA_NAME + "\")))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDES, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDES, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn})))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideJoinTableWithInverseJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDES, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn})))"); - } - }); - } - - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.getNestedAnnotations().iterator().next(); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.getNestedAnnotations().iterator().next(); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName("Foo"); - assertEquals("Foo", associationOverride.getName()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.getNestedAnnotations().iterator().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName(null); - assertNull(associationOverride.getName()); - - assertSourceDoesNotContain("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AssociationOverride", cu); - assertSourceContains("@AssociationOverrides", cu); - } - - public void testAddAssociationOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES))); - } - - public void testAddAssociationOverrideToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name = \"BAR\")})", cu); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"BAZ\"),@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")), @AssociationOverride(name = \"BAR\")})", cu); - - Iterator associationOverrides = typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - assertEquals("BAZ", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("FOO", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("BAR", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES))); - } - - public void testRemoveAssociationOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name = \"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - assertSourceContains("@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\"))", cu); - } - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(0, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - associationOverride.addJoinColumn(0); - associationOverride.addJoinColumn(1); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - associationOverride.addJoinColumn(0).setName("FOO"); - associationOverride.addJoinColumn(1); - associationOverride.addJoinColumn(0).setName("BAR"); - - - Iterator joinColumns = associationOverride.joinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - associationOverride.addJoinColumn(0).setName("FOO"); - - Iterator joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\"), @JoinColumn}))", cu); - - associationOverride.removeJoinColumn(1); - joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - - associationOverride.removeJoinColumn(0); - joinColumns = associationOverride.joinColumns(); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = @JoinColumn))", cu); - - - associationOverride.setName(null); - associationOverride.removeJoinColumn(0); - assertSourceDoesNotContain("@AssociationOverride(", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - - associationOverride.moveJoinColumn(2, 0); - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertNull(associationOverride.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - associationOverride.moveJoinColumn(0, 2); - assertNull(associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertEquals("BAR", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")}))", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(2, associationOverride.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn}))", cu); - } - - public void testGetNullJoinTable() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertNotNull(associationOverride); - assertNull(joinTable); - } - - public void testJoinTableGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertEquals(JOIN_TABLE_NAME, joinTable.getName()); - } - - public void testJoinTableSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertEquals(JOIN_TABLE_NAME, joinTable.getName()); - - joinTable.setName("Foo"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"Foo\"))", cu); - - joinTable.setName(null); - assertNull(associationOverride.getJoinTable().getName()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable)", cu); - } - - public void testAddJoinTable() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertNull(joinTable); - - associationOverride.addJoinTable(); - joinTable = associationOverride.getJoinTable(); - assertNotNull(joinTable); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable)", cu); - } - - public void testRemoveJoinTable() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation joinTable = associationOverride.getJoinTable(); - assertNull(joinTable); - } - - public void testJoinTableGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testJoinTableSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", catalog = \"Foo\"))", cu); - } - - public void testJoinTableSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableGetSchema() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testJoinTableSetSchema() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", schema = \"Foo\"))", cu); - } - - public void testJoinTableSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testJoinTableUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testJoinTableUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testJoinTableAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint}))", cu); - } - - public void testJoinTableRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, table.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(2, table.uniqueConstraintsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))", cu); - - table.removeUniqueConstraint(0); - assertEquals("BAZ", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals(1, table.uniqueConstraintsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"})))", cu); - - table.removeUniqueConstraint(0); - assertEquals(0, table.uniqueConstraintsSize()); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))", cu); - - table.moveUniqueConstraint(2, 0); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"})}))", cu); - } - - public void testJoinTableMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))", cu); - - table.moveUniqueConstraint(0, 2); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})}))", cu); - } - - public void testJoinTableJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(0, table.joinColumnsSize()); - } - - public void testJoinTableJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - - table.addJoinColumn(0); - table.addJoinColumn(1); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testJoinTableJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testJoinTableAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - table.addJoinColumn(0).setName("FOO"); - table.addJoinColumn(1); - table.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - } - - public void testJoinTableRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addJoinColumn(0).setName("FOO"); - - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertEquals("BAR", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - - table.removeJoinColumn(1); - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals(2, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - - table.removeJoinColumn(0); - assertNull(table.joinColumnAt(0).getName()); - assertEquals(1, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = @JoinColumn))", cu); - - - table.removeJoinColumn(0); - assertEquals(0, table.joinColumnsSize()); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - - table.moveJoinColumn(2, 0); - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals("FOO", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testJoinTableMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - - - table.moveJoinColumn(0, 2); - assertNull(table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertEquals("BAR", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")}))", cu); - } - - public void testJoinTableSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn}))", cu); - } - - public void testJoinTableInverseJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(0, table.inverseJoinColumnsSize()); - } - - public void testInverseJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - - table.addInverseJoinColumn(0); - table.addInverseJoinColumn(1); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testJoinTableInverseJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testAddInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - table.addInverseJoinColumn(0).setName("FOO"); - table.addInverseJoinColumn(1); - table.addInverseJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.inverseJoinColumnAt(0).getName()); - assertEquals("FOO", table.inverseJoinColumnAt(1).getName()); - assertNull(table.inverseJoinColumnAt(2).getName()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", inverseJoinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - } - - public void testJoinTableRemoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addInverseJoinColumn(2).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(1); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn(name = \"FOO\")}))", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = @JoinColumn(name = \"FOO\")))", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testJoinTableMoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addInverseJoinColumn(0).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(2, 0); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn, @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testJoinTableMoveInverseJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - table.addInverseJoinColumn(1).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(0, 2); - inverseJoinColumns = table.inverseJoinColumns(); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn, @JoinColumn(name = \"BAR\"), @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testJoinTableSetInverseJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverride2_0Annotation associationOverride = (AssociationOverride2_0Annotation) associationOverrides.getNestedAnnotations().iterator().next(); - JoinTableAnnotation table = associationOverride.getJoinTable(); - - assertEquals(2, table.inverseJoinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.inverseJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn}))", cu); - } - - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Cacheable2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Cacheable2_0AnnotationTests.java deleted file mode 100644 index ad31e854e5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/Cacheable2_0AnnotationTests.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.Cacheable2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class Cacheable2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public Cacheable2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestCacheable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.CACHEABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cacheable"); - } - }); - } - - private ICompilationUnit createTestCacheableWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.CACHEABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cacheable(value=true)"); - } - }); - } - - - - public void testCacheableAnnotation() throws Exception { - ICompilationUnit cu = this.createTestCacheable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertNotNull(typeResource.getAnnotation(JPA2_0.CACHEABLE)); - - typeResource.removeAnnotation(JPA2_0.CACHEABLE); - assertNull(typeResource.getAnnotation(JPA2_0.CACHEABLE)); - - typeResource.addAnnotation(JPA2_0.CACHEABLE); - assertNotNull(typeResource.getAnnotation(JPA2_0.CACHEABLE)); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestCacheableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) typeResource.getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheableAnnotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestCacheableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) typeResource.getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheableAnnotation.getValue()); - - cacheableAnnotation.setValue(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - - assertSourceContains("@Cacheable(value=false)", cu); - - cacheableAnnotation.setValue(null); - cacheableAnnotation.setValue(Boolean.FALSE); - assertSourceContains("@Cacheable(false)", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestCacheableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) typeResource.getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheableAnnotation.getValue()); - - cacheableAnnotation.setValue(null); - assertNull(cacheableAnnotation.getValue()); - - assertSourceContains("@Cacheable", cu); - assertSourceDoesNotContain("value", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/CollectionTable2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/CollectionTable2_0AnnotationTests.java deleted file mode 100644 index 36929a6b17..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/CollectionTable2_0AnnotationTests.java +++ /dev/null @@ -1,498 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.CollectionTable2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; - -@SuppressWarnings("nls") -public class CollectionTable2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public CollectionTable2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestCollectionTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.COLLECTION_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@CollectionTable"); - } - }); - } - - private ICompilationUnit createTestCollectionTableWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.COLLECTION_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@CollectionTable(name = \"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestCollectionTableWithSchema() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.COLLECTION_TABLE); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@CollectionTable(schema = \"" + SCHEMA_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestCollectionTableWithCatalog() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.COLLECTION_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@CollectionTable(catalog = \"" + CATALOG_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestCollectionTableWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.COLLECTION_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@CollectionTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})"); - } - }); - } - - private ICompilationUnit createTestCollectionTableWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.COLLECTION_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@CollectionTable(joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertNotNull(table); - assertEquals(TABLE_NAME, table.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertNotNull(table); - assertNull(table.getName()); - assertNull(table.getCatalog()); - assertNull(table.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertNotNull(table); - assertNull(table.getName()); - - table.setName("Foo"); - assertEquals("Foo", table.getName()); - - assertSourceContains("@CollectionTable(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertEquals(TABLE_NAME, table.getName()); - - table.setName(null); - assertNull(table.getName()); - - assertSourceDoesNotContain("@CollectionTable(", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@CollectionTable(catalog = \"Foo\")", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@CollectionTable(", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@CollectionTable(schema = \"Foo\")", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@CollectionTable(", cu); - } - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@CollectionTable(uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint})", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, table.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(2, table.uniqueConstraintsSize()); - assertSourceContains("@CollectionTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.removeUniqueConstraint(0); - assertEquals("BAZ", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals(1, table.uniqueConstraintsSize()); - assertSourceContains("@CollectionTable(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"}))", cu); - - table.removeUniqueConstraint(0); - assertEquals(0, table.uniqueConstraintsSize()); - assertSourceDoesNotContain("@CollectionTable(", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertSourceContains("@CollectionTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.moveUniqueConstraint(2, 0); - assertSourceContains("@CollectionTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - assertSourceContains("@CollectionTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.moveUniqueConstraint(0, 2); - assertSourceContains("@CollectionTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})})", cu); - } - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - assertEquals(0, table.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - - table.addJoinColumn(0); - table.addJoinColumn(1); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestCollectionTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - table.addJoinColumn(0).setName("FOO"); - table.addJoinColumn(1); - table.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertSourceContains("@CollectionTable(joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - table.addJoinColumn(0).setName("FOO"); - - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertEquals("BAR", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - - table.removeJoinColumn(1); - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals(2, table.joinColumnsSize()); - assertSourceContains("@CollectionTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - - table.removeJoinColumn(0); - assertNull(table.joinColumnAt(0).getName()); - assertEquals(1, table.joinColumnsSize()); - assertSourceContains("@CollectionTable(joinColumns = @JoinColumn)", cu); - - - table.removeJoinColumn(0); - assertEquals(0, table.joinColumnsSize()); - assertSourceDoesNotContain("@CollectionTable(", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@CollectionTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - table.moveJoinColumn(2, 0); - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals("FOO", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@CollectionTable(joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")})", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@CollectionTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - - table.moveJoinColumn(0, 2); - assertNull(table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertEquals("BAR", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@CollectionTable(joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")})", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestCollectionTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - CollectionTable2_0Annotation table = (CollectionTable2_0Annotation) attributeResource.getAnnotation(JPA2_0.COLLECTION_TABLE); - - assertEquals(2, table.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@CollectionTable(joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn})", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java deleted file mode 100644 index 8afadd3146..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class ElementCollection2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public ElementCollection2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection"); - } - }); - } - - private ICompilationUnit createTestElementCollectionWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ELEMENT_COLLECTION, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestElementCollectionWithTargetClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection(targetClass = AnnotationTestType.class)"); - } - }); - } - - public void testElementCollection() throws Exception { - ICompilationUnit cu = this.createTestElementCollection(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertNotNull(elementCollection); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestElementCollectionWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertEquals(FetchType.EAGER, elementCollection.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestElementCollectionWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertEquals(FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, elementCollection.getFetch()); - - assertSourceContains("@ElementCollection(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestElementCollectionWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertEquals(FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(null); - assertNull(elementCollection.getFetch()); - - assertSourceContains("@ElementCollection", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetClass() throws Exception { - ICompilationUnit cu = this.createTestElementCollectionWithTargetClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertEquals(TYPE_NAME, elementCollection.getTargetClass()); - } - - public void testSetTargetClass() throws Exception { - ICompilationUnit cu = this.createTestElementCollectionWithTargetClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertEquals(TYPE_NAME, elementCollection.getTargetClass()); - - elementCollection.setTargetClass("Foo"); - - assertSourceContains("@ElementCollection(targetClass = Foo.class)", cu); - } - - public void testSetTargetClassNull() throws Exception { - ICompilationUnit cu = this.createTestElementCollectionWithTargetClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertEquals(TYPE_NAME, elementCollection.getTargetClass()); - - elementCollection.setTargetClass(null); - - assertSourceContains("@ElementCollection", cu); - assertSourceDoesNotContain("targetClass", cu); - } - - - public void testGetFullyQualifiedTargetClass() throws Exception { - ICompilationUnit cu = this.createTestElementCollectionWithTargetClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(JPA2_0.ELEMENT_COLLECTION); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, elementCollection.getFullyQualifiedTargetClassName()); - - elementCollection.setTargetClass("Foo"); - - assertSourceContains("@ElementCollection(targetClass = Foo.class)", cu); - - assertEquals("Foo", elementCollection.getTargetClass()); - - assertEquals("Foo", elementCollection.getFullyQualifiedTargetClassName()); //bug 196200 changed this - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResource2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResource2_0Tests.java deleted file mode 100644 index 2fb2276f7f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResource2_0Tests.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JavaResource2_0Tests { - - public static Test suite() { - TestSuite suite = new TestSuite(JavaResource2_0Tests.class.getPackage().getName()); - - suite.addTestSuite(Access2_0AnnotationTests.class); - suite.addTestSuite(AssociationOverride2_0Tests.class); - suite.addTestSuite(AssociationOverrides2_0Tests.class); - suite.addTestSuite(Cacheable2_0AnnotationTests.class); - suite.addTestSuite(CollectionTable2_0AnnotationTests.class); - suite.addTestSuite(ElementCollection2_0AnnotationTests.class); - suite.addTestSuite(ManyToMany2_0AnnotationTests.class); - suite.addTestSuite(ManyToOne2_0AnnotationTests.class); - suite.addTestSuite(MapKeyClass2_0AnnotationTests.class); - suite.addTestSuite(MapKeyColumn2_0AnnotationTests.class); - suite.addTestSuite(MapKeyEnumerated2_0AnnotationTests.class); - suite.addTestSuite(MapKeyJoinColumn2_0AnnotationTests.class); - suite.addTestSuite(MapKeyJoinColumns2_0AnnotationTests.class); - suite.addTestSuite(MapKeyTemporal2_0AnnotationTests.class); - suite.addTestSuite(MapsId2_0AnnotationTests.class); - suite.addTestSuite(OneToMany2_0AnnotationTests.class); - suite.addTestSuite(OneToOne2_0AnnotationTests.class); - suite.addTestSuite(OrderColumn2_0AnnotationTests.class); - suite.addTestSuite(SequenceGenerator2_0AnnotationTests.class); - - return suite; - } - - private JavaResource2_0Tests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java deleted file mode 100644 index a4a2a86e67..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider; -import org.eclipse.jpt.core.internal.jpa2.Generic2_0JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.tests.internal.resource.java.JpaJavaResourceModelTestCase; - -public class JavaResourceModel2_0TestCase extends JpaJavaResourceModelTestCase -{ - - public JavaResourceModel2_0TestCase(String name) { - super(name); - } - - @Override - protected JpaAnnotationProvider buildAnnotationProvider() { - return new GenericJpaAnnotationProvider( - Generic2_0JpaAnnotationDefinitionProvider.instance()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToMany2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToMany2_0AnnotationTests.java deleted file mode 100644 index 6d92bd37a9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToMany2_0AnnotationTests.java +++ /dev/null @@ -1,409 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.ManyToMany2_0Annotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; - -@SuppressWarnings("nls") -public class ManyToMany2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public ManyToMany2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithMappedBy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(mappedBy = \"foo\")"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testManyToMany() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertNotNull(manyToMany); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToMany.getFetch()); - - assertSourceContains("@ManyToMany(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(null); - assertNull(manyToMany.getFetch()); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("fetch", cu); - } - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - - manyToMany.setTargetEntity("Foo"); - - assertSourceContains("@ManyToMany(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - - manyToMany.setTargetEntity(null); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, manyToMany.getFullyQualifiedTargetEntityClassName()); - - manyToMany.setTargetEntity("Foo"); - - assertSourceContains("@ManyToMany(targetEntity = Foo.class)", cu); - - assertEquals("Foo", manyToMany.getTargetEntity()); - - assertEquals("Foo", manyToMany.getFullyQualifiedTargetEntityClassName()); //bug 196200 changed this - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals("foo", manyToMany.getMappedBy()); - } - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(null, manyToMany.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertNull(manyToMany.getMappedBy()); - manyToMany.setMappedBy("bar"); - assertEquals("bar", manyToMany.getMappedBy()); - - assertSourceContains("@ManyToMany(mappedBy = \"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals("foo", manyToMany.getMappedBy()); - - manyToMany.setMappedBy(null); - assertNull(manyToMany.getMappedBy()); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeAll()); - - manyToMany.setCascadeAll(true); - assertSourceContains("@ManyToMany(cascade = ALL)", cu); - - assertTrue(manyToMany.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(true); - assertSourceContains("@ManyToMany(cascade = MERGE)", cu); - - assertTrue(manyToMany.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadePersist()); - - manyToMany.setCascadePersist(true); - assertSourceContains("@ManyToMany(cascade = PERSIST)", cu); - - assertTrue(manyToMany.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeRemove()); - - manyToMany.setCascadeRemove(true); - assertSourceContains("@ManyToMany(cascade = REMOVE)", cu); - - assertTrue(manyToMany.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeRefresh()); - - manyToMany.setCascadeRefresh(true); - assertSourceContains("@ManyToMany(cascade = REFRESH)", cu); - - assertTrue(manyToMany.isCascadeRefresh()); - } - - public void testSetCascadeDetach() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToMany2_0Annotation manyToMany = (ManyToMany2_0Annotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeDetach()); - - manyToMany.setCascadeDetach(true); - assertSourceContains("@ManyToMany(cascade = DETACH)", cu); - - assertTrue(manyToMany.isCascadeDetach()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeAll()); - - manyToMany.setCascadeAll(true); - assertTrue(manyToMany.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@ManyToMany(cascade = CascadeType.ALL)", cu); - - manyToMany.setCascadeAll(false); - assertFalse(manyToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - manyToMany.setCascadeAll(false); - assertFalse(manyToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(false); //TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(false); - assertFalse(manyToMany.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeMerge()); - assertTrue(manyToMany.isCascadeRemove()); - - manyToMany.setCascadeMerge(false); - assertSourceContains("@ManyToMany(cascade = REMOVE)", cu); - - manyToMany.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToOne2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToOne2_0AnnotationTests.java deleted file mode 100644 index 69a2fa3668..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/ManyToOne2_0AnnotationTests.java +++ /dev/null @@ -1,402 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.ManyToOne2_0Annotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; - -@SuppressWarnings("nls") -public class ManyToOne2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public ManyToOne2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestManyToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithOptional() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(optional = true)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testManyToOne() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertNotNull(manyToOne); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - - manyToOne.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToOne.getFetch()); - - assertSourceContains("@ManyToOne(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - - manyToOne.setFetch(null); - assertNull(manyToOne.getFetch()); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - - manyToOne.setTargetEntity("Foo"); - - assertSourceContains("@ManyToOne(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - - manyToOne.setTargetEntity(null); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, manyToOne.getFullyQualifiedTargetEntityClassName()); - - manyToOne.setTargetEntity("Foo"); - - assertSourceContains("@ManyToOne(targetEntity = Foo.class)", cu); - - assertEquals("Foo", manyToOne.getTargetEntity()); - - assertEquals("Foo", manyToOne.getFullyQualifiedTargetEntityClassName());//bug 196200 changed this - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - assertSourceContains("@ManyToOne(optional = false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(null); - assertNull(manyToOne.getOptional()); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeAll()); - - manyToOne.setCascadeAll(true); - assertSourceContains("@ManyToOne(cascade = ALL)", cu); - - assertTrue(manyToOne.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(true); - assertSourceContains("@ManyToOne(cascade = MERGE)", cu); - - assertTrue(manyToOne.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadePersist()); - - manyToOne.setCascadePersist(true); - assertSourceContains("@ManyToOne(cascade = PERSIST)", cu); - - assertTrue(manyToOne.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeRemove()); - - manyToOne.setCascadeRemove(true); - assertSourceContains("@ManyToOne(cascade = REMOVE)", cu); - - assertTrue(manyToOne.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeRefresh()); - - manyToOne.setCascadeRefresh(true); - assertSourceContains("@ManyToOne(cascade = REFRESH)", cu); - - assertTrue(manyToOne.isCascadeRefresh()); - } - - public void testSetCascadeDetach() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOne2_0Annotation manyToOne = (ManyToOne2_0Annotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeDetach()); - - manyToOne.setCascadeDetach(true); - assertSourceContains("@ManyToOne(cascade = DETACH)", cu); - - assertTrue(manyToOne.isCascadeDetach()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeAll()); - - manyToOne.setCascadeAll(true); - assertTrue(manyToOne.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@ManyToOne(cascade = CascadeType.ALL)", cu); - - manyToOne.setCascadeAll(false); - assertFalse(manyToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - manyToOne.setCascadeAll(false); - assertFalse(manyToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(false); - assertFalse(manyToOne.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeMerge()); - assertTrue(manyToOne.isCascadeRemove()); - - manyToOne.setCascadeMerge(false); - assertSourceContains("@ManyToOne(cascade = REMOVE)", cu); - - manyToOne.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java deleted file mode 100644 index a6895a867e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class MapKeyClass2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - private static final String MAP_KEY_CLASS_VALUE = "MyClass"; - - public MapKeyClass2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestMapKeyClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_CLASS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyClass"); - } - }); - } - - private ICompilationUnit createTestMapKeyClassWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_CLASS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyClass(" + MAP_KEY_CLASS_VALUE + ".class)"); - } - }); - } - - public void testMapKeyClass() throws Exception { - ICompilationUnit cu = this.createTestMapKeyClass(); - JavaResourcePersistentType resourceType = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute resourceAttribute = resourceType.fields().next(); - - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAP_KEY_CLASS); - assertNotNull(mapKeyClass); - assertNull(mapKeyClass.getValue()); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestMapKeyClassWithValue(); - JavaResourcePersistentType resourceType = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute resourceAttribute = resourceType.fields().next(); - - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAP_KEY_CLASS); - assertEquals(MAP_KEY_CLASS_VALUE, mapKeyClass.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestMapKeyClassWithValue(); - JavaResourcePersistentType resourceType = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute resourceAttribute = resourceType.fields().next(); - - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAP_KEY_CLASS); - assertEquals(MAP_KEY_CLASS_VALUE, mapKeyClass.getValue()); - - mapKeyClass.setValue("foo"); - assertEquals("foo", mapKeyClass.getValue()); - - assertSourceContains("@MapKeyClass(foo.class)", cu); - - mapKeyClass.setValue(null); - - assertSourceDoesNotContain("@MapKeyClass(", cu); - } - - public void testGetFullyQualifiedClass() throws Exception { - ICompilationUnit cu = this.createTestMapKeyClassWithValue(); - JavaResourcePersistentType resourceType = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute resourceAttribute = resourceType.fields().next(); - - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAP_KEY_CLASS); - assertNotNull(mapKeyClass.getValue()); - assertEquals("MyClass", mapKeyClass.getFullyQualifiedClassName()); //bug 196200 changed this - - - mapKeyClass.setValue(TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, mapKeyClass.getFullyQualifiedClassName()); - assertSourceContains("@MapKeyClass(" + TYPE_NAME + ".class)", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyColumn2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyColumn2_0AnnotationTests.java deleted file mode 100644 index 2875a61172..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyColumn2_0AnnotationTests.java +++ /dev/null @@ -1,404 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class MapKeyColumn2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - - public MapKeyColumn2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyColumn"); - } - }); - } - - private ICompilationUnit createTestColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyColumn(name = \"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyColumn(table = \"" + COLUMN_TABLE + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyColumn(" + booleanElement + " = true)"); - } - }); - } - - private ICompilationUnit createTestColumnWithIntElement(final String intElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyColumn(" + intElement + " = 5)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@MapKeyColumn(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@MapKeyColumn(table = \"Foo\")", cu); - - - column.setTable(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@MapKeyColumn(columnDefinition = \"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(Boolean.TRUE, column.getUnique()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUnique()); - - assertSourceContains("@MapKeyColumn(unique = false)", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(Boolean.TRUE, column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getNullable()); - - assertSourceContains("@MapKeyColumn(nullable = false)", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(Boolean.TRUE, column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getInsertable()); - - assertSourceContains("@MapKeyColumn(insertable = false)", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(Boolean.TRUE, column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUpdatable()); - - assertSourceContains("@MapKeyColumn(updatable = false)", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetLength() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("length"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(Integer.valueOf(5), column.getLength()); - } - - public void testSetLength() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getLength()); - - column.setLength(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getLength()); - - assertSourceContains("@MapKeyColumn(length = 5)", cu); - - column.setLength(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetPrecision() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("precision"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(Integer.valueOf(5), column.getPrecision()); - } - - public void testSetPrecision() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertEquals(null, column.getPrecision()); - - column.setPrecision(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getPrecision()); - - assertSourceContains("@MapKeyColumn(precision = 5)", cu); - - column.setPrecision(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } - - public void testGetScale() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("scale"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertEquals(Integer.valueOf(5), column.getScale()); - } - - public void testSetScale() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_COLUMN); - - assertNotNull(column); - assertNull(column.getScale()); - - column.setScale(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getScale()); - - assertSourceContains("@MapKeyColumn(scale = 5)", cu); - - column.setScale(null); - assertSourceDoesNotContain("@MapKeyColumn(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyEnumerated2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyEnumerated2_0AnnotationTests.java deleted file mode 100644 index 77b4c29df7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyEnumerated2_0AnnotationTests.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyEnumerated2_0Annotation; -import org.eclipse.jpt.core.resource.java.EnumType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class MapKeyEnumerated2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public MapKeyEnumerated2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestMapKeyEnumerated() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_ENUMERATED); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyEnumerated"); - } - }); - } - - private ICompilationUnit createTestMapKeyEnumeratedWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyEnumerated(EnumType.ORDINAL)"); - } - }); - } - - public void testMapKeyEnumerated() throws Exception { - ICompilationUnit cu = this.createTestMapKeyEnumerated(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_ENUMERATED); - assertNotNull(enumerated); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestMapKeyEnumeratedWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_ENUMERATED); - assertEquals(EnumType.ORDINAL, enumerated.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestMapKeyEnumerated(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyEnumerated2_0Annotation enumerated = (MapKeyEnumerated2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_ENUMERATED); - - enumerated.setValue(EnumType.STRING); - - assertSourceContains("@MapKeyEnumerated(STRING)", cu); - - enumerated.setValue(null); - - assertSourceDoesNotContain("@MapKeyEnumerated(", cu); - assertSourceContains("@MapKeyEnumerated", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumn2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumn2_0AnnotationTests.java deleted file mode 100644 index e13ce6689e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumn2_0AnnotationTests.java +++ /dev/null @@ -1,352 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class MapKeyJoinColumn2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public MapKeyJoinColumn2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumn"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumn(name = \"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumn(table = \"" + COLUMN_TABLE + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithReferencedColumnName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumn(referencedColumnName = \"" + COLUMN_REFERENCED_COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumn(" + booleanElement + " = true)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getReferencedColumnName()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@MapKeyJoinColumn(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@MapKeyJoinColumn(table = \"Foo\")", cu); - - - column.setTable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@MapKeyJoinColumn(referencedColumnName = \"Foo\")", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@MapKeyJoinColumn(columnDefinition = \"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getUnique()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUnique()); - - assertSourceContains("@MapKeyJoinColumn(unique = false)", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getNullable()); - - assertSourceContains("@MapKeyJoinColumn(nullable = false)", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getInsertable()); - - assertSourceContains("@MapKeyJoinColumn(insertable = false)", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUpdatable()); - - assertSourceContains("@MapKeyJoinColumn(updatable = false)", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumns2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumns2_0AnnotationTests.java deleted file mode 100644 index 9be678d5e6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyJoinColumns2_0AnnotationTests.java +++ /dev/null @@ -1,420 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyJoinColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -@SuppressWarnings("nls") -public class MapKeyJoinColumns2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public MapKeyJoinColumns2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumns(@MapKeyJoinColumn)"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumns(@MapKeyJoinColumn(name = \"" + COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumns(@MapKeyJoinColumn(table = \"" + COLUMN_TABLE + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithReferencedColumnName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumns(@MapKeyJoinColumn(referencedColumnName = \"" + COLUMN_REFERENCED_COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumns(@MapKeyJoinColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumns(@MapKeyJoinColumn(" + booleanElement + " = true))"); - } - }); - } - - private ICompilationUnit createTestJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyJoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(name = \"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(table = \"Foo\"))", cu); - - - column.setTable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(referencedColumnName = \"Foo\"))", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(columnDefinition = \"Foo\"))", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertTrue(column.getUnique().booleanValue()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(Boolean.FALSE); - assertFalse(column.getUnique().booleanValue()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(unique = false))", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertTrue(column.getNullable().booleanValue()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertFalse(column.getNullable().booleanValue()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(nullable = false))", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertTrue(column.getInsertable().booleanValue()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertFalse(column.getInsertable().booleanValue()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(insertable = false))", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertTrue(column.getUpdatable().booleanValue()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - MapKeyJoinColumn2_0Annotation column = (MapKeyJoinColumn2_0Annotation) attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertFalse(column.getUpdatable().booleanValue()); - - assertSourceContains("@MapKeyJoinColumns(@MapKeyJoinColumn(updatable = false))", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@MapKeyJoinColumn(", cu); - } - - - public void testAddJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) attributeResource.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@MapKeyJoinColumns({@MapKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@MapKeyJoinColumn(name = \"FOO\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMNS)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS))); - } - - public void testAddJoinColumnToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) attributeResource.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@MapKeyJoinColumns({@MapKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@MapKeyJoinColumn(name = \"FOO\")})", cu); - - joinColumn = (MapKeyJoinColumn2_0Annotation) attributeResource.addAnnotation(0, JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - joinColumn.setName("BAZ"); - assertSourceContains("@MapKeyJoinColumns({@MapKeyJoinColumn(name = \"BAZ\"),@MapKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"), @MapKeyJoinColumn(name = \"FOO\")})", cu); - - Iterator joinColumns = attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - assertEquals("BAZ", ((MapKeyJoinColumn2_0Annotation) joinColumns.next()).getName()); - assertEquals("BAR", ((MapKeyJoinColumn2_0Annotation) joinColumns.next()).getName()); - assertEquals("FOO", ((MapKeyJoinColumn2_0Annotation) joinColumns.next()).getName()); - - assertNull(attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA2_0.MAP_KEY_JOIN_COLUMNS)); - assertEquals(3, CollectionTools.size(attributeResource.annotations(JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS))); - } - - - public void testRemoveJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyJoinColumn2_0Annotation joinColumn = (MapKeyJoinColumn2_0Annotation) attributeResource.addAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@MapKeyJoinColumns({@MapKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@MapKeyJoinColumn(name = \"FOO\")})", cu); - - attributeResource.removeAnnotation(1, JPA2_0.MAP_KEY_JOIN_COLUMN, JPA2_0.MAP_KEY_JOIN_COLUMNS); - assertSourceContains("@MapKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\")", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyTemporal2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyTemporal2_0AnnotationTests.java deleted file mode 100644 index 4b1868e84e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapKeyTemporal2_0AnnotationTests.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyTemporal2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TemporalType; - -@SuppressWarnings("nls") -public class MapKeyTemporal2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public MapKeyTemporal2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_TEMPORAL); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyTemporal"); - } - }); - } - - private ICompilationUnit createTestTemporalWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAP_KEY_TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKeyTemporal(TemporalType.DATE)"); - } - }); - } - - public void testTemporal() throws Exception { - ICompilationUnit cu = this.createTestTemporal(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_TEMPORAL); - assertNotNull(temporal); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestTemporalWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_TEMPORAL); - assertEquals(TemporalType.DATE, temporal.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestTemporal(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyTemporal2_0Annotation temporal = (MapKeyTemporal2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAP_KEY_TEMPORAL); - - temporal.setValue(TemporalType.TIME); - - assertSourceContains("@MapKeyTemporal(TIME)", cu); - - temporal.setValue(null); - - assertSourceDoesNotContain("@MapKeyTemporal(", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapsId2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapsId2_0AnnotationTests.java deleted file mode 100644 index 30a2a6989e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/MapsId2_0AnnotationTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapsId2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class MapsId2_0AnnotationTests - extends JavaResourceModel2_0TestCase -{ - public MapsId2_0AnnotationTests(String name) { - super(name); - } - - - private ICompilationUnit createTestMapsId() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAPS_ID); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapsId"); - } - }); - } - - private ICompilationUnit createTestMapsIdWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.MAPS_ID); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapsId(\"foo\")"); - } - }); - } - - public void testMapsId() throws Exception { - ICompilationUnit cu = this.createTestMapsId(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapsId2_0Annotation annotation = (MapsId2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAPS_ID); - assertNotNull(annotation); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestMapsIdWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapsId2_0Annotation annotation = (MapsId2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAPS_ID); - assertEquals("foo", annotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestMapsId(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapsId2_0Annotation annotation = (MapsId2_0Annotation) attributeResource.getAnnotation(JPA2_0.MAPS_ID); - annotation.setValue("foo"); - assertSourceContains("@MapsId(\"foo\")", cu); - - annotation.setValue(null); - assertSourceContains("@MapsId", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToMany2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToMany2_0AnnotationTests.java deleted file mode 100644 index 07ba1c5f66..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToMany2_0AnnotationTests.java +++ /dev/null @@ -1,412 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.OneToMany2_0Annotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; - -@SuppressWarnings("nls") -public class OneToMany2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public OneToMany2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestOneToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithMappedBy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(mappedBy = \"foo\")"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testOneToMany() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertNotNull(oneToMany); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToMany.getFetch()); - - assertSourceContains("@OneToMany(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(null); - assertNull(oneToMany.getFetch()); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - - oneToMany.setTargetEntity("Foo"); - - assertSourceContains("@OneToMany(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - - oneToMany.setTargetEntity(null); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, oneToMany.getFullyQualifiedTargetEntityClassName()); - - oneToMany.setTargetEntity("Foo"); - - assertSourceContains("@OneToMany(targetEntity = Foo.class)", cu); - - assertEquals("Foo", oneToMany.getTargetEntity()); - - assertEquals("Foo", oneToMany.getFullyQualifiedTargetEntityClassName()); //bug 196200 changed this - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals("foo", oneToMany.getMappedBy()); - } - - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(null, oneToMany.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertNull(oneToMany.getMappedBy()); - oneToMany.setMappedBy("bar"); - assertEquals("bar", oneToMany.getMappedBy()); - - assertSourceContains("@OneToMany(mappedBy = \"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals("foo", oneToMany.getMappedBy()); - - oneToMany.setMappedBy(null); - assertNull(oneToMany.getMappedBy()); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeAll()); - - oneToMany.setCascadeAll(true); - assertSourceContains("@OneToMany(cascade = ALL)", cu); - - assertTrue(oneToMany.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(true); - assertSourceContains("@OneToMany(cascade = MERGE)", cu); - - assertTrue(oneToMany.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadePersist()); - - oneToMany.setCascadePersist(true); - assertSourceContains("@OneToMany(cascade = PERSIST)", cu); - - assertTrue(oneToMany.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeRemove()); - - oneToMany.setCascadeRemove(true); - assertSourceContains("@OneToMany(cascade = REMOVE)", cu); - - assertTrue(oneToMany.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeRefresh()); - - oneToMany.setCascadeRefresh(true); - assertSourceContains("@OneToMany(cascade = REFRESH)", cu); - - assertTrue(oneToMany.isCascadeRefresh()); - } - - public void testSetCascadeDetach() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeDetach()); - - oneToMany.setCascadeDetach(true); - assertSourceContains("@OneToMany(cascade = DETACH)", cu); - - assertTrue(oneToMany.isCascadeDetach()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeAll()); - - oneToMany.setCascadeAll(true); - assertTrue(oneToMany.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@OneToMany(cascade = CascadeType.ALL)", cu); - - oneToMany.setCascadeAll(false); - assertFalse(oneToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - oneToMany.setCascadeAll(false); - assertFalse(oneToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(false); - assertFalse(oneToMany.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeMerge()); - assertTrue(oneToMany.isCascadeRemove()); - - oneToMany.setCascadeMerge(false); - assertSourceContains("@OneToMany(cascade = REMOVE)", cu); - - oneToMany.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToOne2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToOne2_0AnnotationTests.java deleted file mode 100644 index fcb88124f3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OneToOne2_0AnnotationTests.java +++ /dev/null @@ -1,462 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.OneToOne2_0Annotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; - -@SuppressWarnings("nls") -public class OneToOne2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - public OneToOne2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithOptional() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(optional = true)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithMappedBy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(mappedBy = \"foo\")"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testOneToOne() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertNotNull(oneToOne); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToOne.getFetch()); - - assertSourceContains("@OneToOne(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(null); - assertNull(oneToOne.getFetch()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - - oneToOne.setTargetEntity("Foo"); - - assertSourceContains("@OneToOne(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - - oneToOne.setTargetEntity(null); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, oneToOne.getFullyQualifiedTargetEntityClassName()); - - oneToOne.setTargetEntity("Foo"); - - assertSourceContains("@OneToOne(targetEntity = Foo.class)", cu); - - assertEquals("Foo", oneToOne.getTargetEntity()); - - assertEquals("Foo", oneToOne.getFullyQualifiedTargetEntityClassName()); //bug 196200 changed this - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - assertSourceContains("@OneToOne(optional = false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(null); - assertNull(oneToOne.getOptional()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals("foo", oneToOne.getMappedBy()); - } - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(null, oneToOne.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertNull(oneToOne.getMappedBy()); - oneToOne.setMappedBy("bar"); - assertEquals("bar", oneToOne.getMappedBy()); - - assertSourceContains("@OneToOne(mappedBy = \"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals("foo", oneToOne.getMappedBy()); - - oneToOne.setMappedBy(null); - assertNull(oneToOne.getMappedBy()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeAll()); - - oneToOne.setCascadeAll(true); - assertSourceContains("@OneToOne(cascade = ALL)", cu); - - assertTrue(oneToOne.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(true); - assertSourceContains("@OneToOne(cascade = MERGE)", cu); - - assertTrue(oneToOne.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadePersist()); - - oneToOne.setCascadePersist(true); - assertSourceContains("@OneToOne(cascade = PERSIST)", cu); - - assertTrue(oneToOne.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeRemove()); - - oneToOne.setCascadeRemove(true); - assertSourceContains("@OneToOne(cascade = REMOVE)", cu); - - assertTrue(oneToOne.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeRefresh()); - - oneToOne.setCascadeRefresh(true); - assertSourceContains("@OneToOne(cascade = REFRESH)", cu); - - assertTrue(oneToOne.isCascadeRefresh()); - } - - public void testSetCascadeDetach() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeDetach()); - - oneToOne.setCascadeDetach(true); - assertSourceContains("@OneToOne(cascade = DETACH)", cu); - - assertTrue(oneToOne.isCascadeDetach()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeAll()); - - oneToOne.setCascadeAll(true); - assertTrue(oneToOne.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@OneToOne(cascade = CascadeType.ALL)", cu); - - oneToOne.setCascadeAll(false); - assertFalse(oneToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - oneToOne.setCascadeAll(false); - assertFalse(oneToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(false); - assertFalse(oneToOne.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeMerge()); - assertTrue(oneToOne.isCascadeRemove()); - - oneToOne.setCascadeMerge(false); - assertSourceContains("@OneToOne(cascade = REMOVE)", cu); - - oneToOne.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OrderColumn2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OrderColumn2_0AnnotationTests.java deleted file mode 100644 index eca9a4eab1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/OrderColumn2_0AnnotationTests.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.OrderColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class OrderColumn2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - - public OrderColumn2_0AnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestOrderColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ORDER_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderColumn"); - } - }); - } - - private ICompilationUnit createTestOrderColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ORDER_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderColumn(name = \"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestOrderColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ORDER_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestOrderColumnWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA2_0.ORDER_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderColumn(" + booleanElement + " = true)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestOrderColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestOrderColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUpdatable()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestOrderColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@OrderColumn(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestOrderColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertNotNull(column); - assertSourceContains("@OrderColumn", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestOrderColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestOrderColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@OrderColumn(columnDefinition = \"Foo\")", cu); - - - column.setColumnDefinition(null); - column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertNotNull(column); - assertSourceContains("@OrderColumn", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestOrderColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertEquals(Boolean.TRUE, column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestOrderColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getNullable()); - - assertSourceContains("@OrderColumn(nullable = false)", cu); - - column.setNullable(null); - column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertNotNull(column); - assertSourceContains("@OrderColumn", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestOrderColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertEquals(Boolean.TRUE, column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestOrderColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getInsertable()); - - assertSourceContains("@OrderColumn(insertable = false)", cu); - - column.setInsertable(null); - column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertNotNull(column); - assertSourceContains("@OrderColumn", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestOrderColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertEquals(Boolean.TRUE, column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestOrderColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - OrderColumn2_0Annotation column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUpdatable()); - - assertSourceContains("@OrderColumn(updatable = false)", cu); - - column.setUpdatable(null); - - column = (OrderColumn2_0Annotation) attributeResource.getAnnotation(JPA2_0.ORDER_COLUMN); - assertNotNull(column); - assertSourceContains("@OrderColumn", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationTests.java deleted file mode 100644 index 6d8184b2af..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/resource/java/SequenceGenerator2_0AnnotationTests.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.jpa2.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.internal.jpa2.Generic2_0JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.jpa2.resource.java.SequenceGenerator2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -/** - * SequenceGenerator2_0Tests - */ -@SuppressWarnings("nls") -public class SequenceGenerator2_0AnnotationTests extends JavaResourceModel2_0TestCase { - - private static final String GENERATOR_CATALOG = "TEST_CATALOG"; - private static final String GENERATOR_SCHEMA = "TEST_SCHEMA"; - - public SequenceGenerator2_0AnnotationTests(String name) { - super(name); - } - - @Override - protected JpaAnnotationDefinitionProvider annotationDefinitionProvider() { - return Generic2_0JpaAnnotationDefinitionProvider.instance(); - } - - // ********** catalog ********** - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithCatalog(); - JavaResourcePersistentType typeResource = this.buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGenerator2_0Annotation sequenceGenerator = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_CATALOG, sequenceGenerator.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGenerator2_0Annotation sequenceGenerator = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_CATALOG, sequenceGenerator.getCatalog()); - - sequenceGenerator.setCatalog("foo"); - assertEquals("foo", sequenceGenerator.getCatalog()); - - assertSourceContains("@SequenceGenerator(catalog = \"foo\")", cu); - - sequenceGenerator.setCatalog(null); - assertNull(sequenceGenerator.getCatalog()); - - assertSourceDoesNotContain("@SequenceGenerator(", cu); - } - - // ********** schema ********** - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithSchema(); - JavaResourcePersistentType typeResource = this.buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGenerator2_0Annotation sequenceGenerator = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_SCHEMA, sequenceGenerator.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithSchema(); - JavaResourcePersistentType typeResource = this.buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGenerator2_0Annotation sequenceGenerator = (SequenceGenerator2_0Annotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_SCHEMA, sequenceGenerator.getSchema()); - - sequenceGenerator.setSchema("foo"); - assertEquals("foo", sequenceGenerator.getSchema()); - - assertSourceContains("@SequenceGenerator(schema = \"foo\")", cu); - - sequenceGenerator.setSchema(null); - assertNull(sequenceGenerator.getSchema()); - - assertSourceDoesNotContain("@SequenceGenerator(", cu); - } - - // ********** utility ********** - - protected ICompilationUnit createTestSequenceGeneratorWithStringElement(final String elementName, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator(" + elementName + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestSequenceGeneratorWithCatalog() throws Exception { - return this.createTestSequenceGeneratorWithStringElement("catalog", GENERATOR_CATALOG); - } - - private ICompilationUnit createTestSequenceGeneratorWithSchema() throws Exception { - return this.createTestSequenceGeneratorWithStringElement("schema", GENERATOR_SCHEMA); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaProjectManagerTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaProjectManagerTests.java deleted file mode 100644 index a3a169cf45..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaProjectManagerTests.java +++ /dev/null @@ -1,262 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.model; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import junit.framework.TestCase; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.common.core.tests.internal.projects.TestFacetedProject; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.core.tests.internal.projects.TestPlatformProject; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class JpaProjectManagerTests extends TestCase { - - /** carriage return */ - public static final String CR = System.getProperty("line.separator"); - - protected TestFacetedProject testProject; - public JpaProjectManagerTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (this.debug()) { - this.printName(); - } - this.testProject = this.buildTestProject(); - } - - private boolean debug() { - Boolean debug = (Boolean) ReflectionTools.getStaticFieldValue(this.getGenericJpaProjectManagerClass(), "DEBUG"); - return debug.booleanValue(); - } - - // GenericJpaProjectManager is package-private - private Class getGenericJpaProjectManagerClass() { - return JptCorePlugin.getJpaProjectManager().getClass(); - } - - private void printName() { - String name = this.getName(); - System.out.println(); - System.out.println(); - this.printNameBorder(name); - System.out.println(name); - this.printNameBorder(name); - } - - private void printNameBorder(String name) { - for (int i = name.length(); i-- > 0; ) { - System.out.print('='); - } - System.out.println(); - } - - @Override - protected void tearDown() throws Exception { - this.testProject.getProject().delete(true, true, null); - this.testProject = null; - super.tearDown(); - } - - /** - * Builds a project with the java and utility facets installed, and with - * pre-existing entities added. - */ - private TestFacetedProject buildTestProject() throws Exception { - TestJavaProject tjp = TestJavaProject.buildJavaProject(this.getClass().getSimpleName(), true); - tjp.createCompilationUnit("test.pkg", "TestEntity.java", "@Entity public class TestEntity {}"); - tjp.createCompilationUnit("test.pkg", "TestEntity2.java", "@Entity public class TestEntity2 {}"); - return tjp; - } - - private IFile getFile(TestPlatformProject p, String path) { - return p.getProject().getFile(new Path(path)); - } - - /** - * make sure the DEBUG constants are 'false' before checking in the code - */ - public void testDEBUG() { - this.verifyDEBUG(this.getGenericJpaProjectManagerClass()); - } - - private void verifyDEBUG(Class clazz) { - assertFalse("Recompile with \"DEBUG = false\": " + clazz.getName(), - ((Boolean) ReflectionTools.getStaticFieldValue(clazz, "DEBUG")).booleanValue()); - } - - public void testJpaProjectManager() { - assertNotNull(JptCorePlugin.getJpaProjectManager()); - } - - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider()); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - public void testProjectCloseReopen() throws Exception { - this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel()); - JpaProject jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNotNull(jpaProject); - - this.testProject.getProject().close(null); - assertFalse("Project is not closed", this.testProject.getProject().isOpen()); - jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNull("JpaProject is not null", jpaProject); - - this.testProject.getProject().open(null); - assertTrue(this.testProject.getProject().isOpen()); - jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNotNull("JpaProject is null", jpaProject); - assertEquals(4, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java"))); - - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml"))); - } - - public void testProjectDeleteReimport() throws Exception { - this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel()); - JpaProject jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNotNull(jpaProject); - assertEquals(1, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - - this.testProject.getProject().delete(false, true, null); - jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNull(jpaProject); - assertEquals(0, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - assertEquals(0, ResourcesPlugin.getWorkspace().getRoot().getProjects().length); - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(this.testProject.getProject().getName()); - project.create(null); - assertEquals(1, ResourcesPlugin.getWorkspace().getRoot().getProjects().length); - project.open(null); - - assertTrue(project.isOpen()); - assertTrue(JpaFacet.isInstalled(project)); - jpaProject = JptCorePlugin.getJpaProject(project); - assertNotNull(jpaProject); - assertEquals(4, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml"))); - } - - public void testFacetInstallUninstall() throws Exception { - assertNull(JptCorePlugin.getJpaProject(this.testProject.getProject())); - - this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel()); - assertEquals(1, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - JpaProject jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNotNull(jpaProject); - assertEquals(4, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java"))); - - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml"))); - - this.testProject.uninstallFacet(JpaFacet.ID, "1.0"); - assertEquals(0, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNull(jpaProject); - } - - public void testEditFacetSettingsFileAddThenRemoveJpaFacet() throws Exception { - assertNull(JptCorePlugin.getJpaProject(this.testProject.getProject())); - - // add the JPA facet by modifying the facet settings file directly - IFile facetSettingsFile = this.getFile(this.testProject, ".settings/org.eclipse.wst.common.project.facet.core.xml"); - InputStream inStream = new BufferedInputStream(facetSettingsFile.getContents()); - int fileSize = inStream.available(); - byte[] buf = new byte[fileSize]; - inStream.read(buf); - inStream.close(); - - String oldDocument = new String(buf); - String oldString = ""; - String newString = oldString + CR + " " + ""; - String newDocument = oldDocument.replaceAll(oldString, newString); - - facetSettingsFile.setContents(new ByteArrayInputStream(newDocument.getBytes()), false, false, null); - - assertEquals(1, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - JpaProject jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNotNull(jpaProject); - // persistence.xml and orm.xml do not get created in this situation (?) - assertEquals(2, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java"))); -// assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml"))); -// assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml"))); - - - // now remove the JPA facet - facetSettingsFile.setContents(new ByteArrayInputStream(oldDocument.getBytes()), false, false, null); - assertEquals(0, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNull(jpaProject); - } - - public void testEditFacetSettingsFileRemoveThenAddJpaFacet() throws Exception { - this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel()); - JpaProject jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNotNull(jpaProject); - - // remove the JPA facet by modifying the facet settings file directly - IFile facetSettingsFile = this.getFile(this.testProject, ".settings/org.eclipse.wst.common.project.facet.core.xml"); - InputStream inStream = new BufferedInputStream(facetSettingsFile.getContents()); - int fileSize = inStream.available(); - byte[] buf = new byte[fileSize]; - inStream.read(buf); - inStream.close(); - - String oldDocument = new String(buf); - String oldString = "" + CR + " " + ""; - String newString = ""; - String newDocument = oldDocument.replaceAll(oldString, newString); - - facetSettingsFile.setContents(new ByteArrayInputStream(newDocument.getBytes()), false, false, null); - assertEquals(0, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNull(jpaProject); - - // now add the JPA facet back - facetSettingsFile.setContents(new ByteArrayInputStream(oldDocument.getBytes()), false, false, null); - assertEquals(1, JptCorePlugin.getJpaProjectManager().getJpaProjectsSize()); - jpaProject = JptCorePlugin.getJpaProject(this.testProject.getProject()); - assertNotNull(jpaProject); - assertEquals(4, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml"))); - assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml"))); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JptCoreModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JptCoreModelTests.java deleted file mode 100644 index 14a0130457..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JptCoreModelTests.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.model; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptCoreModelTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreModelTests.class.getPackage().getName()); - suite.addTestSuite(JpaProjectManagerTests.class); - return suite; - } - - private JptCoreModelTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/BaseJpaPlatformTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/BaseJpaPlatformTests.java deleted file mode 100644 index 622c9cc7cf..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/BaseJpaPlatformTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.platform; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; - -@SuppressWarnings("nls") -public class BaseJpaPlatformTests extends TestCase -{ - protected TestJpaProject jpaProject; - - protected static final String PROJECT_NAME = "PlatformTestProject"; - protected static final String PACKAGE_NAME = "platform.test"; - protected static final String PERSISTENCE_XML_LOCATION = "src/META-INF/persistence.xml"; - protected static final String ORM_XML_LOCATION = "src/META-INF/orm.xml"; - - - public BaseJpaPlatformTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.jpaProject = this.buildJpaProject(PROJECT_NAME, false); // false = no auto-build - } - - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild) throws Exception { - return new TestJpaProject(projectName, autoBuild); // false = no auto-build - } - - @Override - protected void tearDown() throws Exception { - this.jpaProject.getProject().delete(true, true, null); - this.jpaProject = null; - super.tearDown(); - } - -// public void testPersistentTypes() throws CoreException, IOException { -// IFile persistenceXmlIFile = jpaProject.getProject().getFile(PERSISTENCE_XML_LOCATION); -// IJpaFile persistenceXmlJpaFile = jpaProject.getJpaProject().getJpaFile(persistenceXmlIFile); -// PersistenceXmlRootContentNode persistenceRoot = (PersistenceXmlRootContentNode) persistenceXmlJpaFile.getContent(); -// XmlPersistence persistence = persistenceRoot.getPersistence(); -// -// IFile ormXmlIFile = jpaProject.getProject().getFile(ORM_XML_LOCATION); -// IJpaFile ormXmlJpaFile = jpaProject.getJpaProject().getJpaFile(ormXmlIFile); -// XmlRootContentNode ormRoot = (XmlRootContentNode) ormXmlJpaFile.getContent(); -// EntityMappingsInternal entityMappings = ormRoot.getEntityMappings(); -// -// // add xml persistent type -// XmlEntityInternal xmlEntity = OrmFactory.eINSTANCE.createXmlEntityInternal(); -// xmlEntity.setSpecifiedName("XmlEntity"); -// entityMappings.getTypeMappings().add(xmlEntity); -// entityMappings.eResource().save(null); -// assertEquals(1, CollectionTools.size(jpaProject.getJpaProject().getPlatform().persistentTypes(PROJECT_NAME))); -// -// // add java persistent type -// jpaProject.createType(PACKAGE_NAME, "JavaEntity.java", -// "@Entity public class JavaEntity {}" -// ); -// XmlJavaClassRef javaClassRef = PersistenceFactory.eINSTANCE.createJavaClassRef(); -// javaClassRef.setJavaClass(PACKAGE_NAME + ".JavaEntity"); -// persistence.getPersistenceUnits().get(0).getClasses().add(javaClassRef); -// persistence.eResource().save(null); -// -// assertEquals(2, CollectionTools.size(jpaProject.getJpaProject().getPlatform().persistentTypes(PROJECT_NAME))); -// } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java deleted file mode 100644 index 417144dc7c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.platform; - -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider; -import org.eclipse.jpt.core.platform.JpaPlatformDescription; -import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatformProvider; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IActionConfigFactory; - -@SuppressWarnings("nls") -public class JpaPlatformExtensionTests extends ContextModelTestCase -{ - public static final String TEST_PLATFORM_ID = TestJpaPlatformProvider.ID; - public static final JpaPlatformDescription TEST_PLATFORM_DESC = - JptCorePlugin.getJpaPlatformManager().getJpaPlatform(TEST_PLATFORM_ID); - public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform"; - - protected TestJpaProject testProject; - - public JpaPlatformExtensionTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - verifyExtensionTestProjectExists(); - } - - @Override - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return super.buildJpaProject(PROJECT_NAME, autoBuild, this.buildConfig()); - } - - protected IDataModel buildConfig() throws Exception { - IActionConfigFactory configFactory = new JpaFacetInstallDataModelProvider(); - IDataModel config = (IDataModel) configFactory.create(); - config.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_1_0.getVersionString()); - config.setProperty(JpaFacetDataModelProperties.PLATFORM, TEST_PLATFORM_DESC); - return config; - } - - public static void verifyExtensionTestProjectExists() { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = - registry.getExtensionPoint(JptCorePlugin.PLUGIN_ID, "jpaPlatform"); - IExtension[] extensions = extensionPoint.getExtensions(); - boolean extensionFound = false; - for (IExtension extension : extensions) { - if (extension.getContributor().getName().equals(ExtensionTestPlugin.PLUGIN_ID)) { - extensionFound = true; - } - } - if (!extensionFound) { - throw new RuntimeException("Missing Extension " + TEST_PLATFORM_ID + ". The ExtensionTestProject plugin must be in your testing workspace."); - } - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testAllJpaPlatformIds() { - assertTrue(CollectionTools.size(JptCorePlugin.getJpaPlatformManager().getJpaPlatforms()) >= 2); - } - - public void testJpaPlatformLabel() { - assertEquals(TEST_PLATFORM_LABEL, JptCorePlugin.getJpaPlatformManager().getJpaPlatform(TEST_PLATFORM_ID).getLabel()); - } - - public void testJpaPlatform() { - assertNotNull(JptCorePlugin.getJpaPlatformManager().buildJpaPlatformImplementation(this.testProject.getProject())); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java deleted file mode 100644 index 865f797589..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.platform; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestAttributeMapping; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestAttributeMappingDefinition; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestTypeMapping; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestTypeMappingDefinition; -import org.eclipse.jpt.core.tests.extension.resource.TestJavaBasicMapping; -import org.eclipse.jpt.core.tests.extension.resource.TestJavaEntity; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaFactory; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatformProvider; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IActionConfigFactory; - -@SuppressWarnings("nls") -public class JpaPlatformTests - extends ContextModelTestCase -{ - protected TestJpaProject testProject; - - public static final String TEST_PLUGIN_CLASS = ExtensionTestPlugin.class.getName(); - public static final String TEST_PLUGIN_ID = "org.eclipse.jpt.core.tests.extension.resource"; - - public static final String TEST_PLATFORM_CLASS_NAME = TestJpaPlatformProvider.class.getName(); - public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform"; - public static final String TEST_JPA_FACTORY = TestJpaFactory.class.getName(); - public static final String TEST_TYPE_MAPPING_PROVIDER_CLASS = JavaTestTypeMappingDefinition.class.getName(); - public static final String TEST_ATTRIBUTE_MAPPING_PROVIDER_CLASS = JavaTestAttributeMappingDefinition.class.getName(); - - public JpaPlatformTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - JpaPlatformExtensionTests.verifyExtensionTestProjectExists(); - } - - @Override - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return super.buildJpaProject(PROJECT_NAME, autoBuild, this.buildConfig()); - } - - protected IDataModel buildConfig() throws Exception { - IActionConfigFactory configFactory = new JpaFacetInstallDataModelProvider(); - IDataModel config = (IDataModel) configFactory.create(); - config.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_1_0.getVersionString()); - config.setProperty( - JpaFacetDataModelProperties.PLATFORM, - JptCorePlugin.getJpaPlatformManager().getJpaPlatform(TestJpaPlatformProvider.ID)); - return config; - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - - protected JpaPlatform jpaPlatform() { - return this.getJpaProject().getJpaPlatform(); - } - - public void testJpaFactory() { - assertTrue(jpaPlatform().getJpaFactory().getClass().getName().equals(TEST_JPA_FACTORY)); - } - - public void testBuildJavaTypeMappingFromMappingKey() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - this.getJavaPersistentType().setMappingKey(JavaTestTypeMapping.TEST_TYPE_MAPPING_KEY); - JavaTypeMapping mapping = this.getJavaPersistentType().getMapping(); - assertTrue(mapping instanceof JavaTestTypeMapping); - - this.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - mapping = this.getJavaPersistentType().getMapping(); - assertTrue(mapping instanceof TestJavaEntity); - } - - public void testBuildJavaAttributeMappingFromMappingKey() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaPersistentAttribute javaAttribute = this.getJavaPersistentType().getAttributeNamed("name"); - javaAttribute.setMappingKey(JavaTestAttributeMapping.TEST_ATTRIBUTE_MAPPING_KEY); - JavaAttributeMapping mapping = javaAttribute.getMapping(); - assertTrue(mapping instanceof JavaTestAttributeMapping); - - javaAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - mapping = javaAttribute.getMapping(); - assertTrue(mapping instanceof TestJavaBasicMapping); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJpaProject.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJpaProject.java deleted file mode 100644 index 1c576707fe..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJpaProject.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.projects; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.utility.Command; -import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackSynchronousSynchronizer; -import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer; -import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer; -import org.eclipse.jpt.common.utility.synchronizers.Synchronizer; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * This builds and holds a "JPA" project. - * Support for adding packages and types. - * - * The JPA project's settings (platform, database connection, etc.) can be - * controlled by building a data model and passing it into the constructor. - */ -@SuppressWarnings("nls") -public class TestJpaProject extends TestJavaProject { - final JpaProject jpaProject; - - public static final String JPA_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.jpa.jar"; - public static final String ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.eclipselink.jar"; - - - // ********** builders ********** - - public static TestJpaProject buildJpaProject(String baseProjectName, boolean autoBuild, IDataModel jpaConfig) - throws CoreException { - return new TestJpaProject(baseProjectName, autoBuild, jpaConfig); - } - - public static TestJpaProject buildJpaProject(String baseProjectName, boolean autoBuild) - throws CoreException { - return buildJpaProject(baseProjectName, autoBuild, null); - } - - // ********** constructors/initialization ********** - - public TestJpaProject(String projectName) throws CoreException { - this(projectName, false); - } - - public TestJpaProject(String projectName, boolean autoBuild) throws CoreException { - this(projectName, autoBuild, null); - } - - public TestJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) throws CoreException { - super(projectName, autoBuild); - String jpaFacetVersion = JpaFacet.VERSION_1_0.getVersionString(); - if (jpaConfig != null) { - jpaFacetVersion = jpaConfig.getStringProperty(IFacetDataModelProperties.FACET_VERSION_STR); - } - this.installFacet("jst.utility", "1.0"); - this.installFacet(JpaFacet.ID, jpaFacetVersion, jpaConfig); - this.addJar(jpaJarName()); - if (eclipseLinkJarName() != null) { - this.addJar(eclipseLinkJarName()); - } - this.jpaProject = JptCorePlugin.getJpaProject(this.getProject()); - this.jpaProject.setDiscoversAnnotatedClasses(true); - this.jpaProject.setContextModelSynchronizer(this.buildSynchronousContextModelSynchronizer()); - this.jpaProject.setUpdateSynchronizer(this.buildSynchronousUpdateSynchronizer()); - } - - protected Synchronizer buildSynchronousContextModelSynchronizer() { - return new SynchronousSynchronizer(this.buildSynchronousContextModelSynchronizerCommand()); - } - - protected Command buildSynchronousContextModelSynchronizerCommand() { - return new SynchronousContextModelSynchronizerCommand(); - } - - protected class SynchronousContextModelSynchronizerCommand implements Command { - public void execute() { - TestJpaProject.this.jpaProject.synchronizeContextModel(new NullProgressMonitor()); - } - } - - protected CallbackSynchronizer buildSynchronousUpdateSynchronizer() { - return new CallbackSynchronousSynchronizer(this.buildSynchronousUpdateSynchronizerCommand()); - } - - protected Command buildSynchronousUpdateSynchronizerCommand() { - return new SynchronousUpdateSynchronizerCommand(); - } - - protected class SynchronousUpdateSynchronizerCommand implements Command { - public void execute() { - TestJpaProject.this.jpaProject.update(new NullProgressMonitor()); - } - } - - public static String jpaJarName() { - return getSystemProperty(JPA_JAR_NAME_SYSTEM_PROPERTY); - } - - public static String eclipseLinkJarName() { - return getSystemProperty(ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY); - } - - private static String getSystemProperty(String propertyName) { - return System.getProperty(propertyName); - } - - - // ********** public methods ********** - - public JpaProject getJpaProject() { - return this.jpaProject; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/JptCoreResourceModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/JptCoreResourceModelTests.java deleted file mode 100644 index 3bafb54b69..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/JptCoreResourceModelTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.JptCoreTests; -import org.eclipse.jpt.core.tests.internal.jpa2.resource.java.JavaResource2_0Tests; -import org.eclipse.jpt.core.tests.internal.resource.java.JptJavaResourceTests; - -/** - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar= - */ -public class JptCoreResourceModelTests - extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreResourceModelTests.class.getPackage().getName()); - - if (JptCoreTests.requiredJarsExists()) { - suite.addTest(JptJavaResourceTests.suite()); - suite.addTest(JavaResource2_0Tests.suite()); - } else { - suite.addTest(TestSuite.warning(JptCoreTests.buildMissingJarErrorMessage())); - } - return suite; - } - - private JptCoreResourceModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverrideTests.java deleted file mode 100644 index b5dbd6262e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverrideTests.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; - -@SuppressWarnings("nls") -public class AssociationOverrideTests extends JpaJavaResourceModelTestCase { - - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE"; - - public AssociationOverrideTests(String name) { - super(name); - } - - private ICompilationUnit createTestAssociationOverrideOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName("Foo"); - assertEquals("Foo", associationOverride.getName()); - assertSourceContains("@AssociationOverride(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName(null); - assertNull(associationOverride.getName()); - - assertSourceDoesNotContain("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AssociationOverride", cu); - } - - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(0, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - associationOverride.addJoinColumn(0); - associationOverride.addJoinColumn(1); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverride.addJoinColumn(0).setName("FOO"); - associationOverride.addJoinColumn(1); - associationOverride.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertNull(associationOverride.joinColumnAt(2).getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - associationOverride.addJoinColumn(0).setName("FOO"); - - Iterator joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\"), @JoinColumn})", cu); - - associationOverride.removeJoinColumn(1); - joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - - associationOverride.removeJoinColumn(0); - joinColumns = associationOverride.joinColumns(); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = @JoinColumn)", cu); - - - associationOverride.setName(null); - associationOverride.removeJoinColumn(0); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - associationOverride.moveJoinColumn(2, 0); - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertNull(associationOverride.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")})", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - associationOverride.moveJoinColumn(0, 2); - assertNull(associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertEquals("BAR", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")})", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(2, associationOverride.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn})", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverridesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverridesTests.java deleted file mode 100644 index 201a3e5864..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverridesTests.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -@SuppressWarnings("nls") -public class AssociationOverridesTests extends JpaJavaResourceModelTestCase { - - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE"; - - public AssociationOverridesTests(String name) { - super(name); - } - - private ICompilationUnit createTestAssociationOverrideOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn}))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\"))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.getNestedAnnotations().iterator().next(); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.getNestedAnnotations().iterator().next(); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName("Foo"); - assertEquals("Foo", associationOverride.getName()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.getNestedAnnotations().iterator().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName(null); - assertNull(associationOverride.getName()); - - assertSourceDoesNotContain("@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AssociationOverride", cu); - assertSourceContains("@AssociationOverrides", cu); - } - - public void testAddAssociationOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES))); - } - - public void testAddAssociationOverrideToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name = \"BAR\")})", cu); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"BAZ\"),@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")), @AssociationOverride(name = \"BAR\")})", cu); - - Iterator associationOverrides = typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - assertEquals("BAZ", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("FOO", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("BAR", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES))); - } - - public void testRemoveAssociationOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name = \"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - assertSourceContains("@AssociationOverride(name = \"FOO\", joinColumns = @JoinColumn(name = \"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\"))", cu); - } - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(0, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - associationOverride.addJoinColumn(0); - associationOverride.addJoinColumn(1); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - associationOverride.addJoinColumn(0).setName("FOO"); - associationOverride.addJoinColumn(1); - associationOverride.addJoinColumn(0).setName("BAR"); - - - Iterator joinColumns = associationOverride.joinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - associationOverride.addJoinColumn(0).setName("FOO"); - - Iterator joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\"), @JoinColumn}))", cu); - - associationOverride.removeJoinColumn(1); - joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn}))", cu); - - associationOverride.removeJoinColumn(0); - joinColumns = associationOverride.joinColumns(); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = @JoinColumn))", cu); - - - associationOverride.setName(null); - associationOverride.removeJoinColumn(0); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - - associationOverride.moveJoinColumn(2, 0); - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertNull(associationOverride.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")}))", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - associationOverride.moveJoinColumn(0, 2); - assertNull(associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertEquals("BAR", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")}))", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(2, associationOverride.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn}))", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverrideTests.java deleted file mode 100644 index e1d9cb56ca..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverrideTests.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class AttributeOverrideTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE"; - - public AttributeOverrideTests(String name) { - super(name); - } - - private ICompilationUnit createTestAttributeOverrideOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestAttributeOverrideWithColumnOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name = \"" + COLUMN_NAME + "\"))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - } - - public void testGetNullColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNotNull(attributeOverride); - assertNull(column); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName("Foo"); - assertEquals("Foo", attributeOverride.getName()); - assertSourceContains("@AttributeOverride(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName(null); - assertNull(attributeOverride.getName()); - - assertSourceDoesNotContain("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AttributeOverride", cu); - } - - public void testColumnGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testColumnSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertEquals(COLUMN_NAME, column.getName()); - - column.setName("Foo"); - - assertSourceContains("@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name = \"Foo\"))", cu); - - column.setName(null); - assertNull(attributeOverride.getColumn().getName()); - attributeOverride.removeColumn(); - assertNull(attributeOverride.getColumn()); - assertSourceContains("@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - } - - public void testAddColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNull(column); - - attributeOverride.addColumn(); - column = attributeOverride.getColumn(); - assertNotNull(column); - assertSourceContains("@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column)", cu); - } - - public void testRemoveColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNull(column); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverridesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverridesTests.java deleted file mode 100644 index aced583600..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverridesTests.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -@SuppressWarnings("nls") -public class AttributeOverridesTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE"; - - public AttributeOverridesTests(String name) { - super(name); - } - - private ICompilationUnit createTestAttributeOverrideOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverrides(@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAttributeOverrideWithColumnOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverrides(@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name = \"" + COLUMN_NAME + "\")))"); - } - }); - } - - private ICompilationUnit createTestAttributeOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@AttributeOverride(name = \"FOO\", column = @Column(name = \"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.getNestedAnnotations().iterator().next(); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - } - - public void testGetNullColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.getNestedAnnotations().iterator().next(); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNotNull(attributeOverride); - assertNull(column); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.getNestedAnnotations().iterator().next(); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName("Foo"); - assertEquals("Foo", attributeOverride.getName()); - assertSourceContains("@AttributeOverrides(@AttributeOverride(name = \"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.getNestedAnnotations().iterator().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName(null); - assertNull(attributeOverride.getName()); - - assertSourceDoesNotContain("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AttributeOverride", cu); - assertSourceContains("@AttributeOverrides", cu); - } - - public void testColumnGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.getNestedAnnotations().iterator().next(); - - ColumnAnnotation column = attributeOverride.getColumn(); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testColumnSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES).next(); - - ColumnAnnotation column = attributeOverride.getColumn(); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName("Foo"); - - assertSourceContains("@AttributeOverrides(@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name = \"Foo\")))", cu); - - column.setName(null); - assertNull(attributeOverride.getColumn().getName()); - attributeOverride.removeColumn(); - assertNull(attributeOverride.getColumn()); - assertSourceContains("@AttributeOverride(name = \"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - } - - public void testAddAttributeOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\", column = @Column(name = \"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)),@AttributeOverride(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testAddAttributeOverrideToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\", column = @Column(name = \"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)),@AttributeOverride(name = \"BAR\")})", cu); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"BAZ\"),@AttributeOverride(name = \"FOO\", column = @Column(name = \"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)), @AttributeOverride(name = \"BAR\")})", cu); - - Iterator attributeOverrides = typeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertEquals("BAZ", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("FOO", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("BAR", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testRemoveAttributeOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\", column = @Column(name = \"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)),@AttributeOverride(name = \"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverride(name = \"FOO\", column = @Column(name = \"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1))", cu); - } - //not sure i want to test this api, how can we keep ContainerAnnotation.add, move, remove from being public? - //users should go throught AbstractJavapersistenceResource. this gets confusing because you would handle it differently - //for non top-level annotations -// public void testAdd() throws Exception { -// ICompilationUnit cu = this.createTestType(); -// JavaPersistentTypeResource typeResource = buildJavaTypeResource(cu); -// JavaPersistentAttributeResource attributeResource = typeResource.fields().next(); -// AttributeOverrides attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// assertNull(attributeOverrides); -// -// attributeResource.addAnnotation(JPA.ATTRIBUTE_OVERRIDES); -// attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// assertNotNull(attributeOverrides); -// -// assertSourceContains("@AttributeOverrides"); -// -// AttributeOverride fooAttributeOverride = attributeOverrides.add(0); -// fooAttributeOverride.setName("Foo"); -// -// assertSourceContains("@AttributeOverrides(@AttributeOverride(name=\"Foo\"))"); -// -// AttributeOverride barAttributeOverride = attributeOverrides.add(0); -// barAttributeOverride.setName("Bar"); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"Bar\"), @AttributeOverride(name=\"Foo\")})"); -// -// } -// -// public void testMove() throws Exception { -// ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); -// JavaPersistentTypeResource typeResource = buildJavaTypeResource(cu); -// JavaPersistentAttributeResource attributeResource = typeResource.fields().next(); -// AttributeOverrides attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// -// AttributeOverride fooAttributeOverride = attributeOverrides.add(1); -// fooAttributeOverride.setName("Foo"); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\"), @AttributeOverride(name=\"Foo\")})"); -// -// attributeOverrides.move(0, 1); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"Foo\"), @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")})"); -// } -// -// public void testRemove() throws Exception { -// ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); -// JavaPersistentTypeResource typeResource = buildJavaTypeResource(cu); -// JavaPersistentAttributeResource attributeResource = typeResource.fields().next(); -// AttributeOverrides attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// -// AttributeOverride fooAttributeOverride = attributeOverrides.add(1); -// fooAttributeOverride.setName("Foo"); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\"), @AttributeOverride(name=\"Foo\")})"); -// -// attributeOverrides.remove(0); -// -// assertSourceContains("@AttributeOverrides(@AttributeOverride(name=\"Foo\"))"); -// -// attributeOverrides.remove(0); -// -// assertSourceContains("@AttributeOverrides()"); -// -// } - - - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/BasicTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/BasicTests.java deleted file mode 100644 index 216f74a8ea..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/BasicTests.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class BasicTests extends JpaJavaResourceModelTestCase { - - public BasicTests(String name) { - super(name); - } - - private ICompilationUnit createTestBasic() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.BASIC); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - } - }); - } - - private ICompilationUnit createTestBasicWithOptional() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.BASIC); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(optional = true)"); - } - }); - } - - private ICompilationUnit createTestBasicWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.BASIC, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch = FetchType.EAGER)"); - } - }); - } - - public void testBasic() throws Exception { - ICompilationUnit cu = this.createTestBasic(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - assertNotNull(basic); - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestBasicWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - assertEquals(Boolean.TRUE, basic.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestBasicWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - assertEquals(Boolean.TRUE, basic.getOptional()); - - basic.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, basic.getOptional()); - - assertSourceContains("@Basic(optional = false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestBasicWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - assertEquals(Boolean.TRUE, basic.getOptional()); - - basic.setOptional(null); - assertNull(basic.getOptional()); - - assertSourceContains("@Basic", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestBasicWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - assertEquals(FetchType.EAGER, basic.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestBasicWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - assertEquals(FetchType.EAGER, basic.getFetch()); - - basic.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, basic.getFetch()); - - assertSourceContains("@Basic(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestBasicWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - assertEquals(FetchType.EAGER, basic.getFetch()); - - basic.setFetch(null); - assertNull(basic.getFetch()); - - assertSourceContains("@Basic", cu); - assertSourceDoesNotContain("fetch", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ColumnTests.java deleted file mode 100644 index a50151e3c8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ColumnTests.java +++ /dev/null @@ -1,404 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class ColumnTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - - public ColumnTests(String name) { - super(name); - } - - private ICompilationUnit createTestColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column"); - } - }); - } - - private ICompilationUnit createTestColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name = \"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(table = \"" + COLUMN_TABLE + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(" + booleanElement + " = true)"); - } - }); - } - - private ICompilationUnit createTestColumnWithIntElement(final String intElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(" + intElement + " = 5)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@Column(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("(name", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@Column(table = \"Foo\")", cu); - - - column.setTable(null); - assertSourceDoesNotContain("table", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@Column(columnDefinition = \"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("columnDefinition", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getUnique()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUnique()); - - assertSourceContains("@Column(unique = false)", cu); - - column.setUnique(null); - assertSourceDoesNotContain("unique", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getNullable()); - - assertSourceContains("@Column(nullable = false)", cu); - - column.setNullable(null); - assertSourceDoesNotContain("nullable", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getInsertable()); - - assertSourceContains("@Column(insertable = false)", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("insertable", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUpdatable()); - - assertSourceContains("@Column(updatable = false)", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("updatable", cu); - } - - public void testGetLength() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("length"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(5), column.getLength()); - } - - public void testSetLength() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getLength()); - - column.setLength(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getLength()); - - assertSourceContains("@Column(length = 5)", cu); - - column.setLength(null); - assertSourceDoesNotContain("length", cu); - } - - public void testGetPrecision() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("precision"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(5), column.getPrecision()); - } - - public void testSetPrecision() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertEquals(null, column.getPrecision()); - - column.setPrecision(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getPrecision()); - - assertSourceContains("@Column(precision = 5)", cu); - - column.setPrecision(null); - assertSourceDoesNotContain("precision", cu); - } - - public void testGetScale() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("scale"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(5), column.getScale()); - } - - public void testSetScale() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getScale()); - - column.setScale(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getScale()); - - assertSourceContains("@Column(scale = 5)", cu); - - column.setScale(null); - assertSourceDoesNotContain("scale", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorColumnTests.java deleted file mode 100644 index a259303838..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorColumnTests.java +++ /dev/null @@ -1,212 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class DiscriminatorColumnTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - - public DiscriminatorColumnTests(String name) { - super(name); - } - - private ICompilationUnit createTestDiscriminatorColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(name = \"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorColumnWithDiscriminatorType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.DISCRIMINATOR_COLUMN, JPA.DISCRIMINATOR_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(discriminatorType = DiscriminatorType.CHAR)"); - } - }); - } - - private ICompilationUnit createTestColumnWithIntElement(final String intElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(" + intElement + " = 5)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getDiscriminatorType()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@DiscriminatorColumn(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("(name", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@DiscriminatorColumn(columnDefinition = \"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("(columnDefinition", cu); - } - - public void testGetLength() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("length"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(Integer.valueOf(5), column.getLength()); - } - - public void testSetLength() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNotNull(column); - assertNull(column.getLength()); - - column.setLength(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getLength()); - - assertSourceContains("@DiscriminatorColumn(length = 5)", cu); - - column.setLength(null); - assertSourceDoesNotContain("(length", cu); - } - - public void testGetDiscriminatorType() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithDiscriminatorType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertEquals(DiscriminatorType.CHAR, column.getDiscriminatorType()); - } - - public void testSetDiscriminatorType() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNull(column.getDiscriminatorType()); - - column.setDiscriminatorType(DiscriminatorType.INTEGER); - assertEquals(DiscriminatorType.INTEGER, column.getDiscriminatorType()); - - assertSourceContains("@DiscriminatorColumn(discriminatorType = INTEGER)", cu); - - column.setDiscriminatorType(null); - assertSourceDoesNotContain("(discriminatorType", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorValueTests.java deleted file mode 100644 index f233bacf51..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorValueTests.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class DiscriminatorValueTests extends JpaJavaResourceModelTestCase { - - public DiscriminatorValueTests(String name) { - super(name); - } - - private ICompilationUnit createTestDiscriminatorValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.DISCRIMINATOR_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorValue"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorValueWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.DISCRIMINATOR_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorValue(value = \"discriminator\")"); - } - }); - } - - public void testDiscriminatorValue() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_VALUE); - assertNotNull(discriminatorValue); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorValueWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_VALUE); - assertEquals("discriminator", discriminatorValue.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_VALUE); - - discriminatorValue.setValue("foo"); - - assertSourceContains("@DiscriminatorValue(\"foo\")", cu); - - discriminatorValue.setValue(null); - - assertSourceDoesNotContain("@DiscriminatorValue(", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddableTests.java deleted file mode 100644 index 3c23c8c321..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddableTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class EmbeddableTests extends JpaJavaResourceModelTestCase { - - public EmbeddableTests(String name) { - super(name); - } - - private ICompilationUnit createTestEmbeddable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable"); - } - }); - } - - private ICompilationUnit createTestEmbeddableAndEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE, JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Embeddable"); - } - }); - } - - public void testEmbeddable() throws Exception { - ICompilationUnit cu = this.createTestEmbeddable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof EmbeddableAnnotation); - } - - public void testEmbeddableAndEntity() throws Exception { - ICompilationUnit cu = this.createTestEmbeddableAndEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof EmbeddableAnnotation); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(JPA.ENTITY); - assertNotNull(entity); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedIdTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedIdTests.java deleted file mode 100644 index 8cb83ecd5c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedIdTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class EmbeddedIdTests extends JpaJavaResourceModelTestCase { - - public EmbeddedIdTests(String name) { - super(name); - } - - private ICompilationUnit createTestEmbeddedId() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDED_ID); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@EmbeddedId"); - } - }); - } - - public void testEmbeddedId() throws Exception { - ICompilationUnit cu = this.createTestEmbeddedId(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof EmbeddedIdAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedTests.java deleted file mode 100644 index b7ba529b43..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class EmbeddedTests extends JpaJavaResourceModelTestCase { - - public EmbeddedTests(String name) { - super(name); - } - - private ICompilationUnit createTestEmbedded() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDED); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - } - }); - } - - public void testEmbedded() throws Exception { - ICompilationUnit cu = this.createTestEmbedded(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof EmbeddedAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EntityTests.java deleted file mode 100644 index 557ac42096..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EntityTests.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; - -@SuppressWarnings("nls") -public class EntityTests extends JpaJavaResourceModelTestCase { - - private static final String ENTITY_NAME = "Foo"; - - public EntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity(name = \"" + ENTITY_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassAndEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - sb.append("@Entity"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestEntityWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(JPA.ENTITY); - assertTrue(entity != null); - assertEquals(ENTITY_NAME, entity.getName()); - } - - public void testGetNameNull() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(JPA.ENTITY); - assertTrue(entity != null); - assertNull(entity.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(JPA.ENTITY); - assertNull(entity.getName()); - entity.setName("Foo"); - assertEquals("Foo", entity.getName()); - - assertSourceContains("@Entity(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestEntityWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(JPA.ENTITY); - assertEquals(ENTITY_NAME, entity.getName()); - - entity.setName(null); - assertNull(entity.getName()); - - assertSourceContains("@Entity", cu); - assertSourceDoesNotContain("@Entity(name = \"Foo\")", cu); - } - - public void testMappedSuperclassAndEntity() throws Exception { - ICompilationUnit cu = this.createTestMappedSuperclassAndEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof EntityAnnotation); - - MappedSuperclassAnnotation mappedSuperclass = (MappedSuperclassAnnotation) typeResource.getAnnotation(JPA.MAPPED_SUPERCLASS); - assertNotNull(mappedSuperclass); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EnumeratedTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EnumeratedTests.java deleted file mode 100644 index 4045aea574..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EnumeratedTests.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.EnumType; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class EnumeratedTests extends JpaJavaResourceModelTestCase { - - public EnumeratedTests(String name) { - super(name); - } - - private ICompilationUnit createTestEnumerated() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENUMERATED); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Enumerated"); - } - }); - } - - private ICompilationUnit createTestEnumeratedWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Enumerated(EnumType.ORDINAL)"); - } - }); - } - - public void testEnumerated() throws Exception { - ICompilationUnit cu = this.createTestEnumerated(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(JPA.ENUMERATED); - assertNotNull(enumerated); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestEnumeratedWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(JPA.ENUMERATED); - assertEquals(EnumType.ORDINAL, enumerated.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestEnumerated(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(JPA.ENUMERATED); - - enumerated.setValue(EnumType.STRING); - - assertSourceContains("@Enumerated(STRING)", cu); - - enumerated.setValue(null); - - assertSourceDoesNotContain("@Enumerated(", cu); - assertSourceContains("@Enumerated", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/GeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/GeneratedValueTests.java deleted file mode 100644 index cece13c89c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/GeneratedValueTests.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.GenerationType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class GeneratedValueTests extends JpaJavaResourceModelTestCase { - - private static final String GENERATOR = "MY_GENERATOR"; - public GeneratedValueTests(String name) { - super(name); - } - - private ICompilationUnit createTestGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.GENERATED_VALUE, JPA.GENERATION_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@GeneratedValue"); - } - }); - } - - private ICompilationUnit createTestGeneratedValueWithGenerator() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.GENERATED_VALUE, JPA.GENERATION_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@GeneratedValue(generator = \"" + GENERATOR + "\")"); - } - }); - } - - private ICompilationUnit createTestGeneratedValueWithStrategy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.GENERATED_VALUE, JPA.GENERATION_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@GeneratedValue(strategy = GenerationType.SEQUENCE)"); - } - }); - } - - public void testGeneratedValue() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertNotNull(generatedValue); - } - - public void testGetGenerator() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithGenerator(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GENERATOR, generatedValue.getGenerator()); - } - - public void testSetGenerator() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithGenerator(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GENERATOR, generatedValue.getGenerator()); - - generatedValue.setGenerator("foo"); - assertEquals("foo", generatedValue.getGenerator()); - - assertSourceContains("@GeneratedValue(generator = \"foo\")", cu); - - generatedValue.setGenerator(null); - assertNull(generatedValue.getGenerator()); - - assertSourceDoesNotContain("generator", cu); - assertSourceContains("@GeneratedValue", cu); - } - - public void testGetStrategy() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithStrategy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GenerationType.SEQUENCE, generatedValue.getStrategy()); - } - - public void testSetStrategy() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithStrategy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GenerationType.SEQUENCE, generatedValue.getStrategy()); - - generatedValue.setStrategy(GenerationType.TABLE); - assertEquals(GenerationType.TABLE, generatedValue.getStrategy()); - - assertSourceContains("@GeneratedValue(strategy = TABLE)", cu); - - generatedValue.setStrategy(null); - assertNull(generatedValue.getStrategy()); - assertSourceDoesNotContain("strategy", cu); - assertSourceContains("@GeneratedValue", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdClassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdClassTests.java deleted file mode 100644 index 9849054abf..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdClassTests.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class IdClassTests extends JpaJavaResourceModelTestCase { - - private static final String ID_CLASS_VALUE = "MyClass"; - - public IdClassTests(String name) { - super(name); - } - - private ICompilationUnit createTestIdClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ID_CLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@IdClass"); - } - }); - } - - private ICompilationUnit createTestIdClassWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ID_CLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@IdClass(" + ID_CLASS_VALUE + ".class)"); - } - }); - } - - public void testIdClass() throws Exception { - ICompilationUnit cu = this.createTestIdClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertNotNull(idClass); - assertNull(idClass.getValue()); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestIdClassWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertEquals(ID_CLASS_VALUE, idClass.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestIdClassWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertEquals(ID_CLASS_VALUE, idClass.getValue()); - - idClass.setValue("foo"); - assertEquals("foo", idClass.getValue()); - - assertSourceContains("@IdClass(foo.class)", cu); - - idClass.setValue(null); - - assertSourceDoesNotContain("@IdClass(", cu); - } - - public void testGetFullyQualifiedClass() throws Exception { - ICompilationUnit cu = this.createTestIdClassWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertNotNull(idClass.getValue()); - assertEquals("MyClass", idClass.getFullyQualifiedClassName()); //bug 196200 changed this - - - idClass.setValue(TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, idClass.getFullyQualifiedClassName()); - assertSourceContains("@IdClass(" + TYPE_NAME + ".class)", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdTests.java deleted file mode 100644 index 86f250eeba..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class IdTests extends JpaJavaResourceModelTestCase { - - public IdTests(String name) { - super(name); - } - - private ICompilationUnit createTestId() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ID); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public void testId() throws Exception { - ICompilationUnit cu = this.createTestId(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof IdAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/InheritanceTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/InheritanceTests.java deleted file mode 100644 index 7f55f29769..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/InheritanceTests.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - -@SuppressWarnings("nls") -public class InheritanceTests extends JpaJavaResourceModelTestCase { - - public InheritanceTests(String name) { - super(name); - } - - private ICompilationUnit createTestInheritance() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.INHERITANCE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Inheritance"); - } - }); - } - - private ICompilationUnit createTestInheritanceWithStrategy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Inheritance(strategy = InheritanceType.JOINED)"); - } - }); - } - - public void testInheritance() throws Exception { - ICompilationUnit cu = this.createTestInheritance(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(JPA.INHERITANCE); - assertNotNull(inheritance); - } - - public void testGetStrategy() throws Exception { - ICompilationUnit cu = this.createTestInheritanceWithStrategy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(JPA.INHERITANCE); - assertEquals(InheritanceType.JOINED, inheritance.getStrategy()); - } - - public void testSetStrategy() throws Exception { - ICompilationUnit cu = this.createTestInheritance(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(JPA.INHERITANCE); - inheritance.setStrategy(InheritanceType.TABLE_PER_CLASS); - - assertSourceContains("@Inheritance(strategy = TABLE_PER_CLASS)", cu); - - inheritance.setStrategy(null); - - assertSourceDoesNotContain("strategy", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java deleted file mode 100644 index e444960d88..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java +++ /dev/null @@ -1,479 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.utility.jdt.FieldAttribute; -import org.eclipse.jpt.common.core.utility.jdt.MethodAttribute; -import org.eclipse.jpt.common.core.utility.jdt.Type; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JPTToolsTests extends JpaJavaResourceModelTestCase { - - public JPTToolsTests(String name) { - super(name); - } - - private ICompilationUnit createTestTypeFieldWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" " + modifier + " String foo;").append(CR); - sb.append(CR); - } - }); - } - - protected FieldAttribute fooField(ICompilationUnit cu) { - return this.buildField("foo", cu); - } - - - private ICompilationUnit createTestTypeGetMethodWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" " + modifier + " int getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeInvalidMethodName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public int foo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeConstructor() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public " + TYPE_NAME + "() {").append(CR); - sb.append(" super();").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeVoidMethodReturnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public void getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeInvalidMethodReturnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public Iterator imports() { - return new ArrayIterator("com.foo.Foo"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public Foo getFoo() {").append(CR); - sb.append(" return null;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(Foo id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeIsMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public boolean isFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(boolean id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeIsMethodReturnInt() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public int isFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeIsAndGetMethodWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" " + modifier + " boolean isFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" " + modifier + " boolean getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(boolean id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeSetMethodWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public int getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" " + modifier + " void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeWithMemberTypes() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append(" public static class FooStatic {}").append(CR); - sb.append(CR); - sb.append(" public class FooNotStatic {}").append(CR); - sb.append(CR); - sb.append(" public @interface MyAnnotation {}").append(CR); - sb.append(CR); - sb.append(" public enum MyEnum {}").append(CR); - } - }); - } - - protected MethodAttribute fooMethod(ICompilationUnit cu) { - return this.buildMethod("getFoo", cu); - } - - //private String foo; - persistable - public void testFieldIsPersistable1() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private"); - FieldAttribute fieldAttribute = fooField(cu); - assertTrue(fieldAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //private static String foo; - not persistable - public void testFieldIsPersistable2() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private static"); - FieldAttribute fieldAttribute = fooField(cu); - assertFalse(fieldAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //private transient String foo; - not persistable - public void testFieldIsPersistable3() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private transient"); - FieldAttribute fieldAttribute = fooField(cu); - assertFalse(fieldAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //private final String foo; - persistable - public void testFieldIsPersistable4() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private final"); - FieldAttribute fieldAttribute = fooField(cu); - assertTrue(fieldAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public String foo; - persistable - public void testFieldIsPersistable5() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("public"); - FieldAttribute fieldAttribute = fooField(cu); - assertTrue(fieldAttribute.isPersistable(this.buildASTRoot(cu))); - } - - - //public int getFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter01() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("public"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //protected int getFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter02() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("protected"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //int getFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter03() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier(""); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //private int getFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter04() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("private"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public static int getFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter05() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("public static"); - MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public final int getFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter06() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("public final"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public void setFoo(int foo) {} - persistable - public void testMethodIsPersistablePropertyGetter07() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("public"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //protected void setFoo(int foo) {} - persistable - public void testMethodIsPersistablePropertyGetter08() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("protected"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //void setFoo(int foo) {} - persistable - public void testMethodIsPersistablePropertyGetter09() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier(""); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //private void setFoo(int foo) {} - persistable - public void testMethodIsPersistablePropertyGetter10() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("private"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public static void setFoo(int foo) {} - not persistable - public void testMethodIsPersistablePropertyGetter11() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("public static"); - MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public final void setFoo(int foo) {} - persistable - public void testMethodIsPersistablePropertyGetter12() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("public final"); - MethodAttribute methodAttribute = fooMethod(cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public boolean isFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter13() throws Exception { - ICompilationUnit cu = createTestTypeIsMethod(); - MethodAttribute methodAttribute = this.buildMethod("isFoo", cu); - assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public int isFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter14() throws Exception { - ICompilationUnit cu = createTestTypeIsMethodReturnInt(); - MethodAttribute methodAttribute = this.buildMethod("isFoo", cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); - } - - //public int isFoo() {} - persistable - //public int getFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter15() throws Exception { - ICompilationUnit cu = createTestTypeIsAndGetMethodWithModifier("public"); - MethodAttribute isFooMethod = this.buildMethod("isFoo", cu); - MethodAttribute getFooMethod = this.buildMethod("getFoo", cu); - - CompilationUnit astRoot = this.buildASTRoot(cu); - assertTrue(isFooMethod.isPersistable(astRoot)); - assertFalse(getFooMethod.isPersistable(astRoot)); - } - - //public int foo() {} - not persistable - public void testMethodIsPersistablePropertyGetter16() throws Exception { - ICompilationUnit cu = createTestTypeInvalidMethodName(); - MethodAttribute fooMethod = this.buildMethod("foo", cu); - assertFalse(fooMethod.isPersistable(this.buildASTRoot(cu))); - } - - //public void getFoo() {} - not persistable - void return type - public void testMethodIsPersistablePropertyGetter17() throws Exception { - ICompilationUnit cu = createTestTypeVoidMethodReturnType(); - MethodAttribute fooMethod = this.buildMethod("getFoo", cu); - assertFalse(fooMethod.isPersistable(this.buildASTRoot(cu))); - } - - //public Foo getFoo() {} - persistable??? - Foo does not resolve - public void testMethodIsPersistablePropertyGetter18() throws Exception { - ICompilationUnit cu = createTestTypeInvalidMethodReturnType(); - MethodAttribute getFooMethod = this.buildMethod("getFoo", cu); - assertTrue(getFooMethod.isPersistable(this.buildASTRoot(cu))); - } - - //method with parameters - not persistable - public void testMethodIsPersistablePropertyGetter19() throws Exception { - ICompilationUnit cu = createTestType(); - MethodAttribute setIdMethod = idSetMethod(cu); - assertFalse(setIdMethod.isPersistable(this.buildASTRoot(cu))); - } - - //constructor - not persistable - public void testMethodIsPersistablePropertyGetter20() throws Exception { - ICompilationUnit cu = createTestTypeConstructor(); - MethodAttribute constructor = buildMethod(TYPE_NAME, cu); - assertFalse(constructor.isPersistable(this.buildASTRoot(cu))); - } - - //no corresponding set method - not persistable - public void testMethodIsPersistablePropertyGetter21() throws Exception { - ICompilationUnit cu = createTestType(); - MethodAttribute getNameMethod = nameGetMethod(cu); - assertFalse(getNameMethod.isPersistable(this.buildASTRoot(cu))); - } - - //public class AnnotationTestType - public void testTypeIsPersistable1() throws Exception { - ICompilationUnit cu = createTestType(); - Type type = testType(cu); - CompilationUnit astRoot = this.buildASTRoot(cu); - assertTrue(type.isPersistable(astRoot)); - } - - //public final class MyFinal - public void testTypeIsPersistable2() throws Exception { - ICompilationUnit cu = this.javaProject.createCompilationUnit("finals", "MyFinal.java", "public final class MyFinal { }"); - Type type = buildType("MyFinal", cu); - CompilationUnit astRoot = this.buildASTRoot(cu); - assertTrue(type.isPersistable(astRoot)); - } - - //public interface MyInterface - public void testTypeIsPersistable3() throws Exception { - ICompilationUnit cu = this.javaProject.createCompilationUnit("interfaces", "MyInterface.java", "public interface MyInterface { }"); - Type type = buildType("MyInterface", cu); - CompilationUnit astRoot = this.buildASTRoot(cu); - assertFalse(type.isPersistable(astRoot)); - } - - //enum not persistable - public void testTypeIsPersistable4() throws Exception { - ICompilationUnit cu = this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ"); - Type type = buildType("TestEnum", cu); - CompilationUnit astRoot = this.buildASTRoot(cu); - assertFalse(type.isPersistable(astRoot)); - } - - //annotation not persistable - public void testTypeIsPersistable5() throws Exception { - ICompilationUnit cu = this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();"); - Type type = buildType("TestAnnotation", cu); - CompilationUnit astRoot = this.buildASTRoot(cu); - assertFalse(type.isPersistable(astRoot)); - } - - //public static member type is persistable - public void testTypeIsPersistable6() throws Exception { - ICompilationUnit cu = this.createTestTypeWithMemberTypes(); - Type testType = this.testType(cu); - Type memberType = this.buildType(testType, "FooStatic", 1, cu); - CompilationUnit astRoot = this.buildASTRoot(cu); - assertTrue(memberType.isPersistable(astRoot)); - } - - //non-static member type is persistable, handled with validation - public void testTypeIsPersistable7() throws Exception { - ICompilationUnit cu = this.createTestTypeWithMemberTypes(); - Type testType = this.testType(cu); - Type memberType = this.buildType(testType, "FooNotStatic", 1, cu); - CompilationUnit astRoot = this.buildASTRoot(cu); - assertTrue(memberType.isPersistable(astRoot)); - } - //TODO still need to test typeIsPersistable() returns false for local and anonymous classes - - -} - diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java deleted file mode 100644 index fca98a723d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.common.core.internal.utility.jdt.NullAnnotationEditFormatter; -import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase; -import org.eclipse.jpt.common.utility.CommandExecutor; -import org.eclipse.jpt.common.utility.internal.BitTools; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider; -import org.eclipse.jpt.core.internal.resource.java.source.SourcePackageInfoCompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.source.SourceTypeCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageInfoCompilationUnit; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; - - -@SuppressWarnings("nls") -public class JavaResourceModelTestCase - extends AnnotationTestCase { - - private JavaElementChangeListener javaElementChangeListener; - protected JavaResourceCompilationUnit javaResourceCompilationUnit; - - - public JavaResourceModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.javaElementChangeListener = new JavaElementChangeListener(); - JavaCore.addElementChangedListener(this.javaElementChangeListener); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - JavaCore.removeElementChangedListener(this.javaElementChangeListener); - this.javaElementChangeListener = null; - } - - private class JavaElementChangeListener - implements IElementChangedListener { - - JavaElementChangeListener() { - super(); - } - - public void elementChanged(ElementChangedEvent event) { - JavaResourceModelTestCase.this.javaElementChanged(event); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - void javaElementChanged(ElementChangedEvent event) { - if (this.javaResourceCompilationUnit == null) { - return; - } - this.syncWithJavaDelta(event.getDelta()); - } - - /** - * NB: this is copied from GenericJpaProject, so it might need to be - * kept in synch with that code if it changes... yech... - */ - protected void syncWithJavaDelta(IJavaElementDelta delta) { - switch (delta.getElement().getElementType()) { - case IJavaElement.JAVA_MODEL : - case IJavaElement.JAVA_PROJECT : - case IJavaElement.PACKAGE_FRAGMENT_ROOT : - case IJavaElement.PACKAGE_FRAGMENT : - this.syncWithJavaDeltaChildren(delta); - break; - case IJavaElement.COMPILATION_UNIT : - this.javaCompilationUnitChanged(delta); - break; - default : - break; // ignore the elements inside a compilation unit - } - } - - protected void syncWithJavaDeltaChildren(IJavaElementDelta delta) { - for (IJavaElementDelta child : delta.getAffectedChildren()) { - this.syncWithJavaDelta(child); // recurse - } - } - - protected void javaCompilationUnitChanged(IJavaElementDelta delta) { - if (this.deltaIsRelevant(delta)) { - this.javaResourceCompilationUnit.synchronizeWithJavaSource(); - } - } - - protected boolean deltaIsRelevant(IJavaElementDelta delta) { - if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) { - return false; - } - return delta.getKind() == IJavaElementDelta.CHANGED; - } - - protected ICompilationUnit createAnnotationAndMembers(String packageName, String annotationName, String annotationBody) throws Exception { - return this.javaProject.createCompilationUnit(packageName, annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - protected ICompilationUnit createEnumAndMembers(String packageName, String enumName, String enumBody) throws Exception { - return this.javaProject.createCompilationUnit(packageName, enumName + ".java", "public enum " + enumName + " { " + enumBody + " }"); - } - - protected JavaResourcePackage buildJavaResourcePackage(ICompilationUnit cu) { - JavaResourcePackageInfoCompilationUnit pkgCu = - new SourcePackageInfoCompilationUnit( - cu, - this.buildAnnotationProvider(), - NullAnnotationEditFormatter.instance(), - CommandExecutor.Default.instance()); - this.javaResourceCompilationUnit = pkgCu; - return pkgCu.getPackage(); - } - - protected JavaResourcePersistentType buildJavaTypeResource(ICompilationUnit cu) { - this.javaResourceCompilationUnit = this.buildJavaResourceCompilationUnit(cu); - this.javaResourceCompilationUnit.resolveTypes(); - return this.hackJavaResourcePersistentType(); - } - - protected JavaResourcePersistentType hackJavaResourcePersistentType() { - return (JavaResourcePersistentType) ReflectionTools.getFieldValue(this.javaResourceCompilationUnit, "persistentType"); - } - - protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit cu) { - if (this.javaResourceCompilationUnit != null) { - throw new IllegalStateException(); - } - return new SourceTypeCompilationUnit( - cu, - this.buildAnnotationProvider(), - NullAnnotationEditFormatter.instance(), - CommandExecutor.Default.instance() - ); - } - - protected JpaAnnotationProvider buildAnnotationProvider() { - return new GenericJpaAnnotationProvider(this.annotationDefinitionProvider()); - } - - protected JpaAnnotationDefinitionProvider annotationDefinitionProvider() { - return GenericJpaAnnotationDefinitionProvider.instance(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java deleted file mode 100644 index 617405592b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java +++ /dev/null @@ -1,870 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement.Editor; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.internal.resource.java.source.SourceIdAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceOneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; - -@SuppressWarnings("nls") -public class JavaResourcePersistentAttributeTests extends JpaJavaResourceModelTestCase { - - public JavaResourcePersistentAttributeTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithNonResolvingField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private Foo foo;").append(CR); - sb.append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonResolvingMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private Foo foo;").append(CR); - sb.append(CR); - sb.append(" @Id"); - sb.append(CR); - sb.append(" public Foo getFoo() {").append(CR); - sb.append(" return this.foo;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" "); - sb.append(CR); - sb.append(" public void setFoo(Foo foo) {").append(CR); - sb.append(" this.foo = foo;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestEntityMultipleVariableDeclarationsPerLine() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" "); - sb.append("@Id"); - sb.append(CR); - sb.append(" "); - sb.append("@Column(name = \"baz\")"); - sb.append(" private String foo, bar;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithIdAndBasic() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append("@Basic"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append(" "); - sb.append("@Column"); - } - }); - } - - private ICompilationUnit createTestEntityWithColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name = \"FOO\", table = \"MY_TABLE\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithIdColumnGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.COLUMN, JPA.ID, JPA.GENERATED_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append("@Column"); - sb.append(CR); - sb.append("@GeneratedValue"); - } - }); - } - - - private ICompilationUnit createTestEntityMultipleColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name = \"FOO\")"); - sb.append(CR); - sb.append("@Column(name = \"BAR\")"); - } - }); - } - - private ICompilationUnit createTestEmbeddedWithAttributeOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverride(name = \"FOO\")"); - } - }); - } - private ICompilationUnit createTestEmbeddedWithAttributeOverrides() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverrides(@AttributeOverride(name = \"FOO\"))"); - } - }); - } - private ICompilationUnit createTestEmbeddedWithAttributeOverridesEmpty() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverrides()"); - } - }); - } - - private ICompilationUnit createTestEmbeddedWith2AttributeOverrides() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverrides({@AttributeOverride(name = \"FOO\"), @AttributeOverride(name = \"BAR\")})"); - } - }); - } - - private ICompilationUnit createTestEmbeddedWithAttributeOverrideAndAttributeOverrides() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverride(name = \"FOO\")"); - sb.append(CR); - sb.append("@AttributeOverrides({@AttributeOverride(name = \"BAR\"), @AttributeOverride(name = \"BAZ\")})"); - } - }); - } - - private ICompilationUnit createTestTypePublicAttribute() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public String foo;"); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypePackageAttribute() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" String foo;"); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeFinalAttribute() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public final String foo;"); - sb.append(CR); - } - }); - } - - public void testJavaAttributeAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertEquals(1, attributeResource.annotationsSize()); - } - - public void testJavaAttributeAnnotation() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertNotNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testJavaAttributeAnnotationNull() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertNull(attributeResource.getAnnotation(JPA.TABLE)); - } - - //This will result in a compilation error, but we assume the first column found - public void testDuplicateAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityMultipleColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation columnResource = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals("FOO", columnResource.getName()); - } - - public void testRemoveColumn() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - attributeResource.removeAnnotation(JPA.COLUMN); - - assertSourceDoesNotContain("@Column", cu); - } - - public void testRemoveColumnName() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ColumnAnnotation columnResource = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - columnResource.setTable(null); - assertSourceContains("@Column(name = \"FOO\")", cu); - - columnResource.setName(null); - assertSourceDoesNotContain("(name", cu); - assertSourceDoesNotContain("@Column(", cu); - } - - public void testMultipleAttributeMappings() throws Exception { - ICompilationUnit cu = this.createTestEntityWithIdAndBasic(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(2, attributeResource.annotationsSize()); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - assertNotNull(attributeResource.getAnnotation(JPA.ID)); - - JavaResourceNode javaAttributeMappingAnnotation = attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME); - assertTrue(javaAttributeMappingAnnotation instanceof BasicAnnotation); - assertSourceContains("@Basic", cu); - assertSourceContains("@Id", cu); - - attributeResource.setPrimaryAnnotation(JPA.ONE_TO_MANY, EmptyIterable.instance()); - assertEquals(1, attributeResource.annotationsSize()); - javaAttributeMappingAnnotation = attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertTrue(javaAttributeMappingAnnotation instanceof OneToManyAnnotation); - assertSourceDoesNotContain("@Id", cu); - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("@Basic", cu); - } - - public void testSetJavaAttributeMappingAnnotation() throws Exception { - ICompilationUnit cu = createTestType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertEquals(0, attributeResource.annotationsSize()); - - attributeResource.setPrimaryAnnotation(JPA.ID, EmptyIterable.instance()); - assertTrue(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME) instanceof IdAnnotation); - assertSourceContains("@Id", cu); - } - - public void testSetJavaAttributeMappingAnnotation2() throws Exception { - ICompilationUnit cu = createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertEquals(1, attributeResource.annotationsSize()); - - attributeResource.setPrimaryAnnotation(JPA.ID, Collections.singleton(ColumnAnnotation.ANNOTATION_NAME)); - assertTrue(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME) instanceof IdAnnotation); - - assertSourceContains("@Id", cu); - assertSourceContains("@Column", cu); - } - - public void testSetJavaAttributeMappingAnnotation3() throws Exception { - ICompilationUnit cu = createTestEntityWithIdColumnGeneratedValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertTrue(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME) instanceof IdAnnotation); - - attributeResource.setPrimaryAnnotation( - JPA.BASIC, - Arrays.asList(new String[] { - ColumnAnnotation.ANNOTATION_NAME, - GeneratedValueAnnotation.ANNOTATION_NAME})); - assertTrue(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME) instanceof BasicAnnotation); - - assertSourceDoesNotContain("@Id", cu); - assertSourceContains("@GeneratedValue", cu); //not supported by Basic - assertSourceContains("@Column", cu); //common between Id and Basic - } - - public void testSetJavaAttributeMappingAnnotationNull() throws Exception { - ICompilationUnit cu = createTestEntityWithIdColumnGeneratedValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertTrue(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME) instanceof IdAnnotation); - - attributeResource.setPrimaryAnnotation( - null, - Arrays.asList(new String[] { - ColumnAnnotation.ANNOTATION_NAME, - GeneratedValueAnnotation.ANNOTATION_NAME})); - - assertEquals(2, attributeResource.annotationsSize()); - assertSourceDoesNotContain("@Id", cu); - assertSourceContains("@GeneratedValue", cu); //not supported by Basic - assertSourceContains("@Column", cu); //common between Id and Basic - } - - public void testAddJavaAttributeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertSourceDoesNotContain("@Column", cu); - attributeResource.addAnnotation(JPA.COLUMN); - assertSourceContains("@Column", cu); - } - - public void testRemoveJavaAttributeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertSourceContains("@Column", cu); - attributeResource.removeAnnotation(JPA.COLUMN); - assertSourceDoesNotContain("@Column", cu); - } - - //update source code to change from @Id to @OneToOne and make sure @Column is not removed - public void testChangeAttributeMappingInSource() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - final JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - idField(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - SourceIdAnnotation.DECLARATION_ANNOTATION_ADAPTER.removeAnnotation(declaration); - } - }); - - cu.createImport("javax.persistence.OneToOne", null, new NullProgressMonitor()); - - idField(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - SourceOneToOneAnnotation.DECLARATION_ANNOTATION_ADAPTER.newMarkerAnnotation(declaration); - } - }); - - assertNotNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(attributeResource.getAnnotation(JPA.ID)); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_ONE)); - assertSourceContains("@Column", cu); - } - - public void testJavaAttributeAnnotationsNestable() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(1, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES).next(); - - assertEquals("FOO", attributeOverride.getName()); - } - - public void testJavaAttributeAnnotationsNoNestable() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(0, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testJavaAttributeAnnotationsContainerNoNestable() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverridesEmpty(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(0, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testJavaAttributeAnnotationsNestableAndContainer() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrideAndAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES).next(); - assertEquals("BAR", attributeOverrideResource.getName()); - } - - // -->> @AttributeOverride(name="FOO") - public void testAddJavaAttributeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - assertSourceContains("@AttributeOverride(name = \"FOO\")", cu); - } - - // @Embedded -->> @Embedded - // @AttributeOverride(name="FOO") @AttributeOverrides({@AttributeOverride(name="FOO"), @AttributeOverride(name="BAR")}) - public void testAddJavaAttributeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\"),@AttributeOverride(name = \"BAR\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - // @Embedded - // @AttributeOverrides(@AttributeOverride(name="FOO")) - // || - // \/ - // @Embedded - // @AttributeOverrides({@AttributeOverride(name="FOO"), @AttributeOverride(name="BAR")}) - public void testAddJavaAttributeAnnotationNestableContainer3() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\"),@AttributeOverride(name = \"BAR\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testAddJavaAttributeAnnotationNestableContainer5() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"BAR\"),@AttributeOverride(name = \"FOO\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - // @Embedded - // @SecondaryTable(name=\"FOO\") - // @AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"BAZ\")}) - // || - // \/ - // @Embedded - // @AttributeOverride(name=\"FOO\") - // @AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"BAZ\"), @AttributeOverride(name=\"BOO\")}) - public void testAddJavaAttributeAnnotationNestableContainer4() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrideAndAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"BAR\"), @AttributeOverride(name = \"BAZ\"),", cu); - assertSourceContains("@AttributeOverride})", cu); - attributeOverride.setName("BOO"); - - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(3, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - Iterator attributeOverrideAnnotations = attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride = (AttributeOverrideAnnotation) attributeOverrideAnnotations.next(); - assertEquals("BAR", attributeOverride.getName()); - attributeOverride = (AttributeOverrideAnnotation) attributeOverrideAnnotations.next(); - assertEquals("BAZ", attributeOverride.getName()); - attributeOverride = (AttributeOverrideAnnotation) attributeOverrideAnnotations.next(); - assertEquals("BOO", attributeOverride.getName()); - - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"BAR\"), @AttributeOverride(name = \"BAZ\"),", cu); - assertSourceContains("@AttributeOverride(name = \"BOO\")})", cu); - } - - //@Entity - //@AttributeOverride(name="FOO") - public void testRemoveJavaAttributeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - - assertSourceDoesNotContain("@AttributeOverride", cu); - } - - - //@Entity - //@SecondaryTables(@SecondaryTable(name="FOO")) - public void testRemoveJavaAttributeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - - assertSourceDoesNotContain("@AttributeOverride", cu); - assertSourceDoesNotContain("@AttributeOverrides", cu); - } - - public void testRemoveJavaAttributeAnnotationIndex() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE , JPA.ATTRIBUTE_OVERRIDES); - - assertSourceDoesNotContain("@AttributeOverride(name = \"FOO\"", cu); - assertSourceContains("@AttributeOverride(name = \"BAR\"", cu); - assertSourceDoesNotContain("@AttributeOverrides", cu); - } - - public void testRemoveJavaAttributeAnnotationIndex2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation newAnnotation = (AttributeOverrideAnnotation)attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - newAnnotation.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\"), @AttributeOverride(name = \"BAR\"),", cu); - assertSourceContains("@AttributeOverride(name = \"BAZ\")})", cu); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\"), @AttributeOverride(name = \"BAZ\")})", cu); - } - - public void testMoveJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation newAnnotation = (AttributeOverrideAnnotation)attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - newAnnotation.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\"), @AttributeOverride(name = \"BAR\"),", cu); - assertSourceContains("@AttributeOverride(name = \"BAZ\")})", cu); - - - attributeResource.moveAnnotation(0, 2, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"BAZ\"), @AttributeOverride(name = \"FOO\"),", cu); - assertSourceContains("@AttributeOverride(name = \"BAR\")})", cu); - } - - public void testMoveJavaTypeAnnotation2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation newAnnotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - newAnnotation.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"FOO\"), @AttributeOverride(name = \"BAR\"),", cu); - assertSourceContains("@AttributeOverride(name = \"BAZ\")})", cu); - - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name = \"BAR\"), @AttributeOverride(name = \"FOO\"),", cu); - assertSourceContains("@AttributeOverride(name = \"BAZ\")})", cu); - } - - //more detailed tests in JPTToolsTests - public void testIsPersistableField() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertTrue(attributeResource.isPersistable()); - } - - public void testIsPersistableField2() throws Exception { - ICompilationUnit cu = createTestEntityWithNonResolvingField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - @SuppressWarnings("unchecked") - List attributes = (List) ReflectionTools.getFieldValue(typeResource, "fields"); - JavaResourcePersistentAttribute attributeResource = attributes.get(0); - - assertEquals("foo", attributeResource.getName()); - assertTrue(attributeResource.isField()); - assertTrue(attributeResource.isPersistable()); //bug 196200 changed this - - this.javaProject.createCompilationUnit("test", "Foo.java", "public class Foo {}"); - - assertTrue(attributeResource.isPersistable()); - } - - public void testGetTypeName() throws Exception { - ICompilationUnit cu = createTestEntityWithNonResolvingField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - @SuppressWarnings("unchecked") - List attributes = (List) ReflectionTools.getFieldValue(typeResource, "fields"); - JavaResourcePersistentAttribute attributeResource = attributes.get(0); - - assertEquals("foo", attributeResource.getName()); - assertEquals("test.Foo", attributeResource.getTypeName()); //bug 196200 changed this - - this.javaProject.createCompilationUnit("test", "Foo.java", "public class Foo {}"); - - assertEquals("test.Foo", attributeResource.getTypeName()); - } - - - //more detailed tests in JPTToolsTests - public void testIsPersistableMethod() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableProperties().next(); - - assertTrue(attributeResource.isPersistable()); - } - - public void testIsPersistableMethod2() throws Exception { - ICompilationUnit cu = createTestEntityWithNonResolvingMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - @SuppressWarnings("unchecked") - List attributes = (List) ReflectionTools.getFieldValue(typeResource, "methods"); - JavaResourcePersistentAttribute attributeResource = attributes.get(0); - - assertEquals("foo", attributeResource.getName()); - assertTrue(attributeResource.isProperty()); - assertTrue(attributeResource.isPersistable());//bug 196200 changed this - - this.javaProject.createCompilationUnit("test", "Foo.java", "public class Foo {}"); - - assertTrue(attributeResource.isPersistable()); - } - - //this tests that we handle mutliple variable declarations in one line. - //The annotations should apply to all fields defined. This is not really a useful - //thing to do with JPA beyond the most basic things that use default column names - public void testMultipleVariableDeclarationsPerLine() throws Exception { - ICompilationUnit cu = createTestEntityMultipleVariableDeclarationsPerLine(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(4, CollectionTools.size(typeResource.fields())); - Iterator fields = typeResource.fields(); - JavaResourcePersistentAttribute attributeResource = fields.next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals("baz", column.getName()); - - attributeResource = fields.next(); - column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals("baz", column.getName()); - } - - public void testIsPublic() throws Exception { - ICompilationUnit cu = createTestTypePublicAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.persistableAttributes().next(); - - assertTrue(Modifier.isPublic(attribute.getModifiers())); - } - - public void testIsPublicFalse() throws Exception { - ICompilationUnit cu = createTestTypePackageAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.persistableAttributes().next(); - - assertFalse(Modifier.isPublic(attribute.getModifiers())); - } - - public void testIsFinal() throws Exception { - ICompilationUnit cu = createTestTypeFinalAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.persistableAttributes().next(); - - assertTrue(Modifier.isFinal(attribute.getModifiers())); - } - - public void testIsFinalFalse() throws Exception { - ICompilationUnit cu = createTestTypePackageAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.persistableAttributes().next(); - - assertFalse(Modifier.isFinal(attribute.getModifiers())); - } - - //TODO add tests for JPTTools static methods -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java deleted file mode 100644 index f3cc00f0cf..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java +++ /dev/null @@ -1,937 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement.Editor; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.internal.resource.java.source.SourceEmbeddableAnnotation; -import org.eclipse.jpt.core.internal.resource.java.source.SourceEntityAnnotation; -import org.eclipse.jpt.core.resource.java.AccessType; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.TableAnnotation; - -@SuppressWarnings("nls") -public class JavaResourcePersistentTypeTests extends JpaJavaResourceModelTestCase { - - public JavaResourcePersistentTypeTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestInvalidAnnotations() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator("javax.persistence.Foo"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Foo"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Foo"); - } - }); - } - - private ICompilationUnit createTestEntityWithMemberEmbeddable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append(" @Embeddable"); - sb.append(CR); - sb.append(" public static class Foo { }").append(CR); - - } - }); - } - - private ICompilationUnit createTestEntityDuplicates() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity(name = \"FirstEntity\")").append(CR); - sb.append("@Entity(name = \"SecondEntity\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithEmbeddable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@Embeddable"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedFieldAndMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedNonPersistableMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendGetNameMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedPersistableMethodNonPersistableField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column"); - sb.append(" private transient int notPersistable;").append(CR); - sb.append(CR); - - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Column"); - } - }); - } - - private ICompilationUnit createTestEntityNoPersistableFields() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.delete(sb.indexOf("private int id;"), sb.indexOf("private int id;") + "private int id;".length()); - sb.delete(sb.indexOf("private String name;"), sb.indexOf("private String name;") + "private String name;".length()); - } - }); - } - -// private ICompilationUnit createTestEntityLarge(final int i) throws Exception { -// return this.createTestType(new DefaultAnnotationWriter() { -// @Override -// public Iterator imports() { -// return new ArrayIterator(JPA.ENTITY + i); -// } -// @Override -// public void appendTypeAnnotationTo(StringBuilder sb) { -// sb.append("@Entity" + i); -// sb.append(CR); -// } -// @Override -// public String typeName() { -// return TYPE_NAME + i; -// } -// }); -// } -// -// public void testLarge() throws Exception { -// for (int i = START; i <= END; i++) { -// this.createAnnotationAndMembers("Entity" +i, "String name();"); -// } -// -// List cus = new ArrayList(); -// for (int i = START; i <= END; i++) { -// cus.add(createTestEntityLarge(i)); -// } -// long start = System.currentTimeMillis(); -// List typeResources = new ArrayList(); -// for (int i = 0; i < END; i++) { -// typeResources.add(buildJavaTypeResource(cus.get(i))); -// } -// long end = System.currentTimeMillis(); -// -// System.out.println(end-start + "ms"); -// for (int i = 0; i < END; i++) { -// assertEquals(1, CollectionTools.size(typeResources.get(i).javaTypeMappingAnnotations())); -// assertNotNull(typeResources.get(i).javaTypeMappingAnnotation(JPA.ENTITY + (i+1))); -// } -// -// -//// assertEquals(0, CollectionTools.size(typeResource.javaTypeAnnotations())); -// } - - - - private ICompilationUnit createTestEntityWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@Table(name = \"FOO\", schema = \"BAR\")"); - } - }); - } - -// private ICompilationUnit createTestEntityWithTableAndIdClass() throws Exception { -// createEntityAnnotation(); -// this.createAnnotationAndMembers("Table", "String name(); String schema();"); -// this.createAnnotationAndMembers("IdClass", "Class value();"); -// return this.createTestType(new DefaultAnnotationWriter() { -// @Override -// public Iterator imports() { -// return new ArrayIterator(JPA.ENTITY, JPA.TABLE, JPA.ID_CLASS); -// } -// @Override -// public void appendTypeAnnotationTo(StringBuilder sb) { -// sb.append("@Entity"); -// sb.append(CR); -// sb.append("@Table"); -// sb.append(CR); -// sb.append("@IdClass"); -// } -// }); -// } -// - - private ICompilationUnit createTestEntityMultipleTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@Table(name = \"FOO\")"); - sb.append(CR); - sb.append("@Table(name = \"BAR\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@SecondaryTable(name = \"FOO\")"); - } - }); - } - private ICompilationUnit createTestEntityWithEmptySecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@SecondaryTables()"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@SecondaryTables(@SecondaryTable(name = \"FOO\"))"); - } - }); - } - - private ICompilationUnit createTestEntityWith2SecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name = \"FOO\"), @SecondaryTable(name = \"BAR\")})"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTableAndSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@SecondaryTable(name = \"FOO\")"); - sb.append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"BAZ\")})"); - } - }); - } - - private ICompilationUnit createTestEntityWithMemberTypes() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append(" static class FooStatic {}").append(CR); - sb.append(CR); - sb.append(" class FooNotStatic {}").append(CR); - sb.append(CR); - sb.append(" @interface MyAnnotation {}").append(CR); - sb.append(CR); - sb.append(" enum MyEnum {}").append(CR); - } - }); - } - - public void testJavaTypeAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertEquals(2, typeResource.annotationsSize()); - } - - public void testJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertNotNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testJavaTypeAnnotationNull() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - //This will result in a compilation error, but we assume the first table found - public void testDuplicateAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityMultipleTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals("FOO", tableResource.getName()); - } - - public void testRemoveTable() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - typeResource.removeAnnotation(JPA.TABLE); - - assertSourceDoesNotContain("@Table", cu); - } - - public void testRemoveTableName() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType jrpt = buildJavaTypeResource(cu); - - TableAnnotation tableAnnotation = (TableAnnotation) jrpt.getAnnotation(JPA.TABLE); - tableAnnotation.setSchema(null); - assertSourceContains("@Table(name = \"FOO\")", cu); - - tableAnnotation.setName(null); - assertSourceDoesNotContain("(name", cu); - } - - public void testMultipleTypeMappings() throws Exception { - ICompilationUnit cu = this.createTestEntityWithEmbeddable(); - - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(2, typeResource.annotationsSize()); - assertNotNull(typeResource.getAnnotation(JPA.EMBEDDABLE)); - assertNotNull(typeResource.getAnnotation(JPA.ENTITY)); - - JavaResourceNode javaTypeMappingAnnotation = typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME); - assertTrue(javaTypeMappingAnnotation instanceof EmbeddableAnnotation); - assertSourceContains("@Entity", cu); - assertSourceContains("@Embeddable", cu); - - typeResource.setPrimaryAnnotation(JPA.MAPPED_SUPERCLASS, EmptyIterable.instance()); - assertEquals(1, typeResource.annotationsSize()); - javaTypeMappingAnnotation = typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME); - assertTrue(javaTypeMappingAnnotation instanceof MappedSuperclassAnnotation); - assertSourceDoesNotContain("@Entity", cu); - assertSourceContains("@MappedSuperclass", cu); - assertSourceDoesNotContain("@Embeddable", cu); - } - - public void testSetJavaTypeMappingAnnotation() throws Exception { - ICompilationUnit cu = createTestType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertEquals(0, typeResource.annotationsSize()); - - typeResource.setPrimaryAnnotation(JPA.ENTITY, EmptyIterable.instance()); - assertTrue(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME) instanceof EntityAnnotation); - assertSourceContains("@Entity", cu); - } - - public void testAddJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertSourceDoesNotContain("@Table", cu); - typeResource.addAnnotation(JPA.TABLE); - - assertSourceContains("@Table", cu); - } - - public void testRemoveJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertSourceContains("@Table", cu); - typeResource.removeAnnotation(JPA.TABLE); - assertSourceDoesNotContain("@Table", cu); - } - - //update source code to change from @Entity to @Embeddable and make sure @Table is not removed - public void testChangeTypeMappingInSource() throws Exception { - ICompilationUnit cu = createTestEntityWithTable(); - final JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - testType(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - SourceEntityAnnotation.DECLARATION_ANNOTATION_ADAPTER.removeAnnotation(declaration); - } - }); - - cu.createImport("javax.persistence.Embeddable", null, new NullProgressMonitor()); - - this.testType(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - SourceEmbeddableAnnotation.DECLARATION_ANNOTATION_ADAPTER.newMarkerAnnotation(declaration); - } - }); - - assertNotNull(typeResource.getAnnotation(JPA.TABLE)); - assertNull(typeResource.getAnnotation(JPA.ENTITY)); - assertNotNull(typeResource.getAnnotation(JPA.EMBEDDABLE)); - assertSourceContains("@Table", cu); - } - - public void testJavaTypeAnnotationsNestable() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(1, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals("FOO", secondaryTableResource.getName()); - } - - public void testJavaTypeAnnotationsNoNestable() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(0, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testJavaTypeAnnotationsContainerNoNestable() throws Exception { - ICompilationUnit cu = createTestEntityWithEmptySecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(0, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testJavaTypeAnnotationsNestableAndContainer() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTableAndSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - assertEquals("BAR", secondaryTableResource.getName()); - } - - // @Entity -->> @Entity - // @SecondaryTable(name="FOO") - public void testAddJavaTypeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("FOO"); - assertSourceContains("@SecondaryTable(name = \"FOO\")", cu); - } - - // @Entity -->> @Entity - // @SecondaryTable(name="FOO") @SecondaryTables({@SecondaryTable(name="FOO"), @SecondaryTable(name="BAR")}) - public void testAddJavaTypeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\"),@SecondaryTable(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - // @Entity - // @SecondaryTables(@SecondaryTable(name="FOO")) - // || - // \/ - // @Entity - // @SecondaryTables({@SecondaryTable(name="FOO"), @SecondaryTable(name="BAR")}) - public void testAddJavaTypeAnnotationNestableContainer3() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\"),@SecondaryTable(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testAddJavaTypeAnnotationNestableContainer5() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAR\"),@SecondaryTable(name = \"FOO\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testAddJavaTypeAnnotationNestableContainer6() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAR\"),@SecondaryTable(name = \"FOO\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAZ\"),@SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"FOO\")})", cu); - - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - // @Entity - // @SecondaryTable(name=\"FOO\") - // @SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\")}) - // || - // \/ - // @Entity - // @SecondaryTable(name=\"FOO\") - // @SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\"), @SecondaryTable(name=\"BOO\")}) - public void testAddJavaTypeAnnotationNestableContainer4() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTableAndSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"BAZ\"), @SecondaryTable})", cu); - secondaryTableResource.setName("BOO"); - - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - Iterator secondaryTableAnnotations = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource = (SecondaryTableAnnotation) secondaryTableAnnotations.next(); - assertEquals("BAR", secondaryTableResource.getName()); - secondaryTableResource = (SecondaryTableAnnotation) secondaryTableAnnotations.next(); - assertEquals("BAZ", secondaryTableResource.getName()); - secondaryTableResource = (SecondaryTableAnnotation) secondaryTableAnnotations.next(); - assertEquals("BOO", secondaryTableResource.getName()); - - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"BAZ\"), @SecondaryTable(name = \"BOO\")})", cu); - } - - //@Entity - //@SecondaryTable(name="FOO") - public void testRemoveJavaTypeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - - //@Entity - //@SecondaryTables(@SecondaryTable(name="FOO")) - public void testRemoveJavaTypeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - assertSourceDoesNotContain("@SecondaryTable", cu); - assertSourceDoesNotContain("@SecondaryTables", cu); - } - - public void testRemoveJavaTypeAnnotationIndex() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - assertSourceDoesNotContain("@SecondaryTable(name = \"FOO\"", cu); - assertSourceContains("@SecondaryTable(name = \"BAR\"", cu); - assertSourceDoesNotContain("@SecondaryTables", cu); - } - - public void testRemoveJavaTypeAnnotationIndex2() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation newAnnotation = (SecondaryTableAnnotation)typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - newAnnotation.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\"), @SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"BAZ", cu); - - typeResource.removeAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\"), @SecondaryTable(name = \"BAZ\")})", cu); - } - - public void testMoveJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation newAnnotation = (SecondaryTableAnnotation)typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - newAnnotation.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\"), @SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"BAZ\")})", cu); - - typeResource.moveAnnotation(0, 2, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAZ\"), @SecondaryTable(name = \"FOO\"), @SecondaryTable(name = \"BAR\")})", cu); - } - - public void testMoveJavaTypeAnnotation2() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation newAnnotation = (SecondaryTableAnnotation)typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - newAnnotation.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\"), @SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"BAZ\")})", cu); - - typeResource.moveAnnotation(2, 0, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAR\"), @SecondaryTable(name = \"BAZ\"), @SecondaryTable(name = \"FOO\")})", cu); - } - - public void testNestedTypes() throws Exception { - ICompilationUnit cu = createTestEntityWithMemberTypes(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals("only persistable types should be returned by #persistableTypes()", 2, CollectionTools.size(persistentType.persistableTypes())); - assertEquals("enums and interfaces should be ignored", 2, CollectionTools.size(persistentType.types())); - } - - public void testDuplicateEntityAnnotations() throws Exception { - ICompilationUnit cu = createTestEntityDuplicates(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - EntityAnnotation javaTypeMappingAnnotation = (EntityAnnotation) persistentType.getAnnotation(JPA.ENTITY); - assertEquals("FirstEntity", javaTypeMappingAnnotation.getName()); - - assertEquals(1, persistentType.annotationsSize()); - - javaTypeMappingAnnotation = (EntityAnnotation) persistentType.getAnnotation(EntityAnnotation.ANNOTATION_NAME); - assertEquals("FirstEntity", javaTypeMappingAnnotation.getName()); - - } - - - public void testAttributes() throws Exception { - // TODO - } - - public void testFields() throws Exception { - // TODO - } - - public void testProperties() throws Exception { - // TODO - } - - - //TODO more tests here with superclasses other than Object. - //1. Test where the superclass does not resolve - //2. Test a superclass that does resolve - //3. What about a superclass that is a class file in a jar?? - //4. - public void testGetSuperclassQualifiedName() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals("java.lang.Object", persistentType.getSuperclassQualifiedName()); - - } - - public void testIsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertTrue(persistentType.isAnnotated()); - - persistentType.removeAnnotation(JPA.ENTITY); - assertFalse(persistentType.isAnnotated()); - - persistentType.addAnnotation(JPA.TABLE); - assertTrue(persistentType.isAnnotated()); - } - - public void testIsMapped() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertTrue(persistentType.isMapped()); - - persistentType.removeAnnotation(JPA.ENTITY); - assertFalse(persistentType.isMapped()); - - persistentType.addAnnotation(JPA.TABLE); - assertFalse(persistentType.isMapped()); - - persistentType.addAnnotation(JPA.EMBEDDABLE); - assertTrue(persistentType.isMapped()); - } - - //more detailed tests in JPTToolsTests - public void testIsPersistable() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertTrue(persistentType.isPersistable()); - } - - public void testAnnotatedMemberType() throws Exception { - ICompilationUnit cu = this.createTestEntityWithMemberEmbeddable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertNotNull(typeResource.getAnnotation(JPA.ENTITY)); - assertNull(typeResource.getAnnotation(JPA.EMBEDDABLE)); - - JavaResourcePersistentType nestedType = typeResource.persistableTypes().next(); - assertNull(nestedType.getAnnotation(JPA.ENTITY)); - assertNotNull(nestedType.getAnnotation(JPA.EMBEDDABLE)); - } - - public void testInvalidAnnotations() throws Exception { - ICompilationUnit cu = this.createTestInvalidAnnotations(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertEquals(0, typeResource.annotationsSize()); - assertEquals(0, typeResource.annotationsSize()); - - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertEquals(0, attributeResource.annotationsSize()); - assertEquals(0, attributeResource.annotationsSize()); - } - - public void testGetAccessNoAttributesAnnotated() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertNull(JavaResourcePersistentType.Tools.buildAccess(persistentType)); - } - - public void testGetAccessFieldsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedField(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.FIELD, JavaResourcePersistentType.Tools.buildAccess(persistentType)); - } - - public void testGetAccessMethodsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedMethod(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.PROPERTY, JavaResourcePersistentType.Tools.buildAccess(persistentType)); - } - - public void testGetAccessFieldsAndMethodsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedFieldAndMethod(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.FIELD, JavaResourcePersistentType.Tools.buildAccess(persistentType)); - } - - public void testGetAccessNonPersistableMethodAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedNonPersistableMethod(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertNull(JavaResourcePersistentType.Tools.buildAccess(persistentType)); - } - - public void testGetAccessPersistableMethodAndNonPersistableFieldAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedPersistableMethodNonPersistableField(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.PROPERTY, JavaResourcePersistentType.Tools.buildAccess(persistentType)); - } - - public void testGetAccessNoPersistableFieldsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityNoPersistableFields(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertNull(JavaResourcePersistentType.Tools.buildAccess(persistentType)); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnTests.java deleted file mode 100644 index e6e0d4981e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnTests.java +++ /dev/null @@ -1,352 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; - -@SuppressWarnings("nls") -public class JoinColumnTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public JoinColumnTests(String name) { - super(name); - } - - private ICompilationUnit createTestJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(name = \"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(table = \"" + COLUMN_TABLE + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithReferencedColumnName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(referencedColumnName = \"" + COLUMN_REFERENCED_COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(" + booleanElement + " = true)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getReferencedColumnName()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@JoinColumn(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("(name", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@JoinColumn(table = \"Foo\")", cu); - - - column.setTable(null); - assertSourceDoesNotContain("(table", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@JoinColumn(referencedColumnName = \"Foo\")", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@JoinColumn(columnDefinition = \"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("(columnDefinition", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getUnique()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUnique()); - - assertSourceContains("@JoinColumn(unique = false)", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getNullable()); - - assertSourceContains("@JoinColumn(nullable = false)", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getInsertable()); - - assertSourceContains("@JoinColumn(insertable = false)", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertEquals(Boolean.TRUE, column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUpdatable()); - - assertSourceContains("@JoinColumn(updatable = false)", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnsTests.java deleted file mode 100644 index c1b8218775..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnsTests.java +++ /dev/null @@ -1,420 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -@SuppressWarnings("nls") -public class JoinColumnsTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public JoinColumnsTests(String name) { - super(name); - } - - private ICompilationUnit createTestJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn)"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(name = \"" + COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(table = \"" + COLUMN_TABLE + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithReferencedColumnName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(referencedColumnName = \"" + COLUMN_REFERENCED_COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(" + booleanElement + " = true))"); - } - }); - } - - private ICompilationUnit createTestJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@JoinColumns(@JoinColumn(name = \"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@JoinColumns(@JoinColumn(table = \"Foo\"))", cu); - - - column.setTable(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@JoinColumns(@JoinColumn(referencedColumnName = \"Foo\"))", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@JoinColumns(@JoinColumn(columnDefinition = \"Foo\"))", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getUnique().booleanValue()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(Boolean.FALSE); - assertFalse(column.getUnique().booleanValue()); - - assertSourceContains("@JoinColumns(@JoinColumn(unique = false))", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getNullable().booleanValue()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertFalse(column.getNullable().booleanValue()); - - assertSourceContains("@JoinColumns(@JoinColumn(nullable = false))", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getInsertable().booleanValue()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertFalse(column.getInsertable().booleanValue()); - - assertSourceContains("@JoinColumns(@JoinColumn(insertable = false))", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getUpdatable().booleanValue()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertFalse(column.getUpdatable().booleanValue()); - - assertSourceContains("@JoinColumns(@JoinColumn(updatable = false))", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@JoinColumn(", cu); - } - - - public void testAddJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@JoinColumns({@JoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@JoinColumn(name = \"FOO\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.JOIN_COLUMNS)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS))); - } - - public void testAddJoinColumnToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@JoinColumns({@JoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@JoinColumn(name = \"FOO\")})", cu); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - assertSourceContains("@JoinColumns({@JoinColumn(name = \"BAZ\"),@JoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"), @JoinColumn(name = \"FOO\")})", cu); - - Iterator joinColumns = attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumns.next()).getName()); - - assertNull(attributeResource.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.JOIN_COLUMNS)); - assertEquals(3, CollectionTools.size(attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS))); - } - - - public void testRemoveJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@JoinColumns({@JoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@JoinColumn(name = \"FOO\")})", cu); - - attributeResource.removeAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - assertSourceContains("@JoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\")", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinTableTests.java deleted file mode 100644 index ee05fd08d6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinTableTests.java +++ /dev/null @@ -1,656 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; - -@SuppressWarnings("nls") -public class JoinTableTests extends JpaJavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public JoinTableTests(String name) { - super(name); - } - - private ICompilationUnit createTestJoinTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(name = \"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithSchema() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_TABLE); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(schema = \"" + SCHEMA_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithCatalog() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(catalog = \"" + CATALOG_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(joinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn})"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithInverseJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertEquals(TABLE_NAME, table.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getName()); - assertNull(table.getCatalog()); - assertNull(table.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getName()); - - table.setName("Foo"); - assertEquals("Foo", table.getName()); - - assertSourceContains("@JoinTable(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals(TABLE_NAME, table.getName()); - - table.setName(null); - assertNull(table.getName()); - - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@JoinTable(catalog = \"Foo\")", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@JoinTable(schema = \"Foo\")", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint})", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, table.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(2, table.uniqueConstraintsSize()); - assertSourceContains("@JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.removeUniqueConstraint(0); - assertEquals("BAZ", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals(1, table.uniqueConstraintsSize()); - assertSourceContains("@JoinTable(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"}))", cu); - - table.removeUniqueConstraint(0); - assertEquals(0, table.uniqueConstraintsSize()); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertSourceContains("@JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.moveUniqueConstraint(2, 0); - assertSourceContains("@JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertSourceContains("@JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.moveUniqueConstraint(0, 2); - assertSourceContains("@JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})})", cu); - } - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(0, table.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - - table.addJoinColumn(0); - table.addJoinColumn(1); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - table.addJoinColumn(0).setName("FOO"); - table.addJoinColumn(1); - table.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertSourceContains("@JoinTable(joinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addJoinColumn(0).setName("FOO"); - - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertEquals("BAR", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - - table.removeJoinColumn(1); - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals(2, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - - table.removeJoinColumn(0); - assertNull(table.joinColumnAt(0).getName()); - assertEquals(1, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns = @JoinColumn)", cu); - - - table.removeJoinColumn(0); - assertEquals(0, table.joinColumnsSize()); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - table.moveJoinColumn(2, 0); - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals("FOO", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")})", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - - table.moveJoinColumn(0, 2); - assertNull(table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertEquals("BAR", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")})", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@JoinTable(joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn})", cu); - } - - public void testInverseJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(0, table.inverseJoinColumnsSize()); - } - - public void testInverseJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - - table.addInverseJoinColumn(0); - table.addInverseJoinColumn(1); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testInverseJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testAddInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - table.addInverseJoinColumn(0).setName("FOO"); - table.addInverseJoinColumn(1); - table.addInverseJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.inverseJoinColumnAt(0).getName()); - assertEquals("FOO", table.inverseJoinColumnAt(1).getName()); - assertNull(table.inverseJoinColumnAt(2).getName()); - assertSourceContains("@JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addInverseJoinColumn(2).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(1); - assertSourceContains("@JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn(name = \"FOO\")})", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceContains("@JoinTable(inverseJoinColumns = @JoinColumn(name = \"FOO\"))", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceDoesNotContain("@JoinTable(", cu); - } - - public void testMoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addInverseJoinColumn(0).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(2, 0); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@JoinTable(inverseJoinColumns = {@JoinColumn(name = \"BAR\"), @JoinColumn, @JoinColumn(name = \"FOO\")})", cu); - } - - public void testMoveInverseJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addInverseJoinColumn(1).setName("FOO"); - - Iterator inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(0, 2); - inverseJoinColumns = table.inverseJoinColumns(); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@JoinTable(inverseJoinColumns = {@JoinColumn, @JoinColumn(name = \"BAR\"), @JoinColumn(name = \"FOO\")})", cu); - } - - public void testSetInverseJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.inverseJoinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.inverseJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@JoinTable(inverseJoinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java deleted file mode 100644 index 8bbba067d6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; - -public class JpaJavaResourceModelTestCase - extends JavaResourceModelTestCase { - - public static final String JAVAX_PERSISTENCE_PACKAGE_NAME = "javax.persistence"; //$NON-NLS-1$ - - - public JpaJavaResourceModelTestCase(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.javaProject.addJar(TestJpaProject.jpaJarName()); - if (TestJpaProject.eclipseLinkJarName() != null) { - this.javaProject.addJar(TestJpaProject.eclipseLinkJarName()); - } - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - // nothing as of yet - } - - protected ICompilationUnit createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - return createAnnotationAndMembers(JAVAX_PERSISTENCE_PACKAGE_NAME, annotationName, annotationBody); - } - - protected ICompilationUnit createEnumAndMembers(String enumName, String enumBody) throws Exception { - return createEnumAndMembers(JAVAX_PERSISTENCE_PACKAGE_NAME, enumName, enumBody); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JptJavaResourceTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JptJavaResourceTests.java deleted file mode 100644 index fc022c1bad..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JptJavaResourceTests.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptJavaResourceTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptJavaResourceTests.class.getPackage().getName()); - suite.addTestSuite(JavaResourcePersistentTypeTests.class); - suite.addTestSuite(JavaResourcePersistentAttributeTests.class); - suite.addTestSuite(JPTToolsTests.class); - - suite.addTestSuite(AssociationOverrideTests.class); - suite.addTestSuite(AssociationOverridesTests.class); - suite.addTestSuite(AttributeOverrideTests.class); - suite.addTestSuite(AttributeOverridesTests.class); - suite.addTestSuite(BasicTests.class); - suite.addTestSuite(ColumnTests.class); - suite.addTestSuite(DiscriminatorValueTests.class); - suite.addTestSuite(DiscriminatorColumnTests.class); - suite.addTestSuite(EmbeddableTests.class); - suite.addTestSuite(EmbeddedTests.class); - suite.addTestSuite(EmbeddedIdTests.class); - suite.addTestSuite(EntityTests.class); - suite.addTestSuite(EnumeratedTests.class); - suite.addTestSuite(GeneratedValueTests.class); - suite.addTestSuite(IdClassTests.class); - suite.addTestSuite(IdTests.class); - suite.addTestSuite(InheritanceTests.class); - suite.addTestSuite(JoinColumnTests.class); - suite.addTestSuite(JoinColumnsTests.class); - suite.addTestSuite(JoinTableTests.class); - suite.addTestSuite(LobTests.class); - suite.addTestSuite(ManyToManyTests.class); - suite.addTestSuite(ManyToOneTests.class); - suite.addTestSuite(MapKeyTests.class); - suite.addTestSuite(MappedSuperclassTests.class); - suite.addTestSuite(NamedNativeQueryTests.class); - suite.addTestSuite(NamedNativeQueriesTests.class); - suite.addTestSuite(NamedQueryTests.class); - suite.addTestSuite(NamedQueriesTests.class); - suite.addTestSuite(OneToManyTests.class); - suite.addTestSuite(OneToOneTests.class); - suite.addTestSuite(OrderByTests.class); - suite.addTestSuite(PrimaryKeyJoinColumnTests.class); - suite.addTestSuite(PrimaryKeyJoinColumnsTests.class); - suite.addTestSuite(QueryHintTests.class); - suite.addTestSuite(SecondaryTableTests.class); - suite.addTestSuite(SecondaryTablesTests.class); - suite.addTestSuite(SequenceGeneratorTests.class); - suite.addTestSuite(TableGeneratorTests.class); - suite.addTestSuite(TableTests.class); - suite.addTestSuite(TemporalTests.class); - suite.addTestSuite(TransientTests.class); - suite.addTestSuite(VersionTests.class); - - return suite; - } - - private JptJavaResourceTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/LobTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/LobTests.java deleted file mode 100644 index f87cb06662..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/LobTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.LobAnnotation; - -@SuppressWarnings("nls") -public class LobTests extends JpaJavaResourceModelTestCase { - - public LobTests(String name) { - super(name); - } - - private ICompilationUnit createTestLob() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.LOB); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Lob"); - } - }); - } - - public void testLob() throws Exception { - ICompilationUnit cu = this.createTestLob(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - LobAnnotation lob = (LobAnnotation) attributeResource.getAnnotation(JPA.LOB); - assertNotNull(lob); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToManyTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToManyTests.java deleted file mode 100644 index 982f654207..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToManyTests.java +++ /dev/null @@ -1,394 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; - -@SuppressWarnings("nls") -public class ManyToManyTests extends JpaJavaResourceModelTestCase { - - public ManyToManyTests(String name) { - super(name); - } - - private ICompilationUnit createTestManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithMappedBy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(mappedBy = \"foo\")"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testManyToMany() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertNotNull(manyToMany); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToMany.getFetch()); - - assertSourceContains("@ManyToMany(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(null); - assertNull(manyToMany.getFetch()); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("fetch", cu); - } - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - - manyToMany.setTargetEntity("Foo"); - - assertSourceContains("@ManyToMany(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - - manyToMany.setTargetEntity(null); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, manyToMany.getFullyQualifiedTargetEntityClassName()); - - manyToMany.setTargetEntity("Foo"); - - assertSourceContains("@ManyToMany(targetEntity = Foo.class)", cu); - - assertEquals("Foo", manyToMany.getTargetEntity()); - - assertEquals("Foo", manyToMany.getFullyQualifiedTargetEntityClassName()); //bug 196200 changed this - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals("foo", manyToMany.getMappedBy()); - } - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals(null, manyToMany.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertNull(manyToMany.getMappedBy()); - manyToMany.setMappedBy("bar"); - assertEquals("bar", manyToMany.getMappedBy()); - - assertSourceContains("@ManyToMany(mappedBy = \"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertEquals("foo", manyToMany.getMappedBy()); - - manyToMany.setMappedBy(null); - assertNull(manyToMany.getMappedBy()); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeAll()); - - manyToMany.setCascadeAll(true); - assertSourceContains("@ManyToMany(cascade = ALL)", cu); - - assertTrue(manyToMany.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(true); - assertSourceContains("@ManyToMany(cascade = MERGE)", cu); - - assertTrue(manyToMany.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadePersist()); - - manyToMany.setCascadePersist(true); - assertSourceContains("@ManyToMany(cascade = PERSIST)", cu); - - assertTrue(manyToMany.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeRemove()); - - manyToMany.setCascadeRemove(true); - assertSourceContains("@ManyToMany(cascade = REMOVE)", cu); - - assertTrue(manyToMany.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeRefresh()); - - manyToMany.setCascadeRefresh(true); - assertSourceContains("@ManyToMany(cascade = REFRESH)", cu); - - assertTrue(manyToMany.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeAll()); - - manyToMany.setCascadeAll(true); - assertTrue(manyToMany.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@ManyToMany(cascade = CascadeType.ALL)", cu); - - manyToMany.setCascadeAll(false); - assertFalse(manyToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - manyToMany.setCascadeAll(false); - assertFalse(manyToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(false); //TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(false); - assertFalse(manyToMany.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeMerge()); - assertTrue(manyToMany.isCascadeRemove()); - - manyToMany.setCascadeMerge(false); - assertSourceContains("@ManyToMany(cascade = REMOVE)", cu); - - manyToMany.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToOneTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToOneTests.java deleted file mode 100644 index f890dae947..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToOneTests.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; - -@SuppressWarnings("nls") -public class ManyToOneTests extends JpaJavaResourceModelTestCase { - - public ManyToOneTests(String name) { - super(name); - } - - private ICompilationUnit createTestManyToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithOptional() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(optional = true)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testManyToOne() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertNotNull(manyToOne); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - - manyToOne.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToOne.getFetch()); - - assertSourceContains("@ManyToOne(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - - manyToOne.setFetch(null); - assertNull(manyToOne.getFetch()); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - - manyToOne.setTargetEntity("Foo"); - - assertSourceContains("@ManyToOne(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - - manyToOne.setTargetEntity(null); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, manyToOne.getFullyQualifiedTargetEntityClassName()); - - manyToOne.setTargetEntity("Foo"); - - assertSourceContains("@ManyToOne(targetEntity = Foo.class)", cu); - - assertEquals("Foo", manyToOne.getTargetEntity()); - - assertEquals("Foo", manyToOne.getFullyQualifiedTargetEntityClassName());//bug 196200 changed this - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - assertSourceContains("@ManyToOne(optional = false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(null); - assertNull(manyToOne.getOptional()); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeAll()); - - manyToOne.setCascadeAll(true); - assertSourceContains("@ManyToOne(cascade = ALL)", cu); - - assertTrue(manyToOne.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(true); - assertSourceContains("@ManyToOne(cascade = MERGE)", cu); - - assertTrue(manyToOne.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadePersist()); - - manyToOne.setCascadePersist(true); - assertSourceContains("@ManyToOne(cascade = PERSIST)", cu); - - assertTrue(manyToOne.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeRemove()); - - manyToOne.setCascadeRemove(true); - assertSourceContains("@ManyToOne(cascade = REMOVE)", cu); - - assertTrue(manyToOne.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeRefresh()); - - manyToOne.setCascadeRefresh(true); - assertSourceContains("@ManyToOne(cascade = REFRESH)", cu); - - assertTrue(manyToOne.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeAll()); - - manyToOne.setCascadeAll(true); - assertTrue(manyToOne.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@ManyToOne(cascade = CascadeType.ALL)", cu); - - manyToOne.setCascadeAll(false); - assertFalse(manyToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - manyToOne.setCascadeAll(false); - assertFalse(manyToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(false); - assertFalse(manyToOne.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeMerge()); - assertTrue(manyToOne.isCascadeRemove()); - - manyToOne.setCascadeMerge(false); - assertSourceContains("@ManyToOne(cascade = REMOVE)", cu); - - manyToOne.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MapKeyTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MapKeyTests.java deleted file mode 100644 index 6397caf248..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MapKeyTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; - -@SuppressWarnings("nls") -public class MapKeyTests extends JpaJavaResourceModelTestCase { - - public MapKeyTests(String name) { - super(name); - } - - private ICompilationUnit createTestMapKey() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAP_KEY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKey"); - } - }); - } - - private ICompilationUnit createTestMapKeyWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAP_KEY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKey(name = \"key\")"); - } - }); - } - - public void testMapKey() throws Exception { - ICompilationUnit cu = this.createTestMapKey(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(JPA.MAP_KEY); - assertNotNull(mapKey); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestMapKeyWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(JPA.MAP_KEY); - assertEquals("key", mapKey.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestMapKey(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(JPA.MAP_KEY); - - mapKey.setName("foo"); - - assertSourceContains("@MapKey(name = \"foo\")", cu); - - mapKey.setName(null); - - assertSourceContains("@MapKey", cu); - assertSourceDoesNotContain("@MapKey(name = \"foo\")", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MappedSuperclassTests.java deleted file mode 100644 index 23c275ae9b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MappedSuperclassTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; - -@SuppressWarnings("nls") -public class MappedSuperclassTests extends JpaJavaResourceModelTestCase { - - public MappedSuperclassTests(String name) { - super(name); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassAndEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - sb.append("@Entity"); - } - }); - } - - public void testMappedSuperclass() throws Exception { - ICompilationUnit cu = this.createTestMappedSuperclass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof MappedSuperclassAnnotation); - } - - public void testMappedSuperclassAndEntity() throws Exception { - ICompilationUnit cu = this.createTestMappedSuperclassAndEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof EntityAnnotation); - - MappedSuperclassAnnotation mappedSuperclass = (MappedSuperclassAnnotation) typeResource.getAnnotation(JPA.MAPPED_SUPERCLASS); - assertNotNull(mappedSuperclass); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueriesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueriesTests.java deleted file mode 100644 index 19f707e516..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueriesTests.java +++ /dev/null @@ -1,421 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -@SuppressWarnings("nls") -public class NamedNativeQueriesTests extends JpaJavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - private static final String QUERY_RESULT_CLASS = "Result"; - private static final String QUERY_RESULT_SET_MAPPING = "resultSetMapping"; - - public NamedNativeQueriesTests(String name) { - super(name); - } - - private ICompilationUnit createTestNamedNativeQueries() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery)"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithName() throws Exception { - return createTestNamedNativeQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedNativeQueryWithQuery() throws Exception { - return createTestNamedNativeQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultSetMapping() throws Exception { - return createTestNamedNativeQueryWithStringElement("resultSetMapping", QUERY_RESULT_SET_MAPPING); - } - - - private ICompilationUnit createTestNamedNativeQueryWithStringElement(final String elementName, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery(" + elementName + " = \"" + value + "\"))"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery(resultClass = " + QUERY_RESULT_CLASS + ".class))"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithQueryHints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint}))"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\")"); - } - }); - } - - public void testNamedNativeQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedNativeQuery(name = \"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedNativeQuery(query = \"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testGetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - } - - public void testSetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - - namedQuery.setResultClass("foo"); - assertEquals("foo", namedQuery.getResultClass()); - - assertSourceContains("@NamedNativeQuery(resultClass = foo.class)", cu); - - namedQuery.setResultClass(null); - assertNull(namedQuery.getResultClass()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testGetFullyQualifiedClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertNotNull(namedQuery.getResultClass()); - assertEquals("Result", namedQuery.getFullyQualifiedResultClassName());//bug 196200 changed this - - namedQuery.setResultClass(TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, namedQuery.getFullyQualifiedResultClassName()); - assertSourceContains("@NamedNativeQuery(resultClass = " + TYPE_NAME + ".class)", cu); - } - - public void testGetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - } - - public void testSetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - - namedQuery.setResultSetMapping("foo"); - assertEquals("foo", namedQuery.getResultSetMapping()); - - assertSourceContains("@NamedNativeQuery(resultSetMapping = \"foo\")", cu); - - namedQuery.setResultSetMapping(null); - assertNull(namedQuery.getResultSetMapping()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - namedQuery.addHint(0).setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertSourceContains("@NamedNativeQuery(hints = {@QueryHint(name = \"BAR\"),@QueryHint(name = \"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints = {@QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")}))", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints = @QueryHint(name = \"BAR\", value = \"FOO\")))", cu); - - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint, @QueryHint(name = \"BAZ\")}))", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints = {@QueryHint, @QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")}))", cu); - } - - public void testAddNamedNativeQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"),@NamedNativeQuery(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES))); - } - - public void testAddNamedNativeQueryToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"),@NamedNativeQuery(name = \"BAR\")})", cu); - - namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAZ"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name = \"BAZ\"),@NamedNativeQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"), @NamedNativeQuery(name = \"BAR\")})", cu); - - Iterator namedQueries = typeResource.annotations(JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) namedQueries.next()).getName()); - assertEquals("foo", ((NamedNativeQueryAnnotation) namedQueries.next()).getName()); - assertEquals("BAR", ((NamedNativeQueryAnnotation) namedQueries.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES))); - } - - public void testRemoveNamedNativeQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"),@NamedNativeQuery(name = \"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - assertSourceContains("@NamedNativeQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\")", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueryTests.java deleted file mode 100644 index c6f214b697..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueryTests.java +++ /dev/null @@ -1,341 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; - -@SuppressWarnings("nls") -public class NamedNativeQueryTests extends JpaJavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - private static final String QUERY_RESULT_CLASS = "Result"; - private static final String QUERY_RESULT_SET_MAPPING = "resultSetMapping"; - - public NamedNativeQueryTests(String name) { - super(name); - } - - private ICompilationUnit createTestNamedNativeQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithName() throws Exception { - return createTestNamedNativeQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedNativeQueryWithQuery() throws Exception { - return createTestNamedNativeQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultSetMapping() throws Exception { - return createTestNamedNativeQueryWithStringElement("resultSetMapping", QUERY_RESULT_SET_MAPPING); - } - - - private ICompilationUnit createTestNamedNativeQueryWithStringElement(final String elementName, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(" + elementName + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(resultClass = " + QUERY_RESULT_CLASS + ".class)"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithQueryHints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_NATIVE_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint})"); - } - }); - } - - public void testNamedNativeQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedNativeQuery(name = \"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedNativeQuery(query = \"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testGetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - } - - public void testSetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - - namedQuery.setResultClass("foo"); - assertEquals("foo", namedQuery.getResultClass()); - - assertSourceContains("@NamedNativeQuery(resultClass = foo.class)", cu); - - namedQuery.setResultClass(null); - assertNull(namedQuery.getResultClass()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testGetFullyQualifiedClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertNotNull(namedQuery.getResultClass()); - assertEquals("Result", namedQuery.getFullyQualifiedResultClassName());//bug 196200 changed this - - namedQuery.setResultClass(TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, namedQuery.getFullyQualifiedResultClassName()); - assertSourceContains("@NamedNativeQuery(resultClass = " + TYPE_NAME + ".class)", cu); - } - - public void testGetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - } - - public void testSetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - - namedQuery.setResultSetMapping("foo"); - assertEquals("foo", namedQuery.getResultSetMapping()); - - assertSourceContains("@NamedNativeQuery(resultSetMapping = \"foo\")", cu); - - namedQuery.setResultSetMapping(null); - assertNull(namedQuery.getResultSetMapping()); - - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - assertEquals(2, namedQuery.hintsSize()); - } - - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - namedQuery.addHint(0).setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertSourceContains("@NamedNativeQuery(hints = {@QueryHint(name = \"BAR\"),@QueryHint(name = \"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints = {@QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints = @QueryHint(name = \"BAR\", value = \"FOO\"))", cu); - - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedNativeQuery(", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint, @QueryHint(name = \"BAZ\")})", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints = {@QueryHint, @QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueriesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueriesTests.java deleted file mode 100644 index 7ab59df81b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueriesTests.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; - -@SuppressWarnings("nls") -public class NamedQueriesTests extends JpaJavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - - public NamedQueriesTests(String name) { - super(name); - } - - private ICompilationUnit createTestNamedQueries() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERIES, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQueries(@NamedQuery)"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithName() throws Exception { - return createTestNamedQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedQueryWithQuery() throws Exception { - return createTestNamedQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedQueryWithStringElement(final String elementName, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERIES, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQueries(@NamedQuery(" + elementName + " = \"" + value + "\"))"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithQueryHints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERIES, JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQueries(@NamedQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint}))"); - } - }); - } - - - private ICompilationUnit createTestNamedQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"))"); - } - }); - } - - public void testNamedQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedQuery(name = \"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedQuery(", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedQuery(query = \"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedQuery(", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - namedQuery.addHint(0).setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - - assertSourceContains("@NamedQuery(hints = {@QueryHint(name = \"BAR\"),@QueryHint(name = \"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints = {@QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")}))", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints = @QueryHint(name = \"BAR\", value = \"FOO\")))", cu); - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedQuery(", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint, @QueryHint(name = \"BAZ\")}))", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.getNestedAnnotations().iterator().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints = {@QueryHint, @QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")}))", cu); - } - - public void testAddNamedQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedQueries({@NamedQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),@NamedQuery(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.NAMED_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_QUERIES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.NAMED_QUERY, JPA.NAMED_QUERIES))); - } - - public void testAddNamedQueryToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedQueries({@NamedQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),@NamedQuery(name = \"BAR\")})", cu); - - - namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAZ"); - assertSourceContains("@NamedQueries({@NamedQuery(name = \"BAZ\"),@NamedQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")), @NamedQuery(name = \"BAR\")})", cu); - - Iterator namedQueries = typeResource.annotations(JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - assertEquals("BAZ", ((NamedQueryAnnotation) namedQueries.next()).getName()); - assertEquals("foo", ((NamedQueryAnnotation) namedQueries.next()).getName()); - assertEquals("BAR", ((NamedQueryAnnotation) namedQueries.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.NAMED_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_QUERIES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.NAMED_QUERY, JPA.NAMED_QUERIES))); - } - - public void testRemoveNamedQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedQueries({@NamedQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\")),@NamedQuery(name = \"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - assertSourceContains("@NamedQuery(name = \"foo\", query = \"bar\", hints = @QueryHint(name = \"BAR\", value = \"FOO\"))", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueryTests.java deleted file mode 100644 index 348023a453..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueryTests.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; - -@SuppressWarnings("nls") -public class NamedQueryTests extends JpaJavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - - public NamedQueryTests(String name) { - super(name); - } - - private ICompilationUnit createTestNamedQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithName() throws Exception { - return createTestNamedQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedQueryWithQuery() throws Exception { - return createTestNamedQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedQueryWithStringElement(final String elementName, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(" + elementName + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithQueryHints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint})"); - } - }); - } - - public void testNamedQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedQuery(name = \"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedQuery(", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedQuery(query = \"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedQuery(", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - assertEquals(2, namedQuery.hintsSize()); - - ListIterator iterator = namedQuery.hints(); - assertEquals("BAR", iterator.next().getName()); - assertNull(iterator.next().getName()); - } - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - QueryHintAnnotation queryHint = namedQuery.addHint(0); - queryHint.setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertSourceContains("@NamedQuery(hints = {@QueryHint(name = \"BAR\"),@QueryHint(name = \"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints = {@QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints = @QueryHint(name = \"BAR\", value = \"FOO\"))", cu); - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedQuery(", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints = {@QueryHint(name = \"BAR\", value = \"FOO\"), @QueryHint, @QueryHint(name = \"BAZ\")})", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints = {@QueryHint, @QueryHint(name = \"BAZ\"), @QueryHint(name = \"BAR\", value = \"FOO\")})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToManyTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToManyTests.java deleted file mode 100644 index 11b1dbf0e5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToManyTests.java +++ /dev/null @@ -1,397 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; - -@SuppressWarnings("nls") -public class OneToManyTests extends JpaJavaResourceModelTestCase { - - public OneToManyTests(String name) { - super(name); - } - - private ICompilationUnit createTestOneToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithMappedBy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(mappedBy = \"foo\")"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testOneToMany() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertNotNull(oneToMany); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToMany.getFetch()); - - assertSourceContains("@OneToMany(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(null); - assertNull(oneToMany.getFetch()); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - - oneToMany.setTargetEntity("Foo"); - - assertSourceContains("@OneToMany(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - - oneToMany.setTargetEntity(null); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, oneToMany.getFullyQualifiedTargetEntityClassName()); - - oneToMany.setTargetEntity("Foo"); - - assertSourceContains("@OneToMany(targetEntity = Foo.class)", cu); - - assertEquals("Foo", oneToMany.getTargetEntity()); - - assertEquals("Foo", oneToMany.getFullyQualifiedTargetEntityClassName()); //bug 196200 changed this - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals("foo", oneToMany.getMappedBy()); - } - - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals(null, oneToMany.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertNull(oneToMany.getMappedBy()); - oneToMany.setMappedBy("bar"); - assertEquals("bar", oneToMany.getMappedBy()); - - assertSourceContains("@OneToMany(mappedBy = \"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertEquals("foo", oneToMany.getMappedBy()); - - oneToMany.setMappedBy(null); - assertNull(oneToMany.getMappedBy()); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeAll()); - - oneToMany.setCascadeAll(true); - assertSourceContains("@OneToMany(cascade = ALL)", cu); - - assertTrue(oneToMany.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(true); - assertSourceContains("@OneToMany(cascade = MERGE)", cu); - - assertTrue(oneToMany.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadePersist()); - - oneToMany.setCascadePersist(true); - assertSourceContains("@OneToMany(cascade = PERSIST)", cu); - - assertTrue(oneToMany.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeRemove()); - - oneToMany.setCascadeRemove(true); - assertSourceContains("@OneToMany(cascade = REMOVE)", cu); - - assertTrue(oneToMany.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeRefresh()); - - oneToMany.setCascadeRefresh(true); - assertSourceContains("@OneToMany(cascade = REFRESH)", cu); - - assertTrue(oneToMany.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeAll()); - - oneToMany.setCascadeAll(true); - assertTrue(oneToMany.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@OneToMany(cascade = CascadeType.ALL)", cu); - - oneToMany.setCascadeAll(false); - assertFalse(oneToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - oneToMany.setCascadeAll(false); - assertFalse(oneToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(false); - assertFalse(oneToMany.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeMerge()); - assertTrue(oneToMany.isCascadeRemove()); - - oneToMany.setCascadeMerge(false); - assertSourceContains("@OneToMany(cascade = REMOVE)", cu); - - oneToMany.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToOneTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToOneTests.java deleted file mode 100644 index 4b5bab97aa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToOneTests.java +++ /dev/null @@ -1,447 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; - -@SuppressWarnings("nls") -public class OneToOneTests extends JpaJavaResourceModelTestCase { - - public OneToOneTests(String name) { - super(name); - } - - private ICompilationUnit createTestOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(fetch = FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithTargetEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(targetEntity = AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithOptional() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(optional = true)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithMappedBy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(mappedBy = \"foo\")"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade = CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithMultipleCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade = {CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithDuplicateCascade() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade = {CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testOneToOne() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertNotNull(oneToOne); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToOne.getFetch()); - - assertSourceContains("@OneToOne(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(null); - assertNull(oneToOne.getFetch()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - - oneToOne.setTargetEntity("Foo"); - - assertSourceContains("@OneToOne(targetEntity = Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - - oneToOne.setTargetEntity(null); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, oneToOne.getFullyQualifiedTargetEntityClassName()); - - oneToOne.setTargetEntity("Foo"); - - assertSourceContains("@OneToOne(targetEntity = Foo.class)", cu); - - assertEquals("Foo", oneToOne.getTargetEntity()); - - assertEquals("Foo", oneToOne.getFullyQualifiedTargetEntityClassName()); //bug 196200 changed this - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - assertSourceContains("@OneToOne(optional = false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(null); - assertNull(oneToOne.getOptional()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals("foo", oneToOne.getMappedBy()); - } - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals(null, oneToOne.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertNull(oneToOne.getMappedBy()); - oneToOne.setMappedBy("bar"); - assertEquals("bar", oneToOne.getMappedBy()); - - assertSourceContains("@OneToOne(mappedBy = \"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertEquals("foo", oneToOne.getMappedBy()); - - oneToOne.setMappedBy(null); - assertNull(oneToOne.getMappedBy()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeAll()); - - oneToOne.setCascadeAll(true); - assertSourceContains("@OneToOne(cascade = ALL)", cu); - - assertTrue(oneToOne.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(true); - assertSourceContains("@OneToOne(cascade = MERGE)", cu); - - assertTrue(oneToOne.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadePersist()); - - oneToOne.setCascadePersist(true); - assertSourceContains("@OneToOne(cascade = PERSIST)", cu); - - assertTrue(oneToOne.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeRemove()); - - oneToOne.setCascadeRemove(true); - assertSourceContains("@OneToOne(cascade = REMOVE)", cu); - - assertTrue(oneToOne.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeRefresh()); - - oneToOne.setCascadeRefresh(true); - assertSourceContains("@OneToOne(cascade = REFRESH)", cu); - - assertTrue(oneToOne.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeAll()); - - oneToOne.setCascadeAll(true); - assertTrue(oneToOne.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@OneToOne(cascade = CascadeType.ALL)", cu); - - oneToOne.setCascadeAll(false); - assertFalse(oneToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - oneToOne.setCascadeAll(false); - assertFalse(oneToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(false); - assertFalse(oneToOne.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeMerge()); - assertTrue(oneToOne.isCascadeRemove()); - - oneToOne.setCascadeMerge(false); - assertSourceContains("@OneToOne(cascade = REMOVE)", cu); - - oneToOne.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OrderByTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OrderByTests.java deleted file mode 100644 index 85e9495c62..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OrderByTests.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; - -@SuppressWarnings("nls") -public class OrderByTests extends JpaJavaResourceModelTestCase { - - public OrderByTests(String name) { - super(name); - } - - private ICompilationUnit createTestOrderBy() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ORDER_BY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderBy"); - } - }); - } - - private ICompilationUnit createTestOrderByWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ORDER_BY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderBy(value = \"key\")"); - } - }); - } - - public void testOrderBy() throws Exception { - ICompilationUnit cu = this.createTestOrderBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(JPA.ORDER_BY); - assertNotNull(orderBy); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestOrderByWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(JPA.ORDER_BY); - assertEquals("key", orderBy.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestOrderBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(JPA.ORDER_BY); - - orderBy.setValue("foo"); - - assertSourceContains("@OrderBy(\"foo\")", cu); - - orderBy.setValue(null); - - assertSourceContains("@OrderBy", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java deleted file mode 100644 index 0e150c8b65..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; - -@SuppressWarnings("nls") -public class PrimaryKeyJoinColumnTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public PrimaryKeyJoinColumnTests(String name) { - super(name); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(name = \"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithReferencedColumnName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(referencedColumnName = \"" + COLUMN_REFERENCED_COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@PrimaryKeyJoinColumn(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@PrimaryKeyJoinColumn(", cu); - } - - - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@PrimaryKeyJoinColumn(referencedColumnName = \"Foo\")", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn(", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@PrimaryKeyJoinColumn(columnDefinition = \"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn(", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java deleted file mode 100644 index f9afc1e078..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; - -@SuppressWarnings("nls") -public class PrimaryKeyJoinColumnsTests extends JpaJavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public PrimaryKeyJoinColumnsTests(String name) { - super(name); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn)"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(name = \"" + COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithReferencedColumnName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(referencedColumnName = \"" + COLUMN_REFERENCED_COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithColumnDefinition() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(columnDefinition = \"" + COLUMN_COLUMN_DEFINITION + "\"))"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getReferencedColumnName()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(name = \"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@PrimaryKeyJoinColumn(", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(referencedColumnName = \"Foo\"))", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn(", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(columnDefinition = \"Foo\"))", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn(", cu); - } - - - public void testAddPrimaryKeyJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"),@PrimaryKeyJoinColumn(name = \"FOO\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMNS)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS))); - } - public void testAddPrimaryKeyJoinColumnToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"),@PrimaryKeyJoinColumn(name = \"FOO\")})", cu); - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAZ"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name = \"BAZ\"),@PrimaryKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"), @PrimaryKeyJoinColumn(name = \"FOO\")})", cu); - - Iterator pkJoinColumns = attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - - assertNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMNS)); - assertEquals(3, CollectionTools.size(attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS))); - } - - public void testRemovePrimaryKeyJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"),@PrimaryKeyJoinColumn(name = \"FOO\")})", cu); - - attributeResource.removeAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - assertSourceContains("@PrimaryKeyJoinColumn(name = \"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\")", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/QueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/QueryHintTests.java deleted file mode 100644 index d94cda4571..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/QueryHintTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; - -@SuppressWarnings("nls") -public class QueryHintTests extends JpaJavaResourceModelTestCase { - - private static final String QUERY_HINT_NAME = "myHint"; - private static final String QUERY_HINT_VALUE = "myValue"; - - public QueryHintTests(String name) { - super(name); - } - - private ICompilationUnit createTestNamedQueryWithQueryHints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(hints = {@QueryHint(name = \"" + QUERY_HINT_NAME + "\", value = \"" + QUERY_HINT_VALUE + "\"), @QueryHint})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - QueryHintAnnotation queryHint = namedQuery.hints().next(); - assertEquals(QUERY_HINT_NAME, queryHint.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - QueryHintAnnotation queryHint = namedQuery.hints().next(); - assertEquals(QUERY_HINT_NAME, queryHint.getName()); - - queryHint.setName("foo"); - assertEquals("foo", queryHint.getName()); - - assertSourceContains("@QueryHint(name = \"foo\", value = \"" + QUERY_HINT_VALUE + "\")", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTableTests.java deleted file mode 100644 index d73d41adf3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTableTests.java +++ /dev/null @@ -1,436 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; - -@SuppressWarnings("nls") -public class SecondaryTableTests extends JpaJavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public SecondaryTableTests(String name) { - super(name); - } - - private ICompilationUnit createTestSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(name = \"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithSchema() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(schema = \"" + SCHEMA_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithCatalog() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(catalog = \"" + CATALOG_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithPkJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAR\"), @PrimaryKeyJoinColumn(name = \"FOO\"), @PrimaryKeyJoinColumn(name = \"BAZ\")})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertEquals(TABLE_NAME, table.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getName()); - assertNull(table.getCatalog()); - assertNull(table.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getName()); - - table.setName("Foo"); - assertEquals("Foo", table.getName()); - - assertSourceContains("@SecondaryTable(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals(TABLE_NAME, table.getName()); - - table.setName(null); - assertNull(table.getName()); - - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@SecondaryTable(catalog = \"Foo\")", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@SecondaryTable(schema = \"Foo\")", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint})", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.removeUniqueConstraint(1); - Iterator uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - assertSourceContains("@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.removeUniqueConstraint(0); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - assertSourceContains("@SecondaryTable(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"}))", cu); - - table.removeUniqueConstraint(0); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - - secondaryTable.moveUniqueConstraint(2, 0); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - assertSourceContains("@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - - secondaryTable.moveUniqueConstraint(0, 2); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - assertSourceContains("@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})})", cu); - } - - - public void testPkJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(0, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.addPkJoinColumn(0); - table.addPkJoinColumn(1); - - assertEquals(2, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, table.pkJoinColumnsSize()); - } - - public void testAddPkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - - table.addPkJoinColumn(0).setName("FOO"); - table.addPkJoinColumn(0); - table.addPkJoinColumn(0).setName("BAR");//test adding a pkJoinColumn in front of 2 other joinColumns - - assertEquals("BAR", table.pkJoinColumnAt(0).getName()); - assertNull(table.pkJoinColumnAt(1).getName()); - assertEquals("FOO", table.pkJoinColumnAt(2).getName()); - - assertEquals(3, table.pkJoinColumnsSize()); - assertSourceContains("@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAR\"),@PrimaryKeyJoinColumn, @PrimaryKeyJoinColumn(name = \"FOO\")})", cu); - } - - public void testRemovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.removePkJoinColumn(1); - assertSourceContains("@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAR\"), @PrimaryKeyJoinColumn(name = \"BAZ\")})", cu); - - table.removePkJoinColumn(0); - assertSourceContains("@SecondaryTable(pkJoinColumns = @PrimaryKeyJoinColumn(name = \"BAZ\"))", cu); - - - table.removePkJoinColumn(0); - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testMovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(2, 0); - assertSourceContains("@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"FOO\"), @PrimaryKeyJoinColumn(name = \"BAZ\"), @PrimaryKeyJoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\")})", cu); - } - - public void testMovePkJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(0, 2); - assertSourceContains("@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAZ\"), @PrimaryKeyJoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\"), @PrimaryKeyJoinColumn(name = \"FOO\")})", cu); - } - - public void testSetPkJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, table.pkJoinColumnsSize()); - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"foo\"), @PrimaryKeyJoinColumn(name = \"FOO\"), @PrimaryKeyJoinColumn(name = \"BAZ\")})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTablesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTablesTests.java deleted file mode 100644 index 0373502482..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTablesTests.java +++ /dev/null @@ -1,503 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; - -@SuppressWarnings("nls") -public class SecondaryTablesTests extends JpaJavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public SecondaryTablesTests(String name) { - super(name); - } - - private ICompilationUnit createTestSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable)"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(name = \"" + TABLE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithSchema() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(schema = \"" + SCHEMA_NAME + "\"))"); - } - }); - } - private ICompilationUnit createTestSecondaryTableWithCatalog() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(catalog = \"" + CATALOG_NAME + "\"))"); - } - }); - } - - - private ICompilationUnit createTestSecondaryTableWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint}))"); - } - }); - } - - private ICompilationUnit createTestSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@SecondaryTable(name = \"FOO\", catalog = \"BAR\", schema = \"BAZ\", uniqueConstraints = @UniqueConstraint(columnNames = {\"BAR\"}))"); - } - }); - } - - private ICompilationUnit createTestSecondaryTablesWithPkJoinColumns() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SECONDARY_TABLES, JPA.SECONDARY_TABLE, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAR\"), @PrimaryKeyJoinColumn(name = \"FOO\"), @PrimaryKeyJoinColumn(name = \"BAZ\")}))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNull(table); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - assertNotNull(secondaryTables); - - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertEquals(TABLE_NAME, secondaryTable.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertNull(secondaryTable.getName()); - assertNull(secondaryTable.getCatalog()); - assertNull(secondaryTable.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - - assertNull(secondaryTable.getName()); - - secondaryTable.setName("Foo"); - assertEquals("Foo", secondaryTable.getName()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(name = \"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertEquals(TABLE_NAME, secondaryTable.getName()); - - secondaryTable.setName(null); - assertNull(secondaryTable.getName()); - - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertEquals(CATALOG_NAME, secondaryTable.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertNull(secondaryTable.getCatalog()); - - secondaryTable.setCatalog("Foo"); - assertEquals("Foo", secondaryTable.getCatalog()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(catalog = \"Foo\"))", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertEquals(CATALOG_NAME, secondaryTable.getCatalog()); - - secondaryTable.setCatalog(null); - assertNull(secondaryTable.getCatalog()); - - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertNotNull(secondaryTable); - assertEquals(SCHEMA_NAME, secondaryTable.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertNull(secondaryTable.getSchema()); - - secondaryTable.setSchema("Foo"); - assertEquals("Foo", secondaryTable.getSchema()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(schema = \"Foo\"))", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - assertEquals(SCHEMA_NAME, secondaryTable.getSchema()); - - secondaryTable.setSchema(null); - assertNull(secondaryTable.getSchema()); - - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - - assertEquals(0, secondaryTable.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - - secondaryTable.addUniqueConstraint(0); - secondaryTable.addUniqueConstraint(1); - - assertEquals(2, secondaryTable.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - - assertEquals(2, secondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - secondaryTable.addUniqueConstraint(1); - secondaryTable.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, secondaryTable.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint}))", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - - secondaryTable.removeUniqueConstraint(2); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint(columnNames = {\"BAR\"})})", cu); - - secondaryTable.removeUniqueConstraint(0); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAR\"}))", cu); - - secondaryTable.removeUniqueConstraint(0); - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - - assertEquals("FOO", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertFalse(secondaryTable.uniqueConstraintAt(2).columnNames().hasNext()); - - secondaryTable.moveUniqueConstraint(2, 0); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertFalse(secondaryTable.uniqueConstraintAt(1).columnNames().hasNext()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint, @UniqueConstraint(columnNames = \"FOO\")}))", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.getNestedAnnotations().iterator().next(); - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - - assertEquals("FOO", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertFalse(secondaryTable.uniqueConstraintAt(2).columnNames().hasNext()); - - secondaryTable.moveUniqueConstraint(0, 2); - assertFalse(secondaryTable.uniqueConstraintAt(0).columnNames().hasNext()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints = {@UniqueConstraint, @UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint(columnNames = {\"BAR\"})}))", cu); - } - - - // @Entity -->> @Entity - // @SecondaryTable(name="FOO") @SecondaryTables({@SecondaryTable(name="FOO"), @SecondaryTable(name="BAR")}) - public void testAddSecondaryTableCopyExisting() throws Exception { - ICompilationUnit cu = createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\", schema = \"BAZ\", catalog = \"BAR\", uniqueConstraints = @UniqueConstraint(columnNames = \"BAR\")),@SecondaryTable(name = \"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testAddSecondaryTable() throws Exception { - ICompilationUnit cu = createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\", schema = \"BAZ\", catalog = \"BAR\", uniqueConstraints = @UniqueConstraint(columnNames = \"BAR\")),@SecondaryTable(name = \"BAR\")})", cu); - - secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"BAZ\"),@SecondaryTable(name = \"FOO\", schema = \"BAZ\", catalog = \"BAR\", uniqueConstraints = @UniqueConstraint(columnNames = \"BAR\")), @SecondaryTable(name = \"BAR\")})", cu); - - Iterator secondaryTables = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testRemoveSecondaryTableCopyExisting() throws Exception { - ICompilationUnit cu = createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name = \"FOO\", schema = \"BAZ\", catalog = \"BAR\", uniqueConstraints = @UniqueConstraint(columnNames = \"BAR\")),@SecondaryTable(name = \"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTable(name = \"FOO\", schema = \"BAZ\", catalog = \"BAR\", uniqueConstraints = @UniqueConstraint(columnNames = \"BAR\"))", cu); - } - - - public void testPkJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals(0, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - table.addPkJoinColumn(0); - table.addPkJoinColumn(1); - - assertEquals(2, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals(3, table.pkJoinColumnsSize()); - } - - public void testAddPkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - table.addPkJoinColumn(0).setName("FOO"); - table.addPkJoinColumn(1); - table.addPkJoinColumn(0).setName("BAR"); - - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAR\"),@PrimaryKeyJoinColumn(name = \"FOO\"), @PrimaryKeyJoinColumn}))", cu); - } - - public void testRemovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - table.removePkJoinColumn(1); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAR\"), @PrimaryKeyJoinColumn(name = \"BAZ\")}))", cu); - - table.removePkJoinColumn(0); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns = @PrimaryKeyJoinColumn(name = \"BAZ\")))", cu); - - table.removePkJoinColumn(0); - assertSourceDoesNotContain("@SecondaryTable(", cu); - } - - public void testMovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(2, 0); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"FOO\"), @PrimaryKeyJoinColumn(name = \"BAZ\"), @PrimaryKeyJoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\")}))", cu); - } - - public void testMovePkJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(0, 2); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"BAZ\"), @PrimaryKeyJoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\"), @PrimaryKeyJoinColumn(name = \"FOO\")}))", cu); - } - - public void testSetPkJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals(3, table.pkJoinColumnsSize()); - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns = {@PrimaryKeyJoinColumn(name = \"foo\"), @PrimaryKeyJoinColumn(name = \"FOO\"), @PrimaryKeyJoinColumn(name = \"BAZ\")}))", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SequenceGeneratorTests.java deleted file mode 100644 index 407f54a108..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SequenceGeneratorTests.java +++ /dev/null @@ -1,234 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; - -@SuppressWarnings("nls") -public class SequenceGeneratorTests extends JpaJavaResourceModelTestCase { - - private static final String GENERATOR_NAME = "MY_GENERATOR"; - private static final String GENERATOR_SEQUENCE_NAME = "MY_SEQUENCE"; - private static final Integer GENERATOR_ALLOCATION_SIZE = Integer.valueOf(5); - private static final Integer GENERATOR_INITIAL_VALUE = Integer.valueOf(5); - - public SequenceGeneratorTests(String name) { - super(name); - } - - private ICompilationUnit createTestSequenceGeneratorOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator"); - } - }); - } - - private ICompilationUnit createTestSequenceGeneratorOnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator"); - } - }); - } - - private ICompilationUnit createTestSequenceGeneratorWithName() throws Exception { - return createTestSequenceGeneratorWithStringElement("name", GENERATOR_NAME); - } - - private ICompilationUnit createTestSequenceGeneratorWithSequenceName() throws Exception { - return createTestSequenceGeneratorWithStringElement("sequenceName", GENERATOR_SEQUENCE_NAME); - } - - protected ICompilationUnit createTestSequenceGeneratorWithStringElement(final String elementName, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator(" + elementName + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestSequenceGeneratorWithAllocationSize() throws Exception { - return createTestSequenceGeneratorWithIntElement("allocationSize", GENERATOR_ALLOCATION_SIZE.intValue()); - } - - private ICompilationUnit createTestSequenceGeneratorWithInitialValue() throws Exception { - return createTestSequenceGeneratorWithIntElement("initialValue", GENERATOR_INITIAL_VALUE.intValue()); - } - - private ICompilationUnit createTestSequenceGeneratorWithIntElement(final String elementName, final int value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator(" + elementName + " = " + value + ")"); - } - }); - } - - public void testSequenceGeneratorOnField() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertNotNull(sequenceGenerator); - } - - public void testSequenceGeneratorOnType() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertNotNull(sequenceGenerator); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_NAME, sequenceGenerator.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_NAME, sequenceGenerator.getName()); - - sequenceGenerator.setName("foo"); - assertEquals("foo", sequenceGenerator.getName()); - - assertSourceContains("@SequenceGenerator(name = \"foo\")", cu); - - sequenceGenerator.setName(null); - assertNull(sequenceGenerator.getName()); - - assertSourceDoesNotContain("@SequenceGenerator(", cu); - } - - public void testGetSequenceName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithSequenceName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_SEQUENCE_NAME, sequenceGenerator.getSequenceName()); - } - - public void testSetSequenceName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithSequenceName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_SEQUENCE_NAME, sequenceGenerator.getSequenceName()); - - sequenceGenerator.setSequenceName("foo"); - assertEquals("foo", sequenceGenerator.getSequenceName()); - - assertSourceContains("@SequenceGenerator(sequenceName = \"foo\")", cu); - - sequenceGenerator.setSequenceName(null); - assertNull(sequenceGenerator.getSequenceName()); - - assertSourceDoesNotContain("@SequenceGenerator(", cu); - } - - public void testGetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, sequenceGenerator.getAllocationSize()); - } - - public void testSetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, sequenceGenerator.getAllocationSize()); - - sequenceGenerator.setAllocationSize(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), sequenceGenerator.getAllocationSize()); - - assertSourceContains("@SequenceGenerator(allocationSize = 500)", cu); - - sequenceGenerator.setAllocationSize(null); - - assertSourceDoesNotContain("@SequenceGenerator(", cu); - - sequenceGenerator.setAllocationSize(Integer.valueOf(0)); - assertSourceContains("@SequenceGenerator(allocationSize = 0)", cu); - } - - public void testGetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, sequenceGenerator.getInitialValue()); - } - - public void testSetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, sequenceGenerator.getInitialValue()); - - sequenceGenerator.setInitialValue(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), sequenceGenerator.getInitialValue()); - - assertSourceContains("@SequenceGenerator(initialValue = 500)", cu); - - sequenceGenerator.setInitialValue(null); - - assertSourceDoesNotContain("@SequenceGenerator(", cu); - - sequenceGenerator.setInitialValue(Integer.valueOf(0)); - assertSourceContains("@SequenceGenerator(initialValue = 0)", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableGeneratorTests.java deleted file mode 100644 index 369cd42ceb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableGeneratorTests.java +++ /dev/null @@ -1,501 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; - -@SuppressWarnings("nls") -public class TableGeneratorTests extends JpaJavaResourceModelTestCase { - - private static final String GENERATOR_NAME = "MY_GENERATOR"; - private static final String GENERATOR_TABLE = "MY_TABLE"; - private static final String GENERATOR_CATALOG = "MY_CATALOG"; - private static final String GENERATOR_SCHEMA = "MY_SCHEMA"; - private static final String GENERATOR_PK_COLUMN_NAME = "MY_PK_COLUMN_NAME"; - private static final String GENERATOR_VALUE_COLUMN_NAME = "MY_VALUE_COLUMN_NAME"; - private static final String GENERATOR_PK_COLUMN_VALUE = "MY_PK_COLUMN_VALUE"; - private static final Integer GENERATOR_ALLOCATION_SIZE = Integer.valueOf(5); - private static final Integer GENERATOR_INITIAL_VALUE = Integer.valueOf(5); - - public TableGeneratorTests(String name) { - super(name); - } - - private ICompilationUnit createTestTableGeneratorOnField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorOnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE_GENERATOR); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorWithName() throws Exception { - return createTestTableGeneratorWithStringElement("name", GENERATOR_NAME); - } - - private ICompilationUnit createTestTableGeneratorWithTable() throws Exception { - return createTestTableGeneratorWithStringElement("table", GENERATOR_TABLE); - } - - private ICompilationUnit createTestTableGeneratorWithCatalog() throws Exception { - return createTestTableGeneratorWithStringElement("catalog", GENERATOR_CATALOG); - } - - private ICompilationUnit createTestTableGeneratorWithSchema() throws Exception { - return createTestTableGeneratorWithStringElement("schema", GENERATOR_SCHEMA); - } - private ICompilationUnit createTestTableGeneratorWithPkColumnName() throws Exception { - return createTestTableGeneratorWithStringElement("pkColumnName", GENERATOR_PK_COLUMN_NAME); - } - - private ICompilationUnit createTestTableGeneratorWithValueColumnName() throws Exception { - return createTestTableGeneratorWithStringElement("valueColumnName", GENERATOR_VALUE_COLUMN_NAME); - } - - private ICompilationUnit createTestTableGeneratorWithPkColumnValue() throws Exception { - return createTestTableGeneratorWithStringElement("pkColumnValue", GENERATOR_PK_COLUMN_VALUE); - } - - private ICompilationUnit createTestTableGeneratorWithStringElement(final String elementName, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator(" + elementName + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorWithAllocationSize() throws Exception { - return createTestTableGeneratorWithIntElement("allocationSize", GENERATOR_ALLOCATION_SIZE.intValue()); - } - - private ICompilationUnit createTestTableGeneratorWithInitialValue() throws Exception { - return createTestTableGeneratorWithIntElement("initialValue", GENERATOR_INITIAL_VALUE.intValue()); - } - - private ICompilationUnit createTestTableGeneratorWithIntElement(final String elementName, final int value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator(" + elementName + " = " + value + ")"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE_GENERATOR, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})"); - } - }); - } - - public void testTableGeneratorOnField() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertNotNull(tableGenerator); - } - - public void testTableGeneratorOnType() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) typeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertNotNull(tableGenerator); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_NAME, tableGenerator.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_NAME, tableGenerator.getName()); - - tableGenerator.setName("foo"); - assertEquals("foo", tableGenerator.getName()); - - assertSourceContains("@TableGenerator(name = \"foo\")", cu); - - tableGenerator.setName(null); - assertNull(tableGenerator.getName()); - - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_TABLE, tableGenerator.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_TABLE, tableGenerator.getTable()); - - tableGenerator.setTable("foo"); - assertEquals("foo", tableGenerator.getTable()); - - assertSourceContains("@TableGenerator(table = \"foo\")", cu); - - tableGenerator.setTable(null); - assertNull(tableGenerator.getTable()); - - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_CATALOG, tableGenerator.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_CATALOG, tableGenerator.getCatalog()); - - tableGenerator.setCatalog("foo"); - assertEquals("foo", tableGenerator.getCatalog()); - - assertSourceContains("@TableGenerator(catalog = \"foo\")", cu); - - tableGenerator.setCatalog(null); - assertNull(tableGenerator.getCatalog()); - - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_SCHEMA, tableGenerator.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_SCHEMA, tableGenerator.getSchema()); - - tableGenerator.setSchema("foo"); - assertEquals("foo", tableGenerator.getSchema()); - - assertSourceContains("@TableGenerator(schema = \"foo\")", cu); - - tableGenerator.setSchema(null); - assertNull(tableGenerator.getSchema()); - - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testGetPkColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_NAME, tableGenerator.getPkColumnName()); - } - - public void testSetPkColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_NAME, tableGenerator.getPkColumnName()); - - tableGenerator.setPkColumnName("foo"); - assertEquals("foo", tableGenerator.getPkColumnName()); - - assertSourceContains("@TableGenerator(pkColumnName = \"foo\")", cu); - - tableGenerator.setPkColumnName(null); - assertNull(tableGenerator.getPkColumnName()); - - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testGetValueColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithValueColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_VALUE_COLUMN_NAME, tableGenerator.getValueColumnName()); - } - - public void testSetValueColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithValueColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_VALUE_COLUMN_NAME, tableGenerator.getValueColumnName()); - - tableGenerator.setValueColumnName("foo"); - assertEquals("foo", tableGenerator.getValueColumnName()); - - assertSourceContains("@TableGenerator(valueColumnName = \"foo\")", cu); - - tableGenerator.setValueColumnName(null); - assertNull(tableGenerator.getValueColumnName()); - - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testGetPkColumnValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_VALUE, tableGenerator.getPkColumnValue()); - } - - public void testSetPkColumnValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_VALUE, tableGenerator.getPkColumnValue()); - - tableGenerator.setPkColumnValue("foo"); - assertEquals("foo", tableGenerator.getPkColumnValue()); - - assertSourceContains("@TableGenerator(pkColumnValue = \"foo\")", cu); - - tableGenerator.setPkColumnValue(null); - assertNull(tableGenerator.getPkColumnValue()); - - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testGetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, tableGenerator.getAllocationSize()); - } - - public void testSetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, tableGenerator.getAllocationSize()); - - tableGenerator.setAllocationSize(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), tableGenerator.getAllocationSize()); - - assertSourceContains("@TableGenerator(allocationSize = 500)", cu); - - tableGenerator.setAllocationSize(null); - - assertSourceDoesNotContain("@TableGenerator(", cu); - - tableGenerator.setAllocationSize(Integer.valueOf(0)); - assertSourceContains("@TableGenerator(allocationSize = 0)", cu); - } - - public void testGetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, tableGenerator.getInitialValue()); - } - - public void testSetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, tableGenerator.getInitialValue()); - - tableGenerator.setInitialValue(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), tableGenerator.getInitialValue()); - - assertSourceContains("@TableGenerator(initialValue = 500)", cu); - - tableGenerator.setInitialValue(null); - - assertSourceDoesNotContain("@TableGenerator(", cu); - - tableGenerator.setInitialValue(Integer.valueOf(0)); - assertSourceContains("@TableGenerator(initialValue = 0)", cu); - } - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(0, tableGenerator.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.addUniqueConstraint(0); - tableGenerator.addUniqueConstraint(1); - - assertEquals(2, tableGenerator.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGenerator.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.addUniqueConstraint(0).addColumnName("FOO"); - tableGenerator.addUniqueConstraint(1); - tableGenerator.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", tableGenerator.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", tableGenerator.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, tableGenerator.uniqueConstraintAt(2).columnNamesSize()); - - assertEquals(3, tableGenerator.uniqueConstraintsSize()); - assertSourceContains("@TableGenerator(uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint})", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.removeUniqueConstraint(1); - assertSourceContains("@TableGenerator(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - tableGenerator.removeUniqueConstraint(0); - assertSourceContains("@TableGenerator(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"}))", cu); - - tableGenerator.removeUniqueConstraint(0); - assertSourceDoesNotContain("@TableGenerator(", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.moveUniqueConstraint(2, 0); - assertSourceContains("@TableGenerator(uniqueConstraints = {@UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.moveUniqueConstraint(0, 2); - assertSourceContains("@TableGenerator(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableTests.java deleted file mode 100644 index bfacfd0189..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableTests.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableAnnotation; - -@SuppressWarnings("nls") -public class TableTests extends JpaJavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public TableTests(String name) { - super(name); - } - - private ICompilationUnit createTestTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table"); - } - }); - } - - private ICompilationUnit createTestTableWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(name = \"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestTableWithSchema() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(schema = \"" + SCHEMA_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestTableWithCatalog() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(catalog = \"" + CATALOG_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestTableWithUniqueConstraints() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertEquals(TABLE_NAME, table.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getName()); - assertNull(table.getCatalog()); - assertNull(table.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getName()); - - table.setName("Foo"); - assertEquals("Foo", table.getName()); - - assertSourceContains("@Table(name = \"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals(TABLE_NAME, table.getName()); - - table.setName(null); - assertNull(table.getName()); - - assertSourceDoesNotContain("@Table(", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@Table(catalog = \"Foo\")", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@Table(", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@Table(schema = \"Foo\")", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@Table(", cu); - } - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint})", cu); - } - - public void testAddUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(0); - table.addUniqueConstraint(1).addColumnName("BAR"); - table.uniqueConstraintAt(1).addColumnName("BAZ"); - - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint,@UniqueConstraint(columnNames = { \"BAR\", \"BAZ\" }), @UniqueConstraint(columnNames = \"FOO\")})", cu); - - assertEquals("FOO", table.uniqueConstraintAt(2).columnNames().next()); - ListIterator columnNames = table.uniqueConstraintAt(1).columnNames(); - assertEquals("BAR", columnNames.next()); - assertEquals("BAZ", columnNames.next()); - } - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.removeUniqueConstraint(1); - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})})", cu); - - table.removeUniqueConstraint(0); - assertSourceContains("@Table(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"}))", cu); - - table.removeUniqueConstraint(0); - assertSourceDoesNotContain("@Table(", cu); - } - - public void testRemoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1).addColumnName("BAR"); - table.addUniqueConstraint(2).addColumnName("BAZ"); - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = \"FOO\"),@UniqueConstraint(columnNames = \"BAR\"), @UniqueConstraint(columnNames = \"BAZ\")})", cu); - - table.removeUniqueConstraint(0); - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"BAZ\")})", cu); - - table.removeUniqueConstraint(0); - assertSourceContains("@Table(uniqueConstraints = @UniqueConstraint(columnNames = \"BAZ\"))", cu); - - table.removeUniqueConstraint(0); - assertSourceDoesNotContain("@Table(", cu); - } - - public void testRemoveUniqueConstraint3() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1).addColumnName("BAR"); - table.addUniqueConstraint(2).addColumnName("BAZ"); - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = \"FOO\"),@UniqueConstraint(columnNames = \"BAR\"), @UniqueConstraint(columnNames = \"BAZ\")})", cu); - - table.removeUniqueConstraint(2); - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = \"FOO\"),@UniqueConstraint(columnNames = \"BAR\")})", cu); - - table.removeUniqueConstraint(1); - assertSourceContains("@Table(uniqueConstraints = @UniqueConstraint(columnNames = \"FOO\"))", cu); - - table.removeUniqueConstraint(0); - assertSourceDoesNotContain("@Table(", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.moveUniqueConstraint(2, 0); - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.moveUniqueConstraint(0, 2); - assertSourceContains("@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TemporalTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TemporalTests.java deleted file mode 100644 index 544836bac8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TemporalTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalType; - -@SuppressWarnings("nls") -public class TemporalTests extends JpaJavaResourceModelTestCase { - - public TemporalTests(String name) { - super(name); - } - - private ICompilationUnit createTestTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TEMPORAL); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Temporal"); - } - }); - } - - private ICompilationUnit createTestTemporalWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Temporal(TemporalType.DATE)"); - } - }); - } - - public void testTemporal() throws Exception { - ICompilationUnit cu = this.createTestTemporal(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(JPA.TEMPORAL); - assertNotNull(temporal); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestTemporalWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(JPA.TEMPORAL); - assertEquals(TemporalType.DATE, temporal.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestTemporal(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(JPA.TEMPORAL); - - temporal.setValue(TemporalType.TIME); - - assertSourceContains("@Temporal(TIME)", cu); - - temporal.setValue(null); - - assertSourceDoesNotContain("@Temporal(", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TransientTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TransientTests.java deleted file mode 100644 index 84f92463f9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TransientTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; - -@SuppressWarnings("nls") -public class TransientTests extends JpaJavaResourceModelTestCase { - - public TransientTests(String name) { - super(name); - } - - private ICompilationUnit createTestTransient() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.TRANSIENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient"); - } - }); - } - - public void testTransient() throws Exception { - ICompilationUnit cu = this.createTestTransient(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof TransientAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/VersionTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/VersionTests.java deleted file mode 100644 index 8e6ef74311..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/VersionTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; - -@SuppressWarnings("nls") -public class VersionTests extends JpaJavaResourceModelTestCase { - - public VersionTests(String name) { - super(name); - } - - private ICompilationUnit createTestVersion() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.VERSION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version"); - } - }); - } - - public void testVersion() throws Exception { - ICompilationUnit cu = this.createTestVersion(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME); - assertTrue(mappingAnnotation instanceof VersionAnnotation); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/test.xml b/jpa/tests/org.eclipse.jpt.core.tests/test.xml deleted file mode 100644 index 71ce1f7d89..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/test.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.classpath b/jpa/tests/org.eclipse.jpt.db.tests/.classpath deleted file mode 100644 index ef8d91ca94..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.classpath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.cvsignore b/jpa/tests/org.eclipse.jpt.db.tests/.cvsignore deleted file mode 100644 index ba077a4031..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.project b/jpa/tests/org.eclipse.jpt.db.tests/.project index f5b0127a1e..a1ffb1d2c4 100644 --- a/jpa/tests/org.eclipse.jpt.db.tests/.project +++ b/jpa/tests/org.eclipse.jpt.db.tests/.project @@ -1,28 +1,5 @@ org.eclipse.jpt.db.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - + renamed to org.eclipse.jpt.jpa.db.tests + \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index b23d0c7038..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Jan 15 11:11:11 EST 2008 -eclipse.preferences.version=1 -encoding/=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.jdt.core.prefs b/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 929d54536d..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Sun May 27 14:59:18 EDT 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/tests/org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF deleted file mode 100644 index a99c8e4bfd..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,19 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.db.tests -Bundle-Version: 1.0.200.qualifier -Bundle-Activator: org.eclipse.jpt.db.tests.internal.JptDbTestsPlugin -Bundle-ActivationPolicy: lazy -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.datatools.connectivity;bundle-version="[1.1.0,1.3.0)", - org.eclipse.datatools.connectivity.sqm.core;bundle-version="1.0.1", - org.eclipse.datatools.modelbase.sql;bundle-version="1.0.0", - org.eclipse.jpt.utility;bundle-version="[1.2.0,2.0.0)", - org.eclipse.jpt.db;bundle-version="[1.2.0,2.0.0)", - org.junit;bundle-version="3.8.0" -Export-Package: org.eclipse.jpt.db.tests.internal;x-internal:=true, - org.eclipse.jpt.db.tests.internal.platforms;x-internal:=true diff --git a/jpa/tests/org.eclipse.jpt.db.tests/about.html b/jpa/tests/org.eclipse.jpt.db.tests/about.html deleted file mode 100644 index be534ba44f..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/about.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - -About - - - - - -

About This Content

- -

May 02, 2008

- -

License

- -

The Eclipse Foundation makes available all content in this plug-in -("Content"). Unless otherwise indicated below, the Content is provided to you -under the terms and conditions of the Eclipse Public License Version 1.0 -("EPL"). A copy of the EPL is available at -http://www.eclipse.org/org/documents/epl-v10.php. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the -Content is being redistributed by another party ("Redistributor") and different -terms and conditions may apply to your use of any object code in the Content. -Check the Redistributor's license that was provided with the Content. If no such -license exists, contact the Redistributor. Unless otherwise indicated below, the -terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at -http://www.eclipse.org/.

- - - diff --git a/jpa/tests/org.eclipse.jpt.db.tests/build.properties b/jpa/tests/org.eclipse.jpt.db.tests/build.properties deleted file mode 100644 index d27ab8f407..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/build.properties +++ /dev/null @@ -1,14 +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 -################################################################################ -source.. = src/ -output.. = bin/ -bin.includes = .,\ - META-INF/,\ - plugin.properties diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/derby.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/derby.properties deleted file mode 100644 index 242d156070..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/derby.properties +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional for Derby -userID = -password = - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/derby/lib/derby.jar -jars = - -# the JDBC URL is required for Derby -# url = jdbc:derby:C:/derby/data/testdb;create=true -url = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/mysql.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/mysql.properties deleted file mode 100644 index d6407deb25..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/mysql.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional, depending on the platform -userID = -password = - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/mysql/mysql-connector-java-5.0.6-bin.jar -jars = - -# the JDBC URL is optional for MySQL -# url = jdbc:mysql://localhost:3306 diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10g.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10g.properties deleted file mode 100644 index 4b911b44e1..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10g.properties +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional, depending on the platform -userID = scott -password = tiger - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/oracle/jdbc/lib/ojdbc5.jar -jars = - -# the JDBC URL is required -# url = jdbc:oracle:thin:@localhost:1521:testdb -url = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10gXE.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10gXE.properties deleted file mode 100644 index e67c01a28e..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10gXE.properties +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional, depending on the platform -userID = scott -password = tiger - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/oracle/jdbc/lib/ojdbc5.jar -jars = - -# the JDBC URL is required -# url = jdbc:oracle:thin:@localhost:1521:XE -url = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle9i.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/oracle9i.properties deleted file mode 100644 index 4b911b44e1..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle9i.properties +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional, depending on the platform -userID = scott -password = tiger - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/oracle/jdbc/lib/ojdbc5.jar -jars = - -# the JDBC URL is required -# url = jdbc:oracle:thin:@localhost:1521:testdb -url = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/postgresql.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/postgresql.properties deleted file mode 100644 index 32fafe463b..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/postgresql.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional, depending on the platform -userID = -password = - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/postgresql/jdbc/postgresql-8.2-505.jdbc3.jar -jars = - -# the JDBC URL is optional for PostgreSQL -# url = jdbc:postgresql diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/sqlserver.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/sqlserver.properties deleted file mode 100644 index f72b645c52..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/sqlserver.properties +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional, depending on the platform -userID = -password = - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/sqlserver/lib/sqljdbc.jar -jars = - -# the JDBC URL is required -# url = jdbc:sqlserver://localhost:1433 -url = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/sybase.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/sybase.properties deleted file mode 100644 index 493d5d4ad9..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/sybase.properties +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ - -# Configure the workspace- and database server-specific settings here. - -# user and password are optional, depending on the platform -userID = -password = - -# the JDBC driver JAR(s) must be specified; -# if there are multiple JARs, separate the names with commas -# jars = C:/sybase/lib/jconn3.jar -jars = - -# the JDBC URL is required -# url = jdbc:sybase:Tds:localhost:5000 -url = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.db.tests/plugin.properties deleted file mode 100644 index 2c98779595..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/plugin.properties +++ /dev/null @@ -1,24 +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 -################################################################################ -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName = JPA DB Tests -providerName = Eclipse.org - diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTests.java deleted file mode 100644 index ce05d768f8..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTests.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.db.tests.internal; - -import java.sql.Connection; -import java.sql.DriverManager; - -import junit.framework.TestCase; - -/** - * These aren't tests. They are just an easy way to dump JDBC metadata to the - * console. - */ -@SuppressWarnings("nls") -public class JDBCTests extends TestCase { - - public JDBCTests(String name) { - super(name); - } - - public void testDerby() throws Exception { - this.dumpMetaData(DERBY); - } - - public void testMySQL() throws Exception { - this.dumpMetaData(MYSQL); - } - - public void testOracle() throws Exception { - this.dumpMetaData(ORACLE); - } - - public void testPostgreSQL() throws Exception { - this.dumpMetaData(POSTGRESQL); - } - - public void testSybase() throws Exception { - this.dumpMetaData(SYBASE); - } - - protected void dumpMetaData(ConnectionConfig config) throws Exception { - System.out.println("***** PLATFORM: " + config.platformName + " *****"); - System.out.println(); - Class.forName(config.driverClassName); - Connection connection = DriverManager.getConnection(this.buildURL(config), config.user, config.password); - System.out.println("CATALOGS:"); - JDBCTools.dump(connection.getMetaData().getCatalogs()); - System.out.println(); - System.out.println("SCHEMATA:"); - JDBCTools.dump(connection.getMetaData().getSchemas()); - connection.close(); - System.out.println(); - } - - protected String buildURL(ConnectionConfig config) { - return "jdbc:" + config.databaseURL; - } - - protected static final ConnectionConfig DERBY = - new ConnectionConfig( - "Derby", - "org.apache.derby.jdbc.EmbeddedDriver", - "derby:C:/derby/data/test", - null, - null - ); - - protected static final ConnectionConfig MYSQL = - new ConnectionConfig( - "MySQL", - "com.mysql.jdbc.Driver", - "mysql://localhost:3306", - "root", - "oracle" - ); - - protected static final ConnectionConfig ORACLE = - new ConnectionConfig( - "Oracle", - "oracle.jdbc.OracleDriver", - "oracle:thin:@localhost:1521:orcl", - "scott", - "tiger" - ); - - protected static final ConnectionConfig POSTGRESQL = - new ConnectionConfig( - "PostgreSQL", - "org.postgresql.Driver", - "postgresql:postgres", - "postgres", - "oracle" - ); - - // the Sybase server must be configured explicitly to "localhost" - // in the config file [SYBASE]/ini/sql.ini - protected static final ConnectionConfig SYBASE = - new ConnectionConfig( - "Sybase", - "com.sybase.jdbc3.jdbc.SybDriver", - "sybase:Tds:localhost:5000", - "sa", - "oracle" - ); - - protected static class ConnectionConfig { - protected final String platformName; - protected final String driverClassName; - protected final String databaseURL; - protected final String user; - protected final String password; - protected ConnectionConfig( - String platformName, - String driverClassName, - String databaseURL, - String user, - String password - ) { - super(); - this.platformName = platformName; - this.driverClassName = driverClassName; - this.databaseURL = databaseURL; - this.user = user; - this.password = password; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTools.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTools.java deleted file mode 100644 index 57c98feafb..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JDBCTools.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.db.tests.internal; - -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.jpt.utility.internal.iterators.ResultSetIterator; - -@SuppressWarnings("nls") -public class JDBCTools { - - public static void dump(Connection connection, String sql) throws SQLException { - dump(execute(connection, sql)); - } - - public static void dump(ResultSet resultSet) throws SQLException { - PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); - // synchronize the console so everything is contiguous - synchronized (System.out) { - dumpOn(resultSet, pw); - } - pw.flush(); - } - - public static void dumpOn(ResultSet resultSet, PrintWriter pw) throws SQLException { - ArrayList> maps = convertToMaps(resultSet); - for (Iterator> mapStream = maps.iterator(); mapStream.hasNext(); ) { - for (Iterator> entryStream = mapStream.next().entrySet().iterator(); entryStream.hasNext(); ) { - Map.Entry entry = entryStream.next(); - pw.print(entry.getKey()); - pw.print(" = "); - pw.print(entry.getValue()); - pw.println(); - } - if (mapStream.hasNext()) { - pw.println(); - } - } - pw.println("total rows: " + maps.size()); - } - - public static ArrayList> convertToMaps(Connection connection, String sql) throws SQLException { - return convertToMaps(execute(connection, sql)); - } - - public static ResultSet execute(Connection connection, String sql) throws SQLException { - Statement statement = connection.createStatement(); - statement.execute(sql); - ResultSet resultSet = statement.getResultSet(); - statement.close(); - return resultSet; - } - - public static ArrayList> convertToMaps(ResultSet resultSet) throws SQLException { - ArrayList> rows = new ArrayList>(); - for (Iterator> stream = buildMapIterator(resultSet); stream.hasNext(); ) { - rows.add(stream.next()); - } - return rows; - } - - public static Iterator> buildMapIterator(ResultSet resultSet) throws SQLException { - return new ResultSetIterator>(resultSet, new MapResultSetIteratorAdapter(buildColumnNames(resultSet))); - } - - public static String[] buildColumnNames(ResultSet resultSet) throws SQLException { - String[] names = new String[resultSet.getMetaData().getColumnCount()]; - for (int i = 0; i < names.length; i++) { - names[i] = resultSet.getMetaData().getColumnName(i + 1); // NB: ResultSet index/subscript is 1-based - } - return names; - } - - public static class MapResultSetIteratorAdapter implements ResultSetIterator.Adapter> { - private final String[] columnNames; - public MapResultSetIteratorAdapter(String[] columnNames) { - super(); - this.columnNames = columnNames; - } - public HashMap buildNext(ResultSet rs) throws SQLException { - HashMap map = new HashMap(this.columnNames.length); - for (int i = 0; i < this.columnNames.length; i++) { - map.put(this.columnNames[i], rs.getObject(i + 1)); // NB: ResultSet index/subscript is 1-based - } - return map; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTests.java deleted file mode 100644 index ea34d083f6..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 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.db.tests.internal; - -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.db.tests.internal.platforms.AllPlatformTests; - -/** - * JPT DB Tests - */ -public class JptDbTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptDbTests.class.getPackage().getName()); - - suite.addTest( AllPlatformTests.suite()); - - return suite; - } - - private JptDbTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTestsPlugin.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTestsPlugin.java deleted file mode 100644 index 6d517b5635..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTestsPlugin.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.db.tests.internal; - -import org.eclipse.core.runtime.Plugin; -import org.osgi.framework.BundleContext; - -/** - * JptDbTestsPlugin - */ -public class JptDbTestsPlugin extends Plugin { - - // The shared instance - private static JptDbTestsPlugin INSTANCE; - - public static final String BUNDLE_ID = "org.eclipse.jpt.db.tests"; //$NON-NLS-1$ - - /** - * Returns the shared instance - */ - public static JptDbTestsPlugin instance() { - return INSTANCE; - } - - /** - * The constructor - */ - public JptDbTestsPlugin() { - super(); - INSTANCE = this; - } - - /** - * This method is called upon plug-in activation - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - } - - /** - * This method is called when the plug-in is stopped - */ - @Override - public void stop(BundleContext context) throws Exception { - INSTANCE = null; - super.stop(context); - } -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/AllPlatformTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/AllPlatformTests.java deleted file mode 100644 index 22ece7e151..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/AllPlatformTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 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.db.tests.internal.platforms; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class AllPlatformTests { - - public static Test suite() { - TestSuite suite = new TestSuite(AllPlatformTests.class.getPackage().getName()); - - suite.addTestSuite(DerbyTests.class); - suite.addTestSuite(MySQLTests.class); - suite.addTestSuite(Oracle10gTests.class); -// suite.addTestSuite(Oracle10gXETests.class); -// suite.addTestSuite(Oracle9iTests.class); - suite.addTestSuite(PostgreSQLTests.class); -// suite.addTestSuite(SQLServerTests.class); - suite.addTestSuite(SybaseTests.class); - - return suite; - } - - private AllPlatformTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java deleted file mode 100644 index ba1caf6258..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java +++ /dev/null @@ -1,1027 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.db.tests.internal.platforms; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.net.URL; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.datatools.connectivity.ConnectionProfileException; -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.IManagedConnection; -import org.eclipse.datatools.connectivity.ProfileManager; -import org.eclipse.datatools.connectivity.drivers.IDriverMgmtConstants; -import org.eclipse.datatools.connectivity.drivers.IPropertySet; -import org.eclipse.datatools.connectivity.drivers.PropertySetImpl; -import org.eclipse.datatools.connectivity.drivers.XMLFileManager; -import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; -import org.eclipse.datatools.connectivity.internal.ConnectivityPlugin; -import org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionInfo; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ConnectionListener; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.ConnectionProfileFactory; -import org.eclipse.jpt.db.ConnectionProfileListener; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.DatabaseIdentifierAdapter; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.db.Sequence; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.db.ForeignKey.ColumnPair; -import org.eclipse.jpt.db.tests.internal.JptDbTestsPlugin; -import org.eclipse.jpt.utility.IndentingPrintWriter; -import org.eclipse.jpt.utility.internal.ReflectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ResultSetIterator; - -/** - * Base class for testing DTP wrappers on various databases. - */ -@SuppressWarnings("nls") -public abstract class DTPPlatformTests extends TestCase { - - /** - * The platform properties are loaded from a Java properties file in the - * 'org.eclipse.jpt.db.tests/config' directory. Each database platform has - * its own properties file (e.g. 'derby.properties'). - */ - private Properties platformProperties; - - /** - * This is the Dali connection profile wrapper. - */ - protected ConnectionProfile connectionProfile; - - - // ********** constants ********** - - private static final String PLATFORM_CONFIG_DIRECTORY = "config"; - - private static final String DB_USER_ID_PROPERTY = "userID"; - private static final String DB_USER_ID_DEFAULT = "user"; - - private static final String DB_PASSWORD_PROPERTY = "password"; - private static final String DB_PASSWORD_DEFAULT = ""; - - private static final String DB_DRIVER_JARS_PROPERTY = "jars"; - // required - no default - - private static final String DB_URL_PROPERTY = "url"; - // required - no default - - - - // ********** constructor ********** - - protected DTPPlatformTests(String name) { - super(name); - } - - - // ********** set-up/tear-down ********** - - @Override - protected void setUp() throws Exception { - super.setUp(); - - this.platformProperties = this.loadPlatformProperties(); - this.buildDTPDriverDefinitionFile(); - this.buildDTPConnectionProfile(); - this.connectionProfile = this.getConnectionProfileFactory().buildConnectionProfile(this.getProfileName(), DatabaseIdentifierAdapter.Default.instance()); - } - - @Override - protected void tearDown() throws Exception { - this.connectionProfile = null; - this.platformProperties = null; - - super.tearDown(); - } - - // ***** platform properties file - private Properties loadPlatformProperties() throws IOException { - Properties p = new Properties(); - p.load(this.buildPlatformPropertiesFileURL().openStream()); - return p; - } - - private URL buildPlatformPropertiesFileURL() { - return Platform.getBundle(this.getTestPluginBundleID()).getEntry(this.getPlatformPropertiesFilePath()); - } - - private String getTestPluginBundleID() { - return JptDbTestsPlugin.BUNDLE_ID; - } - - private String getPlatformPropertiesFilePath() { - return this.getPlatformPropertiesDirectoryName() + '/' + this.getPlatformPropertiesFileName(); - } - - private String getPlatformPropertiesDirectoryName() { - return PLATFORM_CONFIG_DIRECTORY; - } - - /** - * Each database platform has a separate properties file in the 'config' - * directory that must be customized by whomever is executing the tests. - */ - protected abstract String getPlatformPropertiesFileName(); - - // ***** driver definition file - private void buildDTPDriverDefinitionFile() throws CoreException { - XMLFileManager.setStorageLocation(this.getDTPDriverDefinitionLocation()); - XMLFileManager.setFileName(this.getDTPDriverFileName()); - - IPropertySet[] sets = XMLFileManager.loadPropertySets(); - for (IPropertySet set : sets) { - if (set.getID().equals(this.getDriverDefinitionID())) { - return; // property sets live across tests - } - } - - XMLFileManager.saveNamedPropertySet(this.buildDTPDriverDefinitionPropertySets()); - - // verify the file was created: - File driverDefinitioneFile = this.getDTPDriverDefinitionLocation().append(this.getDTPDriverFileName()).toFile(); - assertTrue(driverDefinitioneFile.exists()); - } - - private IPath getDTPDriverDefinitionLocation() { - return ConnectivityPlugin.getDefault().getStateLocation(); - } - - private String getDTPDriverFileName() { - return IDriverMgmtConstants.DRIVER_FILE; - } - - private IPropertySet[] buildDTPDriverDefinitionPropertySets() { - IPropertySet[] propertySets = new IPropertySet[1]; - PropertySetImpl propertySet = new PropertySetImpl(this.getDriverName(), this.getDriverDefinitionID()); - propertySet.setProperties(this.getDriverDefinitionID(), this.buildDTPDriverDefinitionProperties()); - propertySets[0] = propertySet; - return propertySets; - } - - protected abstract String getDriverName(); - - protected abstract String getDriverDefinitionID(); - - private Properties buildDTPDriverDefinitionProperties() { - Properties p = new Properties(); - p.setProperty(ConnectionProfile.DRIVER_DEFINITION_TYPE_PROP_ID, this.getDriverDefinitionType()); - p.setProperty(ConnectionProfile.DRIVER_JAR_LIST_PROP_ID, this.getJDBCDriverJarList()); - p.setProperty(IJDBCDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, this.getDatabaseVendor()); - p.setProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, this.getDatabaseVersion()); - p.setProperty(IJDBCDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, this.getDriverClass()); - p.setProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID, this.getJDBCURL()); - p.setProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID, this.getUserID()); - p.setProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID, this.getPassword()); - return p; - } - - protected abstract String getDriverDefinitionType(); - - /** - * The JAR list is workspace-specific and is set in the properties file. - */ - private String getJDBCDriverJarList() { - return this.getRequiredPlatformProperty(DB_DRIVER_JARS_PROPERTY); - } - - protected abstract String getDatabaseVendor(); - - protected abstract String getDatabaseVersion(); - - protected abstract String getDriverClass(); - - /** - * The database URL is workspace-specific and is set in the properties file - * for some databases. - */ - private String getJDBCURL() { - return this.platformProperties.getProperty(DB_URL_PROPERTY, this.getDefaultJDBCURL()); - } - - protected String getDefaultJDBCURL() { - return ""; - } - - /** - * The user ID is optional and can be set in the properties file. - */ - protected String getUserID() { - return this.platformProperties.getProperty(DB_USER_ID_PROPERTY, DB_USER_ID_DEFAULT); - } - - /** - * The password is optional and can be set in the properties file. - */ - private String getPassword() { - return this.platformProperties.getProperty(DB_PASSWORD_PROPERTY, DB_PASSWORD_DEFAULT); - } - - // ***** DTP connection profile - private void buildDTPConnectionProfile() throws ConnectionProfileException { - if (this.getDTPProfileManager().getProfileByName(this.getProfileName()) != null) { - return; // profiles live across tests - } - this.createProfile(this.getProfileName()); - assertNotNull(this.getDTPProfileManager().getProfileByName(this.getProfileName())); - } - - protected void createProfile(String profileName) throws ConnectionProfileException { - this.getDTPProfileManager().createProfile( - profileName, - this.getProfileDescription(), - this.getProviderID(), - this.buildDTPConnectionProfileProperties() - ); - } - - protected abstract String getProfileName(); - - protected abstract String getProfileDescription(); - - protected String getProviderID() { - return ConnectionProfile.CONNECTION_PROFILE_TYPE; - } - - protected Properties buildDTPConnectionProfileProperties() { - Properties p = new Properties(); - p.setProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID, this.getUserID()); - p.setProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID, this.getPassword()); - p.setProperty(ConnectionProfile.DRIVER_DEFINITION_PROP_ID, this.getDriverDefinitionID()); - - p.setProperty(IJDBCDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, this.getDriverClass()); - p.setProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID, this.getJDBCURL()); - p.setProperty(IJDBCDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, this.getDatabaseVendor()); - p.setProperty(IJDBCDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, this.getDatabaseVersion()); - - p.setProperty(ConnectionProfile.DATABASE_SAVE_PWD_PROP_ID, this.passwordIsSaved()); - return p; - } - - private String passwordIsSaved() { - return "true"; - } - - - // ********** tests ********** - - public void testConnectionProfileListener() throws ConnectionProfileException { - TestConnectionProfileListener listener = new TestConnectionProfileListener(); - this.getConnectionProfileFactory().addConnectionProfileListener(listener); - - String cpName1 = this.getProfileName() + "1"; - this.createProfile(cpName1); - IConnectionProfile dtpCP = this.getDTPProfileManager().getProfileByName(cpName1); - assertNotNull(dtpCP); - - assertEquals(cpName1, listener.addedName); - listener.clear(); - - String cpName2 = this.getProfileName() + "2"; - this.getDTPProfileManager().modifyProfile(dtpCP, cpName2, null); - assertEquals(cpName1, listener.renamedOldName); - assertEquals(cpName2, listener.renamedNewName); - listener.clear(); - - ConnectionProfile cp = this.getConnectionProfileFactory().buildConnectionProfile(cpName2); - assertNotNull(cp); - - this.getDTPProfileManager().deleteProfile(dtpCP); - assertEquals(cpName2, listener.removedName); - listener.clear(); - - cp = this.getConnectionProfileFactory().buildConnectionProfile(cpName2); - assertNull(cp); - - this.getConnectionProfileFactory().removeConnectionProfileListener(listener); - } - - public void testName() { - assertEquals(this.getProfileName(), this.connectionProfile.getName()); - } - - public void testConnection() throws Exception { - assertTrue(this.connectionProfile.isInactive()); - assertTrue(this.connectionProfile.isDisconnected()); - this.connectionProfile.connect(); - assertTrue(this.connectionProfile.isActive()); - assertTrue(this.connectionProfile.isConnected()); - - this.verifyDatabaseVersionNumber(); - this.verifyDatabaseVendor(); - this.verifyDatabaseContent(); - - this.connectionProfile.disconnect(); - assertTrue(this.connectionProfile.isInactive()); - assertTrue(this.connectionProfile.isDisconnected()); - } - - private void verifyDatabaseVersionNumber() { - Database database = this.connectionProfile.getDatabase(); - assertNotNull(database); - - String actual = database.getVersion(); - String expected = this.getDatabaseVersion(); - String errorMessage = "expected: " + expected + " - actual: " + actual; - // partial match is good enough - assertTrue(errorMessage, actual.indexOf(expected) != -1); - } - - private void verifyDatabaseVendor() { - Database database = this.connectionProfile.getDatabase(); - String actual = database.getVendorName(); - String expected = this.getDatabaseVendor(); - assertEquals(expected, actual); - } - - private void verifyDatabaseContent() { - Database database = this.connectionProfile.getDatabase(); - assertTrue(database.getSchemataSize() >= 0); - - Schema schema = database.getDefaultSchema(); - if (schema != null) { - if (schema.getTablesSize() > 0) { - Table table = schema.getTables().iterator().next(); - assertTrue(table.getColumnsSize() >= 0); - assertTrue(table.getPrimaryKeyColumnsSize() >= 0); - assertTrue(table.getForeignKeysSize() >= 0); - } - } - } - - protected abstract boolean executeOfflineTests(); - - public final void testOffline() { - if ( ! this.executeOfflineTests()) { - return; - } - if ( ! this.connectionProfile.supportsWorkOfflineMode()) { - return; - } - - this.prepareForOfflineWork(); - - IStatus status = this.connectionProfile.workOffline(); - assertTrue(status.isOK()); - assertTrue(this.connectionProfile.isActive()); - assertTrue(this.connectionProfile.isWorkingOffline()); - - this.connectionProfile.disconnect(); - assertTrue(this.connectionProfile.isInactive()); - assertTrue(this.connectionProfile.isDisconnected()); - } - - protected void prepareForOfflineWork() { - if ( ! this.connectionProfile.canWorkOffline()) { - this.connectionProfile.connect(); - IStatus status = this.connectionProfile.saveWorkOfflineData(); - assertTrue(status.isOK()); - this.connectionProfile.disconnect(); - assertTrue(this.connectionProfile.canWorkOffline()); - } - } - - public void testConnectionListenerConnect() { - assertTrue(this.connectionProfileHasNoListeners()); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - assertTrue(this.connectionProfileHasAnyListeners()); - - this.connectionProfile.connect(); - assertSame(this.connectionProfile, listener.openedProfile); - listener.clear(); - - this.connectionProfile.disconnect(); - assertSame(this.connectionProfile, listener.okToCloseProfile); - assertSame(this.connectionProfile, listener.aboutToCloseProfile); - assertSame(this.connectionProfile, listener.closedProfile); - - this.connectionProfile.removeConnectionListener(listener); - assertTrue(this.connectionProfileHasNoListeners()); - } - - public final void testConnectionListenerOffline() { - if ( ! this.executeOfflineTests()) { - return; - } - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.prepareForOfflineWork(); - listener.clear(); - - this.connectionProfile.workOffline(); - assertSame(this.connectionProfile, listener.openedProfile); - listener.clear(); - - this.connectionProfile.disconnect(); - assertSame(this.connectionProfile, listener.okToCloseProfile); - assertSame(this.connectionProfile, listener.aboutToCloseProfile); - assertSame(this.connectionProfile, listener.closedProfile); - listener.clear(); - - this.connectionProfile.removeConnectionListener(listener); - } - - public void testConnectionListenerDatabase() { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - assertSame(this.connectionProfile.getDatabase(), listener.changedDatabase); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testConnectionListenerCatalog() { - this.connectionProfile.connect(); - if ( ! this.connectionProfile.getDatabase().supportsCatalogs()) { - this.connectionProfile.disconnect(); - return; - } - - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - // take the first catalog - org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog = this.getFirstDTPCatalog(); - Catalog catalog = this.getCatalogNamed(dtpCatalog.getName()); - ((ICatalogObject) dtpCatalog).refresh(); - assertSame(catalog, listener.changedCatalog); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testConnectionListenerSchema() { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - List dtpCatalogs = this.getDTPCatalogs(); - org.eclipse.datatools.modelbase.sql.schema.Catalog dtpCatalog = null; - org.eclipse.datatools.modelbase.sql.schema.Schema dtpSchema = null; - Schema schema = null; - if (this.connectionProfile.getDatabase().supportsCatalogs()) { - dtpCatalog = dtpCatalogs.get(0); - dtpSchema = (org.eclipse.datatools.modelbase.sql.schema.Schema) dtpCatalog.getSchemas().get(0); - schema = this.getCatalogNamed(dtpCatalog.getName()).getSchemaNamed(dtpSchema.getName()); - } else { - if (dtpCatalogs.isEmpty()) { - dtpSchema = (org.eclipse.datatools.modelbase.sql.schema.Schema) this.getDTPDatabase().getSchemas().get(0); - schema = this.connectionProfile.getDatabase().getSchemaNamed(dtpSchema.getName()); - } else { - dtpCatalog = dtpCatalogs.get(0); // should be the "virtual" catalog - assertEquals("", dtpCatalog.getName()); - dtpSchema = (org.eclipse.datatools.modelbase.sql.schema.Schema) dtpCatalog.getSchemas().get(0); - // the schemata are held directly by the database in this situation - schema = this.getDatabase().getSchemaNamed(dtpSchema.getName()); - } - } - assertTrue(schema.getTablesSize() >= 0); // force tables to be loaded - ((ICatalogObject) dtpSchema).refresh(); - assertSame(schema, listener.changedSchema); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testSupportsCatalogs() { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - boolean supportsCatalogs = this.supportsCatalogs(); - assertEquals(supportsCatalogs, this.connectionProfile.getDatabase().supportsCatalogs()); - if (supportsCatalogs) { - assertTrue(this.connectionProfile.getDatabase().getCatalogsSize() > 0); - assertEquals(0, this.connectionProfile.getDatabase().getSchemataSize()); - } else { - assertEquals(0, this.connectionProfile.getDatabase().getCatalogsSize()); - assertTrue(this.connectionProfile.getDatabase().getSchemataSize() > 0); - } - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - protected abstract boolean supportsCatalogs(); - -// public void testDEBUG() throws Exception { -// this.connectionProfile.connect(); -// this.dumpJDBCCatalogs(); -// this.dumpJDBCSchemata(); -// this.dumpDatabaseContainers(); -// this.connectionProfile.disconnect(); -// } - - - // ********** convenience methods ********** - - protected ConnectionProfileFactory getConnectionProfileFactory() { - return JptDbPlugin.getConnectionProfileFactory(); - } - - protected ConnectionProfile getConnectionProfile() { - return this.connectionProfile; - } - - protected Database getDatabase() { - return this.connectionProfile.getDatabase(); - } - - protected Catalog getDefaultCatalog() { - return this.getDatabase().getDefaultCatalog(); - } - - /** - * only valid on databases that do not support catalogs - */ - protected Schema getDefaultSchema() { - return this.getDatabase().getDefaultSchema(); - } - - protected Catalog getCatalogNamed(String catalogName) { - return this.connectionProfile.getDatabase().getCatalogNamed(catalogName); - } - - protected String getRequiredPlatformProperty(String propertyKey) { - String propertyValue = this.platformProperties.getProperty(propertyKey); - if (StringTools.stringIsEmpty(propertyValue)) { - throw new IllegalArgumentException("The database platform properties file '" + this.getPlatformPropertiesFilePath() - + "' is missing a value for the property '" + propertyKey + "'."); - } - return propertyValue; - } - - protected boolean connectionProfileHasAnyListeners() { - return connectionProfileHasAnyListeners(this.connectionProfile); - } - - protected static boolean connectionProfileHasAnyListeners(ConnectionProfile cp) { - return ((Boolean) ReflectionTools.executeMethod(cp, "hasAnyListeners")).booleanValue(); - } - - protected boolean connectionProfileHasNoListeners() { - return connectionProfileHasNoListeners(this.connectionProfile); - } - - protected static boolean connectionProfileHasNoListeners(ConnectionProfile cp) { - return ((Boolean) ReflectionTools.executeMethod(cp, "hasNoListeners")).booleanValue(); - } - - - // ********** DTP model ********** - - protected ProfileManager getDTPProfileManager() { - return ProfileManager.getInstance(); - } - - protected IConnectionProfile getDTPConnectionProfile() { - return getDTPConnectionProfile(this.connectionProfile); - } - - protected static IConnectionProfile getDTPConnectionProfile(ConnectionProfile cp) { - return (IConnectionProfile) ReflectionTools.getFieldValue(cp, "dtpConnectionProfile"); - } - - protected IManagedConnection getDTPManagedConnection() { - return (IManagedConnection) ReflectionTools.getFieldValue(this.connectionProfile, "dtpManagedConnection"); - } - - protected org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase() { - return getDTPDatabase(this.connectionProfile.getDatabase()); - } - - protected static org.eclipse.datatools.modelbase.sql.schema.Database getDTPDatabase(Database database) { - return (org.eclipse.datatools.modelbase.sql.schema.Database) ReflectionTools.getFieldValue(database, "dtpDatabase"); - } - - @SuppressWarnings("unchecked") - protected List getDTPCatalogs() { - return this.getDTPDatabase().getCatalogs(); - } - - protected org.eclipse.datatools.modelbase.sql.schema.Catalog getFirstDTPCatalog() { - return this.getDTPCatalogs().get(0); - } - - protected org.eclipse.datatools.modelbase.sql.schema.Catalog getDTPCatalogNamed(String name) { - return getDTPCatalog(this.getDatabase().getCatalogNamed(name)); - } - - protected static org.eclipse.datatools.modelbase.sql.schema.Catalog getDTPCatalog(Catalog catalog) { - return (org.eclipse.datatools.modelbase.sql.schema.Catalog) ReflectionTools.getFieldValue(catalog, "dtpCatalog"); - } - - protected org.eclipse.datatools.modelbase.sql.schema.Schema getDTPSchemaNamed(String name) { - return getDTPSchema(this.getDatabase().getSchemaNamed(name)); - } - - protected static org.eclipse.datatools.modelbase.sql.schema.Schema getDTPSchema(Schema schema) { - return (org.eclipse.datatools.modelbase.sql.schema.Schema) ReflectionTools.getFieldValue(schema, "dtpSchema"); - } - - - // ********** execute SQL ********** - - /** - * ignore any errors (useful for dropping database objects that might - * not be there) - */ - protected void executeUpdateIgnoreErrors(String sql) { - try { - this.executeUpdate(sql); - } catch (Exception ex) { -// System.err.println("SQL: " + sql); -// ex.printStackTrace(); - } - } - - protected void executeUpdate(String sql) throws SQLException { - Statement jdbcStatement = this.createJDBCStatement(); - try { - jdbcStatement.executeUpdate(sql); - } finally { - jdbcStatement.close(); - } - } - - protected void dump(String sql) throws SQLException { - this.dump(sql, 20); - } - - protected void dump(String sql, int columnWidth) throws SQLException { - IndentingPrintWriter pw = new IndentingPrintWriter(new OutputStreamWriter(System.out)); - // synchronize the console so everything is contiguous - synchronized (System.out) { - this.dumpOn(sql, pw, columnWidth); - } - pw.flush(); - } - - protected void dumpOn(String sql, IndentingPrintWriter pw, int columnWidth) throws SQLException { - pw.println(sql); - for (ArrayList row : this.execute(sql)) { - for (Object columnValue : row) { - StringTools.padOrTruncateOn(String.valueOf(columnValue), columnWidth, pw); - pw.print(' '); - } - pw.println(); - } - } - - protected ArrayList> execute(String sql) throws SQLException { - Statement jdbcStatement = this.createJDBCStatement(); - jdbcStatement.execute(sql); - ArrayList> rows = this.buildRows(jdbcStatement.getResultSet()); - jdbcStatement.close(); - return rows; - } - - protected ArrayList> buildRows(ResultSet resultSet) throws SQLException { - ArrayList> rows = new ArrayList>(); - for (Iterator> stream = this.buildArrayIterator(resultSet); stream.hasNext(); ) { - rows.add(stream.next()); - } - return rows; - } - - protected Iterator> buildArrayIterator(ResultSet resultSet) throws SQLException { - return new ResultSetIterator>(resultSet, new ListResultSetIteratorAdapter(resultSet.getMetaData().getColumnCount())); - } - - public static class ListResultSetIteratorAdapter implements ResultSetIterator.Adapter> { - private final int columnCount; - public ListResultSetIteratorAdapter(int columnCount) { - super(); - this.columnCount = columnCount; - } - public ArrayList buildNext(ResultSet rs) throws SQLException { - ArrayList list = new ArrayList(this.columnCount); - for (int i = 1; i <= this.columnCount; i++) { // NB: ResultSet index/subscript is 1-based - list.add(rs.getObject(i)); - } - return list; - } - } - - protected Statement createJDBCStatement() throws SQLException { - return this.getJDBCConnection().createStatement(); - } - - protected Connection getJDBCConnection() { - return ((ConnectionInfo) this.getDTPManagedConnection().getConnection().getRawConnection()).getSharedConnection(); - } - - protected DatabaseMetaData getDatabaseMetaData() throws SQLException { - return this.getJDBCConnection().getMetaData(); - } - - - // ********** dump DTP metadata ********** - - /** - * dump all the database metadata to the console - */ - protected void dumpDatabase() { - this.dumpDatabase(true); - } - - /** - * dump the database catalogs and schemata to the console - */ - protected void dumpDatabaseContainers() { - this.dumpDatabase(false); - } - - protected void dumpDatabase(boolean deep) { - IndentingPrintWriter pw = new IndentingPrintWriter(new OutputStreamWriter(System.out)); - // synchronize the console so everything is contiguous - synchronized (System.out) { - this.dumpDatabaseOn(pw, deep); - } - pw.flush(); - } - - protected void dumpDatabaseOn(IndentingPrintWriter pw, boolean deep) { - Database database = this.connectionProfile.getDatabase(); - pw.print("database: "); - pw.println(database.getName()); - if (database.supportsCatalogs()) { - for (Catalog catalog : database.getCatalogs()) { - this.dumpCatalogOn(catalog, pw, deep); - } - } else { - this.dumpSchemaContainerOn(database, pw, deep); - } - } - - protected void dumpCatalogOn(Catalog catalog, IndentingPrintWriter pw, boolean deep) { - pw.print("catalog: "); - pw.println(catalog.getName()); - pw.indent(); - this.dumpSchemaContainerOn(catalog, pw, deep); - pw.undent(); - } - - protected void dumpSchemaContainerOn(SchemaContainer schemaContainer, IndentingPrintWriter pw, boolean deep) { - for (Schema schema : schemaContainer.getSchemata()) { - this.dumpSchemaOn(schema, pw, deep); - } - } - - protected void dumpSchema(Schema schema) { - this.dumpSchema(schema, true); - } - - protected void dumpSchema(Schema schema, boolean deep) { - IndentingPrintWriter pw = new IndentingPrintWriter(new OutputStreamWriter(System.out)); - // synchronize the console so everything is contiguous - synchronized (System.out) { - this.dumpSchemaOn(schema, pw, deep); - } - pw.flush(); - } - - protected void dumpSchemaOn(Schema schema, IndentingPrintWriter pw, boolean deep) { - pw.print("schema: "); - pw.println(schema.getName()); - if (deep) { - pw.indent(); - for (Table table : schema.getTables()) { - this.dumpTableOn(table, pw); - } - for (Sequence sequence : schema.getSequences()) { - this.dumpSequenceOn(sequence, pw); - } - pw.undent(); - } - } - - protected void dumpTableOn(Table table, IndentingPrintWriter pw) { - pw.print("table: "); - pw.println(table.getName()); - pw.indent(); - for (Column column : table.getColumns()) { - this.dumpColumnOn(column, pw); - } - for (ForeignKey foreignKey : table.getForeignKeys()) { - this.dumpForeignKeyOn(foreignKey, pw); - } - pw.undent(); - } - - protected void dumpColumnOn(Column column, IndentingPrintWriter pw) { - pw.print("column: "); - pw.print(column.getName()); - pw.print(" : "); - pw.print(column.getDataTypeName()); - if (column.isPartOfPrimaryKey()) { - pw.print(" [primary key]"); - } - pw.println(); - } - - protected void dumpForeignKeyOn(ForeignKey foreignKey, IndentingPrintWriter pw) { - pw.print("foreign key: "); - pw.print(foreignKey.getName()); - pw.print("=>"); - pw.print(foreignKey.getReferencedTable().getName()); - pw.print(" ("); - for (Iterator stream = foreignKey.getColumnPairs().iterator(); stream.hasNext(); ) { - ColumnPair cp = stream.next(); - pw.print(cp.getBaseColumn().getName()); - pw.print("=>"); - pw.print(cp.getReferencedColumn().getName()); - if (stream.hasNext()) { - pw.print(", "); - } - } - pw.print(')'); - pw.println(); - } - - protected void dumpSequenceOn(Sequence sequence, IndentingPrintWriter pw) { - pw.print("sequence: "); - pw.println(sequence.getName()); - } - - - // ********** dump JDBC metadata ********** - - protected void dumpJDBCCatalogs() throws SQLException { - IndentingPrintWriter pw = new IndentingPrintWriter(new OutputStreamWriter(System.out)); - // synchronize the console so everything is contiguous - synchronized (System.out) { - this.dumpJDBCCatalogsOn(pw); - } - pw.flush(); - } - - protected void dumpJDBCCatalogsOn(IndentingPrintWriter pw) throws SQLException { - pw.println("JDBC catalogs: "); - pw.indent(); - ArrayList> rows = this.buildRows(this.getDatabaseMetaData().getCatalogs()); - for (Iterator> stream = rows.iterator(); stream.hasNext(); ) { - pw.println(stream.next().get(0)); - } - pw.undent(); - } - - protected void dumpJDBCSchemata() throws SQLException { - IndentingPrintWriter pw = new IndentingPrintWriter(new OutputStreamWriter(System.out)); - // synchronize the console so everything is contiguous - synchronized (System.out) { - this.dumpJDBCSchemataOn(pw); - } - pw.flush(); - } - - protected void dumpJDBCSchemataOn(IndentingPrintWriter pw) throws SQLException { - pw.println("JDBC schemata: "); - pw.indent(); - ArrayList> rows = this.buildRows(this.getDatabaseMetaData().getSchemas()); - for (ArrayList row : rows) { - if (row.size() == 2) { // catalogs were added in jdk 1.4 - Object catalog = row.get(1); - pw.print(catalog); - pw.print('.'); - } - Object schema = row.get(0); - pw.println(schema); - } - pw.undent(); - } - - - // ********** connection profile listener ********** - - protected static class TestConnectionProfileListener implements ConnectionProfileListener { - public String addedName; - public String removedName; - public String renamedOldName; - public String renamedNewName; - - public void connectionProfileAdded(String name) { - this.addedName = name; - } - public void connectionProfileRemoved(String name) { - this.removedName = name; - } - public void connectionProfileRenamed(String oldName, String newName) { - this.renamedOldName = oldName; - this.renamedNewName = newName; - } - public void clear() { - this.addedName = null; - this.removedName = null; - this.renamedOldName = null; - this.renamedNewName = null; - } - } - - - // ********** connection listener ********** - - protected static class TestConnectionListener implements ConnectionListener { - public ConnectionProfile openedProfile; - public ConnectionProfile modifiedProfile; - public ConnectionProfile okToCloseProfile; - public ConnectionProfile aboutToCloseProfile; - public ConnectionProfile closedProfile; - public Database changedDatabase; - public Catalog changedCatalog; - public Schema changedSchema; - public Sequence changedSequence; - public Table changedTable; - public Column changedColumn; - public ForeignKey changedForeignKey; - - public void opened(ConnectionProfile profile) { - this.openedProfile = profile; - } - public void modified(ConnectionProfile profile) { - this.modifiedProfile = profile; - } - public boolean okToClose(ConnectionProfile profile) { - this.okToCloseProfile = profile; - return true; - } - public void aboutToClose(ConnectionProfile profile) { - this.aboutToCloseProfile = profile; - } - public void closed(ConnectionProfile profile) { - this.closedProfile = profile; - } - public void databaseChanged(ConnectionProfile profile, Database database) { - this.changedDatabase = database; - } - public void catalogChanged(ConnectionProfile profile, Catalog catalog) { - this.changedCatalog = catalog; - } - public void schemaChanged(ConnectionProfile profile, Schema schema) { - this.changedSchema = schema; - } - public void sequenceChanged(ConnectionProfile profile, Sequence sequence) { - this.changedSequence = sequence; - } - public void tableChanged(ConnectionProfile profile, Table table) { - this.changedTable = table; - } - public void columnChanged(ConnectionProfile profile, Column column) { - this.changedColumn = column; - } - public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey) { - this.changedForeignKey = foreignKey; - } - public void clear() { - this.openedProfile = null; - this.modifiedProfile = null; - this.okToCloseProfile = null; - this.aboutToCloseProfile = null; - this.closedProfile = null; - this.changedDatabase = null; - this.changedCatalog = null; - this.changedSchema = null; - this.changedSequence = null; - this.changedTable = null; - this.changedColumn = null; - this.changedForeignKey = null; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DerbyTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DerbyTests.java deleted file mode 100644 index 6ec1ba4f6d..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DerbyTests.java +++ /dev/null @@ -1,482 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.db.tests.internal.platforms; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; - -@SuppressWarnings("nls") -public class DerbyTests extends DTPPlatformTests { - - public DerbyTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "derby.properties"; - } - - @Override - protected String getDriverName() { - return "Derby Embedded JDBC Driver"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.Derby Embedded JDBC Driver"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.connectivity.db.derby101.genericDriverTemplate"; - } - - @Override - protected String getDatabaseVendor() { - return "Derby"; - } - - @Override - protected String getDatabaseVersion() { - return "10.1"; - } - - @Override - protected String getDriverClass() { - return "org.apache.derby.jdbc.EmbeddedDriver"; - } - - @Override - protected String getProfileName() { - return "Derby_10.1_Embedded"; - } - - @Override - protected String getProfileDescription() { - return "Derby 10.1 Embedded JDBC Profile [Test]"; - } - - @Override - protected String getProviderID() { - return "org.eclipse.datatools.connectivity.db.derby.embedded.connectionProfile"; - } - - @Override - protected boolean supportsCatalogs() { - return false; - } - - @Override - protected boolean executeOfflineTests() { - return true; - } - - public void testSchema() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropSchema("TEST1"); - this.dropSchema("TEST2"); - - this.executeUpdate("CREATE SCHEMA TEST1"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema1 = this.getDatabase().getSchemaNamed("TEST1"); - assertNotNull(schema1); - - this.executeUpdate("CREATE SCHEMA TEST2"); - Schema schema2 = this.getDatabase().getSchemaNamed("TEST2"); - assertNull(schema2); // should be null until refresh - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - assertSame(this.getDatabase(), listener.changedDatabase); - - schema2 = this.getDatabase().getSchemaNamed("TEST2"); - assertNotNull(schema2); - assertNotSame(schema1, this.getDatabase().getSchemaNamed("TEST1")); // we should have a new schema after the refresh - - this.dropSchema("TEST2"); - this.dropSchema("TEST1"); - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testSchemaLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropSchema("LOOKUP_TEST"); - this.dropSchema("\"lookup_TEST\""); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - this.executeUpdate("CREATE SCHEMA LOOKUP_TEST"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - assertNotNull(this.getDatabase().getSchemaNamed("LOOKUP_TEST")); - assertNotNull(this.getDatabase().getSchemaForIdentifier("LOOKUP_TEST")); - - assertNull(this.getDatabase().getSchemaNamed("lookup_test")); - assertNotNull(this.getDatabase().getSchemaForIdentifier("lookup_test")); - - assertNull(this.getDatabase().getSchemaNamed("lookup_TEST")); - assertNotNull(this.getDatabase().getSchemaForIdentifier("lookup_TEST")); - - assertNotNull(this.getDatabase().getSchemaForIdentifier("\"LOOKUP_TEST\"")); - assertNull(this.getDatabase().getSchemaForIdentifier("\"lookup_TEST\"")); - - this.dropSchema("LOOKUP_TEST"); - - this.executeUpdate("CREATE SCHEMA \"lookup_TEST\""); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - assertNull(this.getDatabase().getSchemaNamed("LOOKUP_TEST")); - assertNull(this.getDatabase().getSchemaForIdentifier("LOOKUP_TEST")); - - assertNull(this.getDatabase().getSchemaNamed("lookup_test")); - assertNull(this.getDatabase().getSchemaForIdentifier("lookup_test")); - - assertNotNull(this.getDatabase().getSchemaNamed("lookup_TEST")); - assertNull(this.getDatabase().getSchemaForIdentifier("lookup_TEST")); - - assertNull(this.getDatabase().getSchemaForIdentifier("\"LOOKUP_TEST\"")); - assertNotNull(this.getDatabase().getSchemaForIdentifier("\"lookup_TEST\"")); - - this.dropSchema("\"lookup_TEST\""); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testSchemaIdentifier() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropSchema("LOOKUP_TEST"); - this.dropSchema("\"lookup_TEST\""); - - this.executeUpdate("CREATE SCHEMA lookup_test"); // this gets folded to uppercase - this.executeUpdate("CREATE SCHEMA \"lookup_TEST\""); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDatabase().getSchemaForIdentifier("LOOKUP_TEST"); - assertEquals("LOOKUP_TEST", schema.getIdentifier()); - assertEquals("LOOKUP_TEST", schema.getIdentifier("LookupTest")); - assertNull(schema.getIdentifier("Lookup_Test")); - - schema = this.getDatabase().getSchemaForIdentifier("lookup_test"); - assertEquals("LOOKUP_TEST", schema.getIdentifier()); - - schema = this.getDatabase().getSchemaForIdentifier("\"lookup_TEST\""); - assertEquals("\"lookup_TEST\"", schema.getIdentifier()); - assertEquals("\"lookup_TEST\"", schema.getIdentifier("lookup_TEST")); - - this.dropSchema("\"lookup_TEST\""); - this.dropSchema("LOOKUP_TEST"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testTable() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("TABLE_TEST", "FOO_BAZ"); - this.dropTable("TABLE_TEST", "BAZ"); - this.dropTable("TABLE_TEST", "FOO"); - this.dropTable("TABLE_TEST", "BAR"); - this.dropSchema("TABLE_TEST"); - - this.executeUpdate("CREATE SCHEMA TABLE_TEST"); - this.executeUpdate("SET SCHEMA = TABLE_TEST"); - - this.executeUpdate(this.buildBarDDL()); - this.executeUpdate(this.buildFooDDL()); - this.executeUpdate(this.buildBazDDL()); - this.executeUpdate(this.buildFooBazDDL()); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDatabase().getSchemaNamed("TABLE_TEST"); - - // FOO - Table fooTable = schema.getTableNamed("FOO"); - assertEquals(4, fooTable.getColumnsSize()); - assertEquals(1, fooTable.getPrimaryKeyColumnsSize()); - assertEquals(1, fooTable.getForeignKeysSize()); - - Column pkColumn = fooTable.getPrimaryKeyColumn(); - assertEquals("ID", pkColumn.getName()); - Column idColumn = fooTable.getColumnNamed("ID"); - assertSame(pkColumn, idColumn); - assertEquals("INTEGER", idColumn.getDataTypeName()); - assertSame(fooTable, idColumn.getTable()); - assertTrue(idColumn.isPartOfPrimaryKey()); - assertFalse(idColumn.isPartOfForeignKey()); - assertEquals("int", idColumn.getJavaTypeDeclaration()); - - Column nameColumn = fooTable.getColumnNamed("NAME"); - assertEquals("VARCHAR", nameColumn.getDataTypeName()); - assertEquals("java.lang.String", nameColumn.getJavaTypeDeclaration()); - assertEquals(20, nameColumn.getLength()); - assertFalse(nameColumn.isPartOfPrimaryKey()); - assertFalse(nameColumn.isNumeric()); - assertTrue(nameColumn.isNullable()); - - Column barColumn = fooTable.getColumnNamed("BAR_ID"); - assertEquals("INTEGER", barColumn.getDataTypeName()); - assertTrue(barColumn.isPartOfForeignKey()); - assertFalse(barColumn.isPartOfPrimaryKey()); - - Column salaryColumn = fooTable.getColumnNamed("SALARY"); - assertEquals("DECIMAL", salaryColumn.getDataTypeName()); - assertTrue(salaryColumn.isNullable()); - assertTrue(salaryColumn.isNumeric()); - assertEquals(11, salaryColumn.getPrecision()); - assertEquals(2, salaryColumn.getScale()); - assertEquals(-1, salaryColumn.getLength()); - - ForeignKey barFK = fooTable.getForeignKeys().iterator().next(); // there should only be 1 foreign key - assertEquals(1, barFK.getColumnPairsSize()); - assertEquals("BAR", barFK.getAttributeName()); - assertNull(barFK.getJoinColumnAnnotationIdentifier("bar")); - assertEquals("BAR_ID", barFK.getJoinColumnAnnotationIdentifier("primaryBar")); - assertSame(fooTable, barFK.getBaseTable()); - - assertFalse(fooTable.isPossibleJoinTable()); - assertSame(schema, fooTable.getSchema()); - - // BAR - Table barTable = schema.getTableNamed("BAR"); - assertEquals(3, barTable.getColumnsSize()); - assertEquals(1, barTable.getPrimaryKeyColumnsSize()); - assertEquals(0, barTable.getForeignKeysSize()); - assertEquals("ID", barTable.getPrimaryKeyColumn().getName()); - assertFalse(barTable.isPossibleJoinTable()); - - Column id2Column = barTable.getColumnNamed("ID2"); - assertEquals("INTEGER", id2Column.getDataTypeName()); -// assertTrue(id2Column.isPartOfUniqueConstraint()); // doesn't work(?) - assertFalse(id2Column.isNullable()); - assertTrue(id2Column.isNumeric()); - assertEquals(0, id2Column.getPrecision()); // not sure what to expect here... - assertEquals(0, id2Column.getScale()); // not sure what to expect here either... - assertEquals("BLOB", barTable.getColumnNamed("CHUNK").getDataTypeName()); - assertEquals("byte[]", barTable.getColumnNamed("CHUNK").getJavaTypeDeclaration()); - assertTrue(barTable.getColumnNamed("CHUNK").isLOB()); - assertSame(barTable, barFK.getReferencedTable()); - - // BAZ - Table bazTable = schema.getTableNamed("BAZ"); - Column nicknameColumn = bazTable.getColumnNamed("NICKNAME"); - assertEquals(20, nicknameColumn.getLength()); -// assertTrue(nicknameColumn.isPartOfUniqueConstraint()); // doesn't work(?) - - // FOO_BAZ - Table foo_bazTable = schema.getTableNamed("FOO_BAZ"); - assertEquals(2, foo_bazTable.getColumnsSize()); - assertEquals(0, foo_bazTable.getPrimaryKeyColumnsSize()); - assertEquals(2, foo_bazTable.getForeignKeysSize()); - assertTrue(foo_bazTable.isPossibleJoinTable()); - assertTrue(foo_bazTable.joinTableNameIsDefault()); - assertTrue(foo_bazTable.getColumnNamed("FOO_ID").isPartOfForeignKey()); - - this.dropTable("TABLE_TEST", "FOO_BAZ"); - this.dropTable("TABLE_TEST", "BAZ"); - this.dropTable("TABLE_TEST", "FOO"); - this.dropTable("TABLE_TEST", "BAR"); - this.dropSchema("TABLE_TEST"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private static final String CR = System.getProperty("line.separator"); //$NON-NLS-1$ - - private String buildBarDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE BAR (").append(CR); - sb.append(" ID INT PRIMARY KEY,").append(CR); - sb.append(" ID2 INT UNIQUE NOT NULL,").append(CR); - sb.append(" CHUNK BLOB(100K)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE FOO (").append(CR); - sb.append(" ID INT PRIMARY KEY,").append(CR); - sb.append(" NAME VARCHAR(20),").append(CR); - sb.append(" SALARY DECIMAL(11, 2),").append(CR); - sb.append(" BAR_ID INT REFERENCES BAR(ID)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE BAZ (").append(CR); - sb.append(" ID INT PRIMARY KEY,").append(CR); - sb.append(" NICKNAME VARCHAR(20) NOT NULL UNIQUE").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE FOO_BAZ (").append(CR); - sb.append(" FOO_ID INT REFERENCES FOO(ID),").append(CR); - sb.append(" BAZ_ID INT REFERENCES BAZ(ID)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - public void testColumnLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("COLUMN_TEST", "test"); - this.dropSchema("COLUMN_TEST"); - - this.executeUpdate("CREATE SCHEMA COLUMN_TEST"); - this.executeUpdate("SET SCHEMA = COLUMN_TEST"); - - // lowercase - this.executeUpdate("CREATE TABLE test (id INTEGER, name VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Table table = this.getDatabase().getSchemaNamed("COLUMN_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("id")); - assertNotNull(table.getColumnForIdentifier("name")); - - this.dropTable("COLUMN_TEST", "test"); - - // uppercase - this.executeUpdate("CREATE TABLE test (ID INTEGER, NAME VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDatabase().getSchemaNamed("COLUMN_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("ID")); - assertNotNull(table.getColumnForIdentifier("NAME")); - - this.dropTable("COLUMN_TEST", "test"); - - // mixed case - this.executeUpdate("CREATE TABLE test (Id INTEGER, Name VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDatabase().getSchemaNamed("COLUMN_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("Id")); - assertNotNull(table.getColumnForIdentifier("Name")); - - this.dropTable("COLUMN_TEST", "test"); - - // delimited - this.executeUpdate("CREATE TABLE test (\"Id\" INTEGER, \"Name\" VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDatabase().getSchemaNamed("COLUMN_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("\"Id\"")); - assertNotNull(table.getColumnForIdentifier("\"Name\"")); - - this.dropTable("COLUMN_TEST", "test"); - this.dropSchema("COLUMN_TEST"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testCrossSchemaReference() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("XREF_TEST2", "EMP"); - this.dropSchema("XREF_TEST2"); - this.dropTable("XREF_TEST1", "ORG"); - this.dropSchema("XREF_TEST1"); - - this.executeUpdate("CREATE SCHEMA XREF_TEST1"); - this.executeUpdate("SET SCHEMA = XREF_TEST1"); - this.executeUpdate("CREATE TABLE ORG (ID INTEGER PRIMARY KEY, NAME VARCHAR(20))"); - - this.executeUpdate("CREATE SCHEMA XREF_TEST2"); - this.executeUpdate("SET SCHEMA = XREF_TEST2"); - this.executeUpdate("CREATE TABLE EMP (ID INTEGER PRIMARY KEY, NAME VARCHAR(20), " + - "ORG_ID INTEGER REFERENCES XREF_TEST1.ORG(ID))"); - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - Schema schema1 = this.getDatabase().getSchemaNamed("XREF_TEST1"); - assertNotNull(schema1); - Table orgTable = schema1.getTableNamed("ORG"); - assertNotNull(orgTable); - - Schema schema2 = this.getDatabase().getSchemaNamed("XREF_TEST2"); - assertNotNull(schema2); - Table empTable = schema2.getTableNamed("EMP"); - assertNotNull(empTable); - assertEquals(1, empTable.getForeignKeysSize()); - ForeignKey fk = empTable.getForeignKeys().iterator().next(); - Table refTable = fk.getReferencedTable(); - assertNotNull(refTable); - assertEquals("ORG", refTable.getName()); - assertEquals(1, fk.getColumnPairsSize()); - ForeignKey.ColumnPair cp = fk.getColumnPairs().iterator().next(); - Column baseColumn = cp.getBaseColumn(); - assertEquals("ORG_ID", baseColumn.getName()); - Column refColumn = cp.getReferencedColumn(); - assertEquals("ID", refColumn.getName()); - - this.dropTable("XREF_TEST2", "EMP"); - this.dropSchema("XREF_TEST2"); - this.dropTable("XREF_TEST1", "ORG"); - this.dropSchema("XREF_TEST1"); - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private void dropTable(String schemaName, String tableName) throws Exception { - Schema schema= this.getDatabase().getSchemaForIdentifier(schemaName); - if (schema != null) { - if (schema.getTableForIdentifier(tableName) != null) { - this.executeUpdate("DROP TABLE " + schemaName + '.' + tableName); - } - } - } - - /** - * NB: A Derby schema must be empty before it can be dropped. - */ - private void dropSchema(String name) throws Exception { - if (this.getDatabase().getSchemaForIdentifier(name) != null) { - this.executeUpdate("DROP SCHEMA " + name + " RESTRICT"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/MySQLTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/MySQLTests.java deleted file mode 100644 index 28c944eeee..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/MySQLTests.java +++ /dev/null @@ -1,404 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.db.tests.internal.platforms; - -import java.util.Properties; - -import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants; -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; - -/** - * MySQL - * - * Notes: - * - We can only get database objects from the database associated with our - * connection profile. - * - We can reference objects across multiple databases, so they are sorta like - * schemas.... - * - Foreign keys must be defined as table-level constraints; they cannot be - * defined as part of the column clause. - * - Case-sensitivity and -folding is whacked on MySQL.... - */ -@SuppressWarnings("nls") -public class MySQLTests extends DTPPlatformTests { - - public MySQLTests( String name) { - super(name); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "mysql.properties"; - } - - @Override - protected String getDriverName() { - return "MySQL JDBC Driver"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.MySQL JDBC Driver"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.enablement.mysql.4_1.driverTemplate"; - } - - @Override - protected String getDatabaseVendor() { - return "MySql"; - } - - @Override - protected String getDatabaseVersion() { - return "4.1"; - } - - @Override - protected String getDriverClass() { - return "com.mysql.jdbc.Driver"; - } - - @Override - protected String getDefaultJDBCURL() { - return "jdbc:mysql://localhost:3306"; - } - - @Override - protected String getProfileName() { - return "MySQL_4.1"; - } - - @Override - protected String getProfileDescription() { - return "MySQL 4.1 JDBC Profile [Test]"; - } - - @Override - protected boolean supportsCatalogs() { - return false; - } - - @Override - protected Properties buildDTPConnectionProfileProperties() { - Properties p = super.buildDTPConnectionProfileProperties(); - p.setProperty(IJDBCDriverDefinitionConstants.DATABASE_NAME_PROP_ID, this.getDatabaseName()); - return p; - } - - private String getDatabaseName() { - return "dalitest"; - } - - @Override - protected boolean executeOfflineTests() { - return true; // seems to work... - } - - public void testDatabase() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - // DTP: MySQL has a single schema with the same name as the database - Schema schema = this.getDatabase().getSchemaNamed(this.getDatabaseName()); - assertNotNull(schema); - assertSame(this.getDefaultSchema(), schema); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testTable() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropDatabase(this.getDatabaseName()); - this.executeUpdate("CREATE DATABASE " + this.getDatabaseName()); - this.getJDBCConnection().setCatalog(this.getDatabaseName()); - - this.dropTable(this.getDatabaseName(), "foo_baz"); - this.dropTable(this.getDatabaseName(), "baz"); - this.dropTable(this.getDatabaseName(), "foo"); - this.dropTable(this.getDatabaseName(), "bar"); - - this.executeUpdate(this.buildBarDDL()); - this.executeUpdate(this.buildFooDDL()); - this.executeUpdate(this.buildBazDDL()); - this.executeUpdate(this.buildFooBazDDL()); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDefaultSchema(); - - // foo - Table fooTable = schema.getTableNamed("foo"); - assertEquals(3, fooTable.getColumnsSize()); - assertEquals(1, fooTable.getPrimaryKeyColumnsSize()); - assertEquals(1, fooTable.getForeignKeysSize()); - - Column pkColumn = fooTable.getPrimaryKeyColumn(); - assertEquals("id", pkColumn.getName()); - Column idColumn = fooTable.getColumnNamed("id"); - assertSame(pkColumn, idColumn); - assertEquals("INT", idColumn.getDataTypeName()); - assertSame(fooTable, idColumn.getTable()); - assertTrue(idColumn.isPartOfPrimaryKey()); - assertFalse(idColumn.isPartOfForeignKey()); - assertEquals("int", idColumn.getJavaTypeDeclaration()); - - Column nameColumn = fooTable.getColumnNamed("name"); - assertEquals("VARCHAR", nameColumn.getDataTypeName()); - assertEquals("java.lang.String", nameColumn.getJavaTypeDeclaration()); - assertFalse(nameColumn.isPartOfPrimaryKey()); - - Column barColumn = fooTable.getColumnNamed("bar_id"); - assertEquals("INT", barColumn.getDataTypeName()); - assertTrue(barColumn.isPartOfForeignKey()); - assertFalse(barColumn.isPartOfPrimaryKey()); - - ForeignKey barFK = fooTable.getForeignKeys().iterator().next(); // there should only be 1 foreign key - assertEquals(1, barFK.getColumnPairsSize()); - assertEquals("bar", barFK.getAttributeName()); - assertNull(barFK.getJoinColumnAnnotationIdentifier("bar")); - assertEquals("bar_id", barFK.getJoinColumnAnnotationIdentifier("primaryBar")); - assertSame(fooTable, barFK.getBaseTable()); - - assertFalse(fooTable.isPossibleJoinTable()); - assertSame(schema, fooTable.getSchema()); - - // BAR - Table barTable = schema.getTableNamed("bar"); - assertEquals(2, barTable.getColumnsSize()); - assertEquals(1, barTable.getPrimaryKeyColumnsSize()); - assertEquals(0, barTable.getForeignKeysSize()); - assertEquals("id", barTable.getPrimaryKeyColumn().getName()); - assertFalse(barTable.isPossibleJoinTable()); - assertEquals("BLOB", barTable.getColumnNamed("chunk").getDataTypeName()); - assertEquals("byte[]", barTable.getColumnNamed("chunk").getJavaTypeDeclaration()); - assertTrue(barTable.getColumnNamed("chunk").isLOB()); - assertSame(barTable, barFK.getReferencedTable()); - - // FOO_BAZ - Table foo_bazTable = schema.getTableNamed("foo_baz"); - assertEquals(2, foo_bazTable.getColumnsSize()); - assertEquals(0, foo_bazTable.getPrimaryKeyColumnsSize()); - assertEquals(2, foo_bazTable.getForeignKeysSize()); - assertTrue(foo_bazTable.isPossibleJoinTable()); - assertTrue(foo_bazTable.joinTableNameIsDefault()); - assertTrue(foo_bazTable.getColumnNamed("foo_id").isPartOfForeignKey()); - - this.dropTable(this.getDatabaseName(), "foo_baz"); - this.dropTable(this.getDatabaseName(), "baz"); - this.dropTable(this.getDatabaseName(), "foo"); - this.dropTable(this.getDatabaseName(), "bar"); - - this.dropDatabase(this.getDatabaseName()); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private static final String CR = System.getProperty("line.separator"); //$NON-NLS-1$ - - private String buildBarDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE bar (").append(CR); - sb.append(" id INTEGER PRIMARY KEY,").append(CR); - sb.append(" chunk BLOB").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE foo (").append(CR); - sb.append(" id INTEGER PRIMARY KEY,").append(CR); - sb.append(" name VARCHAR(20),").append(CR); - sb.append(" bar_id INTEGER,").append(CR); - sb.append(" FOREIGN KEY (bar_id) REFERENCES bar(id)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE baz (").append(CR); - sb.append(" id INTEGER PRIMARY KEY,").append(CR); - sb.append(" name VARCHAR(20)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE foo_baz (").append(CR); - sb.append(" foo_id INT,").append(CR); - sb.append(" baz_id INT,").append(CR); - sb.append(" FOREIGN KEY (foo_id) REFERENCES foo(id),").append(CR); - sb.append(" FOREIGN KEY (baz_id) REFERENCES baz(id)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - /** - * On Windows, table names get folded to lowercase by default; - * even if the name is delimited (apparently). - */ - public void testTableLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropDatabase(this.getDatabaseName()); - this.executeUpdate("CREATE DATABASE " + this.getDatabaseName()); - this.getJDBCConnection().setCatalog(this.getDatabaseName()); - - this.dropTable(this.getDatabaseName(), "test1"); - this.dropTable(this.getDatabaseName(), "TEST2"); - this.dropTable(this.getDatabaseName(), "`TEST3`"); - - this.executeUpdate("CREATE TABLE test1 (id INTEGER, name VARCHAR(20))"); - this.executeUpdate("CREATE TABLE TEST2 (id INTEGER, name VARCHAR(20))"); - this.executeUpdate("CREATE TABLE `TEST3` (id INTEGER, name VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDefaultSchema(); - - Table test1Table = schema.getTableForIdentifier("test1"); - assertNotNull(test1Table); - - // this probably only works on Windows - Table test2Table = schema.getTableForIdentifier("test2"); - assertNotNull(test2Table); - - // this probably only works on Windows - Table test3Table = schema.getTableForIdentifier("`test3`"); - assertNotNull(test3Table); - - this.dropTable(this.getDatabaseName(), "test1"); - this.dropTable(this.getDatabaseName(), "TEST2"); - this.dropTable(this.getDatabaseName(), "`TEST3`"); - - this.dropDatabase(this.getDatabaseName()); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testColumnLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropDatabase(this.getDatabaseName()); - this.executeUpdate("CREATE DATABASE " + this.getDatabaseName()); - this.getJDBCConnection().setCatalog(this.getDatabaseName()); - - this.dropTable(this.getDatabaseName(), "test"); - - // lowercase - this.executeUpdate("CREATE TABLE test (id INTEGER, name VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Table table = this.getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnNamed("id")); - assertNotNull(table.getColumnNamed("name")); - - this.dropTable(this.getDatabaseName(), "test"); - - // uppercase - this.executeUpdate("CREATE TABLE test (ID INTEGER, NAME VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnNamed("ID")); - assertNotNull(table.getColumnNamed("NAME")); - - this.dropTable(this.getDatabaseName(), "test"); - - // mixed case - this.executeUpdate("CREATE TABLE test (Id INTEGER, Name VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnNamed("Id")); - assertNotNull(table.getColumnNamed("Name")); - - this.dropTable(this.getDatabaseName(), "test"); - - // delimited - this.executeUpdate("CREATE TABLE test (`Id` INTEGER, `Name` VARCHAR(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnForIdentifier("`Id`")); - assertNotNull(table.getColumnForIdentifier("`Name`")); - - this.dropTable(this.getDatabaseName(), "test"); - - this.dropDatabase(this.getDatabaseName()); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - /** - * We can only get a single "schema" per connection via DTP, - * so cross-schema references are not visible. - */ - public void testCrossSchemaReference() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropDatabase("xref_test2"); - this.dropDatabase("xref_test1"); - - this.executeUpdate("CREATE DATABASE xref_test1"); - this.getJDBCConnection().setCatalog("xref_test1"); - this.executeUpdate("CREATE TABLE org (id INTEGER PRIMARY KEY, name VARCHAR(20))"); - - this.executeUpdate("CREATE DATABASE xref_test2"); - this.getJDBCConnection().setCatalog("xref_test2"); - this.executeUpdate("CREATE TABLE emp (id INTEGER PRIMARY KEY, name VARCHAR(20), " + - "org_id INTEGER, FOREIGN KEY (org_id) REFERENCES xref_test1.org(id))"); - - this.getJDBCConnection().setCatalog("xref_test2"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - Schema schema2 = this.getDefaultSchema(); - assertNotNull(schema2); - Table empTable = schema2.getTableNamed("emp"); - assertNotNull(empTable); - // no foreign keys - assertEquals(0, empTable.getForeignKeysSize()); - - this.dropDatabase("xref_test2"); - this.dropDatabase("xref_test1"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private void dropTable(String dbName, String tableName) throws Exception { - this.executeUpdate("DROP TABLE IF EXISTS " + dbName + '.' + tableName); - } - - private void dropDatabase(String name) throws Exception { - this.executeUpdate("DROP DATABASE IF EXISTS " + name); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gTests.java deleted file mode 100644 index c70e3437e5..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gTests.java +++ /dev/null @@ -1,397 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.db.tests.internal.platforms; - -import java.sql.SQLException; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; - -@SuppressWarnings("nls") -public class Oracle10gTests extends DTPPlatformTests { - - public Oracle10gTests( String name) { - super( name); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "oracle10g.properties"; - } - - @Override - protected String getDriverName() { - return "Oracle 10g Thin Driver"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.Oracle Thin Driver"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.enablement.oracle.10.driverTemplate"; - } - - @Override - protected String getDatabaseVendor() { - return "Oracle"; - } - - @Override - protected String getDatabaseVersion() { - return "10"; - } - - @Override - protected String getDriverClass() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - protected String getProfileName() { - return "Oracle10g_10.1.0.4"; - } - - @Override - protected String getProfileDescription() { - return "Oracle10g (10.1.0.4) JDBC Profile [Test]"; - } - - @Override - protected boolean supportsCatalogs() { - return false; - } - - @Override - protected boolean executeOfflineTests() { - // working offline is pretty ugly - return false; - } - - public void testDatabase() throws Exception { - if (this.connectionProfile.getUserName().toUpperCase().equals("SYS")) { - System.out.println("skipped test: " + this.getClass() + '.' + this.getName()); - return; // SYS does not have a schema - } - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - // Oracle should have a schema with the same name as the user - Schema schema = this.getDatabase().getSchemaForIdentifier(this.getUserID()); - assertNotNull(schema); - assertSame(this.getDefaultSchema(), schema); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testTable() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("foo_baz"); - this.dropTable("baz"); - this.dropTable("foo"); - this.dropTable("bar"); - - this.executeUpdate(this.buildBarDDL()); - this.executeUpdate(this.buildFooDDL()); - this.executeUpdate(this.buildBazDDL()); - this.executeUpdate(this.buildFooBazDDL()); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDefaultSchema(); - - // foo - Table fooTable = schema.getTableForIdentifier("foo"); - assertEquals(3, fooTable.getColumnsSize()); - assertEquals(1, fooTable.getPrimaryKeyColumnsSize()); - assertEquals(1, fooTable.getForeignKeysSize()); - - Column pkColumn = fooTable.getPrimaryKeyColumn(); - assertEquals("ID", pkColumn.getName()); - Column idColumn = fooTable.getColumnForIdentifier("id"); - assertSame(pkColumn, idColumn); - assertEquals("NUMBER", idColumn.getDataTypeName()); - assertSame(fooTable, idColumn.getTable()); - assertTrue(idColumn.isPartOfPrimaryKey()); - assertFalse(idColumn.isPartOfForeignKey()); - assertEquals("java.math.BigDecimal", idColumn.getJavaTypeDeclaration()); - - Column nameColumn = fooTable.getColumnForIdentifier("name"); - assertEquals("VARCHAR2", nameColumn.getDataTypeName()); - assertEquals("java.lang.String", nameColumn.getJavaTypeDeclaration()); - assertFalse(nameColumn.isPartOfPrimaryKey()); - - Column barColumn = fooTable.getColumnForIdentifier("bar_id"); - assertEquals("NUMBER", barColumn.getDataTypeName()); - assertTrue(barColumn.isPartOfForeignKey()); - assertFalse(barColumn.isPartOfPrimaryKey()); - - ForeignKey barFK = fooTable.getForeignKeys().iterator().next(); // there should only be 1 foreign key - assertEquals(1, barFK.getColumnPairsSize()); - assertEquals("BAR", barFK.getAttributeName()); - assertNull(barFK.getJoinColumnAnnotationIdentifier("bar")); - assertEquals("BAR_ID", barFK.getJoinColumnAnnotationIdentifier("primaryBar")); - assertSame(fooTable, barFK.getBaseTable()); - - assertFalse(fooTable.isPossibleJoinTable()); - assertSame(schema, fooTable.getSchema()); - - // BAR - Table barTable = schema.getTableForIdentifier("bar"); - assertEquals(2, barTable.getColumnsSize()); - assertEquals(1, barTable.getPrimaryKeyColumnsSize()); - assertEquals(0, barTable.getForeignKeysSize()); - assertEquals("ID", barTable.getPrimaryKeyColumn().getName()); - assertFalse(barTable.isPossibleJoinTable()); - assertEquals("BLOB", barTable.getColumnForIdentifier("chunk").getDataTypeName()); - assertEquals("byte[]", barTable.getColumnForIdentifier("chunk").getJavaTypeDeclaration()); - assertTrue(barTable.getColumnForIdentifier("chunk").isLOB()); - assertSame(barTable, barFK.getReferencedTable()); - - // FOO_BAZ - Table foo_bazTable = schema.getTableForIdentifier("foo_baz"); - assertEquals(2, foo_bazTable.getColumnsSize()); - assertEquals(0, foo_bazTable.getPrimaryKeyColumnsSize()); - assertEquals(2, foo_bazTable.getForeignKeysSize()); - assertTrue(foo_bazTable.isPossibleJoinTable()); - assertTrue(foo_bazTable.joinTableNameIsDefault()); - assertTrue(foo_bazTable.getColumnForIdentifier("foo_id").isPartOfForeignKey()); - - this.dropTable("foo_baz"); - this.dropTable("baz"); - this.dropTable("foo"); - this.dropTable("bar"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private static final String CR = System.getProperty("line.separator"); //$NON-NLS-1$ - - private String buildBarDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE bar (").append(CR); - sb.append(" id NUMBER(10) PRIMARY KEY,").append(CR); - sb.append(" chunk BLOB").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE foo (").append(CR); - sb.append(" id NUMBER(10) PRIMARY KEY,").append(CR); - sb.append(" name VARCHAR2(20),").append(CR); - sb.append(" bar_id REFERENCES bar(id)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE baz (").append(CR); - sb.append(" id NUMBER(10) PRIMARY KEY,").append(CR); - sb.append(" name VARCHAR2(20)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE foo_baz (").append(CR); - sb.append(" foo_id NUMBER(10) REFERENCES foo(id),").append(CR); - sb.append(" baz_id NUMBER(10) REFERENCES baz(id)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - public void testTableLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("test1"); - this.dropTable("TEST2"); - this.dropTable("\"test3\""); - - this.executeUpdate("CREATE TABLE test1 (id NUMBER(10), name VARCHAR2(20))"); - this.executeUpdate("CREATE TABLE TEST2 (id NUMBER(10), name VARCHAR2(20))"); - this.executeUpdate("CREATE TABLE \"test3\" (id NUMBER(10), name VARCHAR2(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDefaultSchema(); - - Table test1Table = schema.getTableForIdentifier("test1"); - assertNotNull(test1Table); - test1Table = schema.getTableForIdentifier("TEST1"); - assertNotNull(test1Table); - - Table test2Table = schema.getTableForIdentifier("test2"); - assertNotNull(test2Table); - test2Table = schema.getTableForIdentifier("TEST2"); - assertNotNull(test2Table); - - Table test3Table = schema.getTableForIdentifier("\"test3\""); - assertNotNull(test3Table); - test3Table = schema.getTableForIdentifier("test3"); - assertNull(test3Table); - - this.dropTable("test1"); - this.dropTable("TEST2"); - this.dropTable("\"test3\""); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testColumnLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("test"); - - // lowercase - this.executeUpdate("CREATE TABLE test (id NUMBER(10), name VARCHAR2(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Table table = this.getDefaultSchema().getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("id")); - assertNotNull(table.getColumnForIdentifier("name")); - - this.dropTable("test"); - - // uppercase - this.executeUpdate("CREATE TABLE test (ID NUMBER(10), NAME VARCHAR2(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultSchema().getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("ID")); - assertNotNull(table.getColumnForIdentifier("NAME")); - - this.dropTable("test"); - - // mixed case - this.executeUpdate("CREATE TABLE test (Id NUMBER(10), Name VARCHAR2(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultSchema().getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("Id")); - assertNotNull(table.getColumnForIdentifier("Name")); - - this.dropTable("test"); - - // delimited - this.executeUpdate("CREATE TABLE test (\"Id\" NUMBER(10), \"Name\" VARCHAR2(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultSchema().getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("\"Id\"")); - assertNotNull(table.getColumnForIdentifier("\"Name\"")); - - this.dropTable("test"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testCrossSchemaReference() throws Exception { - if ( ! this.connectionProfile.getUserName().toUpperCase().equals("SYS")) { - System.out.println("skipped test: " + this.getClass() + '.' + this.getName()); - return; // SYS does not have a schema - } - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.executeUpdateIgnoreErrors("DROP USER XREF_TEST2 CASCADE"); - this.executeUpdateIgnoreErrors("DROP USER XREF_TEST1 CASCADE"); - - this.executeUpdate("CREATE USER XREF_TEST1 IDENTIFIED BY foo"); - this.executeUpdate("ALTER USER XREF_TEST1 QUOTA UNLIMITED ON USERS"); - this.executeUpdate("CREATE TABLE XREF_TEST1.ORG (ID NUMBER(10) PRIMARY KEY, NAME VARCHAR2(20))"); - - this.executeUpdate("CREATE USER XREF_TEST2 IDENTIFIED BY foo"); - this.executeUpdate("ALTER USER XREF_TEST2 QUOTA UNLIMITED ON USERS"); - this.executeUpdate("GRANT ALL ON XREF_TEST1.ORG TO XREF_TEST2"); - this.executeUpdate("CREATE TABLE XREF_TEST2.EMP (ID NUMBER(10) PRIMARY KEY, NAME VARCHAR2(20), " + - "ORG_ID NUMBER(10) REFERENCES XREF_TEST1.ORG(ID))"); - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - Schema schema1 = this.getDatabase().getSchemaNamed("XREF_TEST1"); - assertNotNull(schema1); - Table orgTable = schema1.getTableNamed("ORG"); - assertNotNull(orgTable); - - Schema schema2 = this.getDatabase().getSchemaNamed("XREF_TEST2"); - assertNotNull(schema2); - Table empTable = schema2.getTableNamed("EMP"); - assertNotNull(empTable); - assertEquals(1, empTable.getForeignKeysSize()); - ForeignKey fk = empTable.getForeignKeys().iterator().next(); - Table refTable = fk.getReferencedTable(); - assertNotNull(refTable); - assertEquals("ORG", refTable.getName()); - assertEquals(1, fk.getColumnPairsSize()); - ForeignKey.ColumnPair cp = fk.getColumnPairs().iterator().next(); - Column baseColumn = cp.getBaseColumn(); - assertEquals("ORG_ID", baseColumn.getName()); - Column refColumn = cp.getReferencedColumn(); - assertEquals("ID", refColumn.getName()); - - this.executeUpdate("DROP USER XREF_TEST2 CASCADE"); - this.executeUpdate("DROP USER XREF_TEST1 CASCADE"); - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private void dropTable(String tableName) throws Exception { - this.executeUpdateIgnoreErrors("DROP TABLE " + tableName + " CASCADE CONSTRAINTS"); - } - -// need Oracle enablement plug-in -// public void testSequence() throws Exception { -// this.connectionProfile.connect(); -// TestConnectionListener listener = new TestConnectionListener(); -// this.connectionProfile.addConnectionListener(listener); -// -// this.dropSequence("FOO_SEQ"); -// -// this.executeUpdate("CREATE SEQUENCE FOO_SEQ"); -// ((ICatalogObject) this.getDTPDatabase()).refresh(); -// -// Sequence sequence = this.getDatabase().getDefaultSchema().getSequenceForIdentifier("FOO"); -// assertNotNull(sequence); -// assertEquals("FOO_SEQ", sequence.getName()); -// -// this.dropSequence("FOO_SEQ"); -// -// this.connectionProfile.removeConnectionListener(listener); -// this.connectionProfile.disconnect(); -// } -// -// private void dropSequence(String sequenceName) throws Exception { -// this.executeUpdateIgnoreErrors("DROP SEQUENCE " + sequenceName); -// } -// - protected void dumpUserObjects() throws SQLException { - this.dump("select * from user_objects"); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gXETests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gXETests.java deleted file mode 100644 index 7f309f8520..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gXETests.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Oracle 10g Thin Driver Test - */ -@SuppressWarnings("nls") -public class Oracle10gXETests extends DTPPlatformTests { - - public Oracle10gXETests( String name) { - super( name); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "oracle10gXE.properties"; - } - - @Override - protected String getDriverName() { - return "Oracle 10g Thin Driver"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.Oracle Thin Driver"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.enablement.oracle.10.driverTemplate"; - } - - @Override - protected String getDatabaseVendor() { - return "Oracle"; - } - - @Override - protected String getDatabaseVersion() { - return "10"; - } - - @Override - protected String getDriverClass() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - protected String getProfileName() { - return "Oracle10g_XE"; - } - - @Override - protected String getProfileDescription() { - return "Oracle10g XE Release 2 (10.2) JDBC Profile [Test]"; - } - - @Override - protected boolean supportsCatalogs() { - return false; - } - - @Override - protected boolean executeOfflineTests() { - // working offline is pretty ugly - return false; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle9iTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle9iTests.java deleted file mode 100644 index 9d1c474849..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle9iTests.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Oracle 9i Thin Driver Test - */ -@SuppressWarnings("nls") -public class Oracle9iTests extends DTPPlatformTests { - - public Oracle9iTests( String name) { - super( name); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "oracle9i.properties"; - } - - @Override - protected String getDriverName() { - return "Oracle 9i Thin Driver"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.Oracle Thin Driver"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.enablement.oracle.9.driverTemplate"; - } - - @Override - protected String getDatabaseVendor() { - return "Oracle"; - } - - @Override - protected String getDatabaseVersion() { - return "9"; - } - - @Override - protected String getDriverClass() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - protected String getProfileName() { - return "Oracle9i"; - } - - @Override - protected String getProfileDescription() { - return "Oracle9i JDBC Profile [Test]"; - } - - @Override - protected boolean supportsCatalogs() { - return false; - } - - @Override - protected boolean executeOfflineTests() { - // working offline is pretty ugly - return false; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/PostgreSQLTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/PostgreSQLTests.java deleted file mode 100644 index 4b54bbf4fb..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/PostgreSQLTests.java +++ /dev/null @@ -1,486 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.db.tests.internal.platforms; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; - -@SuppressWarnings("nls") -public class PostgreSQLTests extends DTPPlatformTests { - - public PostgreSQLTests( String name) { - super( name); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "postgresql.properties"; - } - - @Override - protected String getDriverName() { - return "PostgreSQL JDBC Driver"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.PostgreSQL JDBC Driver"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.enablement.postgresql.postgresqlDriverTemplate"; - } - - @Override - protected String getDatabaseVendor() { - return "postgres"; - } - - @Override - protected String getDatabaseVersion() { - return "8.x"; - } - - @Override - protected String getDriverClass() { - return "org.postgresql.Driver"; - } - - @Override - protected String getDefaultJDBCURL() { - // using this URL will result in the DTP database containing a single - // catalog named "" - which, unfortunately, resembles the pseudo-catalog - // generated by DTP for databases that do not return any catalogs via - // JDBC metadata calls... - return "jdbc:postgresql"; - } - - @Override - protected String getProfileName() { - return "PostgreSQL"; - } - - @Override - protected String getProfileDescription() { - return "PostgreSQL 8.2 JDBC Profile [Test]"; - } - - @Override - protected boolean supportsCatalogs() { - return true; - } - - @Override - protected boolean executeOfflineTests() { - // DTP does not support PostgreSQL off-line - see 226704/241558 - return false; - } - - public void testSchema() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropSchema("TEST1"); - this.dropSchema("TEST2"); - - this.executeUpdate("CREATE SCHEMA TEST1"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema1 = this.getDefaultCatalog().getSchemaForIdentifier("TEST1"); - assertNotNull(schema1); - - this.executeUpdate("CREATE SCHEMA TEST2"); - Schema schema2 = this.getDefaultCatalog().getSchemaForIdentifier("TEST2"); - assertNull(schema2); // should be null until refresh - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - assertSame(this.getDatabase(), listener.changedDatabase); - - schema2 = this.getDefaultCatalog().getSchemaForIdentifier("TEST2"); - assertNotNull(schema2); - assertNotSame(schema1, this.getDefaultCatalog().getSchemaForIdentifier("TEST1")); // we should have a new schema after the refresh - - this.dropSchema("TEST2"); - this.dropSchema("TEST1"); - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testSchemaLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropSchema("LOOKUP_TEST"); - this.dropSchema("\"lookup_TEST\""); - - this.executeUpdate("CREATE SCHEMA LOOKUP_TEST"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - assertNull(this.getDefaultCatalog().getSchemaNamed("LOOKUP_TEST")); - assertNotNull(this.getDefaultCatalog().getSchemaForIdentifier("LOOKUP_TEST")); - - assertNotNull(this.getDefaultCatalog().getSchemaNamed("lookup_test")); - assertNotNull(this.getDefaultCatalog().getSchemaForIdentifier("lookup_test")); - - assertNull(this.getDefaultCatalog().getSchemaNamed("lookup_TEST")); - assertNotNull(this.getDefaultCatalog().getSchemaForIdentifier("lookup_TEST")); - - assertNotNull(this.getDefaultCatalog().getSchemaForIdentifier("\"lookup_test\"")); - assertNull(this.getDefaultCatalog().getSchemaForIdentifier("\"lookup_TEST\"")); - assertNull(this.getDefaultCatalog().getSchemaForIdentifier("\"LOOKUP_TEST\"")); - - this.dropSchema("LOOKUP_TEST"); - - this.executeUpdate("CREATE SCHEMA \"lookup_TEST\""); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - assertNull(this.getDefaultCatalog().getSchemaNamed("LOOKUP_TEST")); - assertNull(this.getDefaultCatalog().getSchemaForIdentifier("LOOKUP_TEST")); - - assertNull(this.getDefaultCatalog().getSchemaNamed("lookup_test")); - assertNull(this.getDefaultCatalog().getSchemaForIdentifier("lookup_test")); - - assertNotNull(this.getDefaultCatalog().getSchemaNamed("lookup_TEST")); - assertNull(this.getDefaultCatalog().getSchemaForIdentifier("lookup_TEST")); - - assertNull(this.getDefaultCatalog().getSchemaForIdentifier("\"LOOKUP_TEST\"")); - assertNotNull(this.getDefaultCatalog().getSchemaForIdentifier("\"lookup_TEST\"")); - - this.dropSchema("\"lookup_TEST\""); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testSchemaIdentifier() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropSchema("LOOKUP_TEST"); - this.dropSchema("\"lookup_TEST\""); - - this.executeUpdate("CREATE SCHEMA lookup_test"); // this gets folded to lowercase - this.executeUpdate("CREATE SCHEMA \"lookup_TEST\""); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDefaultCatalog().getSchemaForIdentifier("LOOKUP_TEST"); - assertEquals("lookup_test", schema.getIdentifier()); - assertEquals("lookup_test", schema.getIdentifier("LookupTest")); - assertNull(schema.getIdentifier("Lookup_Test")); - - schema = this.getDefaultCatalog().getSchemaNamed("lookup_test"); - assertEquals("lookup_test", schema.getIdentifier()); - - schema = this.getDefaultCatalog().getSchemaForIdentifier("\"lookup_TEST\""); - assertEquals("\"lookup_TEST\"", schema.getIdentifier()); - assertEquals("\"lookup_TEST\"", schema.getIdentifier("lookup_TEST")); - - this.dropSchema("\"lookup_TEST\""); - this.dropSchema("LOOKUP_TEST"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testTable() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("TABLE_TEST", "FOO_BAZ"); - this.dropTable("TABLE_TEST", "BAZ"); - this.dropTable("TABLE_TEST", "FOO"); - this.dropTable("TABLE_TEST", "BAR"); - this.dropSchema("TABLE_TEST"); - - this.executeUpdate("CREATE SCHEMA TABLE_TEST"); - this.executeUpdate("SET search_path TO TABLE_TEST"); - - this.executeUpdate(this.buildBarDDL()); - this.executeUpdate(this.buildFooDDL()); - this.executeUpdate(this.buildBazDDL()); - this.executeUpdate(this.buildFooBazDDL()); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDefaultCatalog().getSchemaForIdentifier("TABLE_TEST"); - - // FOO - Table fooTable = schema.getTableForIdentifier("FOO"); - assertEquals(3, fooTable.getColumnsSize()); - assertEquals(1, fooTable.getPrimaryKeyColumnsSize()); - assertEquals(1, fooTable.getForeignKeysSize()); - - Column pkColumn = fooTable.getPrimaryKeyColumn(); - assertEquals("id", pkColumn.getName()); - Column idColumn = fooTable.getColumnForIdentifier("ID"); - assertSame(pkColumn, idColumn); - assertEquals("INT4", idColumn.getDataTypeName()); - assertSame(fooTable, idColumn.getTable()); - assertTrue(idColumn.isPartOfPrimaryKey()); - assertFalse(idColumn.isPartOfForeignKey()); - assertEquals("java.lang.Integer", idColumn.getJavaTypeDeclaration()); - - Column nameColumn = fooTable.getColumnForIdentifier("NAME"); - assertEquals("VARCHAR", nameColumn.getDataTypeName()); - assertEquals("java.lang.String", nameColumn.getJavaTypeDeclaration()); - assertFalse(nameColumn.isPartOfPrimaryKey()); - - Column barColumn = fooTable.getColumnForIdentifier("BAR_ID"); - assertEquals("INT4", barColumn.getDataTypeName()); - assertTrue(barColumn.isPartOfForeignKey()); - assertFalse(barColumn.isPartOfPrimaryKey()); - - ForeignKey barFK = fooTable.getForeignKeys().iterator().next(); // there should only be 1 foreign key - assertEquals(1, barFK.getColumnPairsSize()); - assertEquals("bar", barFK.getAttributeName()); - assertNull(barFK.getJoinColumnAnnotationIdentifier("bar")); - assertEquals("bar_id", barFK.getJoinColumnAnnotationIdentifier("primaryBar")); - assertSame(fooTable, barFK.getBaseTable()); - - assertFalse(fooTable.isPossibleJoinTable()); - assertSame(schema, fooTable.getSchema()); - - // BAR - Table barTable = schema.getTableForIdentifier("BAR"); - assertEquals(2, barTable.getColumnsSize()); - assertEquals(1, barTable.getPrimaryKeyColumnsSize()); - assertEquals(0, barTable.getForeignKeysSize()); - assertEquals("id", barTable.getPrimaryKeyColumn().getName()); - assertFalse(barTable.isPossibleJoinTable()); - assertEquals("BYTEA", barTable.getColumnForIdentifier("CHUNK").getDataTypeName()); - assertEquals("byte[]", barTable.getColumnForIdentifier("CHUNK").getJavaTypeDeclaration()); - // assertTrue(barTable.getColumnForIdentifier("CHUNK").dataTypeIsLOB()); - assertSame(barTable, barFK.getReferencedTable()); - - // FOO_BAZ - Table foo_bazTable = schema.getTableForIdentifier("FOO_BAZ"); - assertEquals(2, foo_bazTable.getColumnsSize()); - assertEquals(0, foo_bazTable.getPrimaryKeyColumnsSize()); - assertEquals(2, foo_bazTable.getForeignKeysSize()); - assertTrue(foo_bazTable.isPossibleJoinTable()); - assertTrue(foo_bazTable.joinTableNameIsDefault()); - assertTrue(foo_bazTable.getColumnForIdentifier("FOO_ID").isPartOfForeignKey()); - - this.dropTable("TABLE_TEST", "FOO_BAZ"); - this.dropTable("TABLE_TEST", "BAZ"); - this.dropTable("TABLE_TEST", "FOO"); - this.dropTable("TABLE_TEST", "BAR"); - this.dropSchema("TABLE_TEST"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private static final String CR = System.getProperty("line.separator"); //$NON-NLS-1$ - - private String buildBarDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE BAR (").append(CR); - sb.append(" ID integer PRIMARY KEY,").append(CR); - sb.append(" CHUNK bytea").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE FOO (").append(CR); - sb.append(" ID integer PRIMARY KEY,").append(CR); - sb.append(" NAME varchar(20),").append(CR); - sb.append(" BAR_ID integer REFERENCES BAR(ID)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE BAZ (").append(CR); - sb.append(" ID integer PRIMARY KEY,").append(CR); - sb.append(" NAME varchar(20)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("CREATE TABLE FOO_BAZ (").append(CR); - sb.append(" FOO_ID int REFERENCES FOO(ID),").append(CR); - sb.append(" BAZ_ID int REFERENCES BAZ(ID)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - public void testColumnLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("TABLE_TEST", "test"); - this.dropSchema("TABLE_TEST"); - - this.executeUpdate("CREATE SCHEMA TABLE_TEST"); - this.executeUpdate("SET search_path TO TABLE_TEST"); - - // lowercase - this.executeUpdate("CREATE TABLE test (id int, name varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Table table = this.getDefaultCatalog().getSchemaForIdentifier("TABLE_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("id")); - assertNotNull(table.getColumnForIdentifier("name")); - - this.dropTable("TABLE_TEST", "test"); - - // uppercase - this.executeUpdate("CREATE TABLE test (ID int, NAME varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultCatalog().getSchemaForIdentifier("TABLE_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("ID")); - assertNotNull(table.getColumnForIdentifier("NAME")); - - this.dropTable("TABLE_TEST", "test"); - - // mixed case - this.executeUpdate("CREATE TABLE test (Id int, Name varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultCatalog().getSchemaForIdentifier("TABLE_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("Id")); - assertNotNull(table.getColumnForIdentifier("Name")); - - this.dropTable("TABLE_TEST", "test"); - - // delimited - this.executeUpdate("CREATE TABLE test (\"Id\" int, \"Name\" varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDefaultCatalog().getSchemaForIdentifier("TABLE_TEST").getTableForIdentifier("test"); - assertNotNull(table.getColumnForIdentifier("\"Id\"")); - assertNotNull(table.getColumnForIdentifier("\"Name\"")); - - this.dropTable("TABLE_TEST", "test"); - this.dropSchema("TABLE_TEST"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testCrossSchemaReference() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.dropTable("XREF_TEST2", "EMP"); - this.dropSchema("XREF_TEST2"); - this.dropTable("XREF_TEST1", "ORG"); - this.dropSchema("XREF_TEST1"); - - this.executeUpdate("CREATE SCHEMA XREF_TEST1"); - this.executeUpdate("SET search_path TO XREF_TEST1"); - this.executeUpdate("CREATE TABLE ORG (ID integer PRIMARY KEY, NAME varchar(20))"); - - this.executeUpdate("CREATE SCHEMA XREF_TEST2"); - this.executeUpdate("SET search_path TO XREF_TEST2"); - this.executeUpdate("CREATE TABLE EMP (ID integer PRIMARY KEY, NAME varchar(20), " + - "ORG_ID integer REFERENCES XREF_TEST1.ORG(ID))"); - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - Schema schema1 = this.getDefaultCatalog().getSchemaNamed("xref_test1"); - assertNotNull(schema1); - Table orgTable = schema1.getTableNamed("org"); - assertNotNull(orgTable); - - Schema schema2 = this.getDefaultCatalog().getSchemaNamed("xref_test2"); - assertNotNull(schema2); - Table empTable = schema2.getTableNamed("emp"); - assertNotNull(empTable); - assertEquals(1, empTable.getForeignKeysSize()); - ForeignKey fk = empTable.getForeignKeys().iterator().next(); - Table refTable = fk.getReferencedTable(); - assertNotNull(refTable); - assertEquals("org", refTable.getName()); - assertEquals(1, fk.getColumnPairsSize()); - ForeignKey.ColumnPair cp = fk.getColumnPairs().iterator().next(); - Column baseColumn = cp.getBaseColumn(); - assertEquals("org_id", baseColumn.getName()); - Column refColumn = cp.getReferencedColumn(); - assertEquals("id", refColumn.getName()); - - this.dropTable("XREF_TEST2", "EMP"); - this.dropSchema("XREF_TEST2"); - this.dropTable("XREF_TEST1", "ORG"); - this.dropSchema("XREF_TEST1"); - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private void dropTable(String schemaName, String tableName) throws Exception { - Schema schema= this.getDefaultCatalog().getSchemaForIdentifier(schemaName); - if (schema != null) { - if (schema.getTableForIdentifier(tableName) != null) { - this.executeUpdate("DROP TABLE " + schemaName + '.' + tableName); - } - } - } - - private void dropSchema(String name) throws Exception { - if (this.getDefaultCatalog().getSchemaForIdentifier(name) != null) { - this.executeUpdate("DROP SCHEMA " + name + " CASCADE"); - } - } - -// see 241578/241557 -// public void testSequence() throws Exception { -// this.connectionProfile.connect(); -// TestConnectionListener listener = new TestConnectionListener(); -// this.connectionProfile.addConnectionListener(listener); -// -// this.dropSequence("SEQUENCE_TEST", "FOO"); -// this.dropSchema("SEQUENCE_TEST"); -// -// this.executeUpdate("CREATE SCHEMA SEQUENCE_TEST"); -// this.executeUpdate("SET search_path TO SEQUENCE_TEST"); -// -// this.executeUpdate(this.buildBarDDL()); -// this.executeUpdate("CREATE SEQUENCE FOO START 1"); -//// List list = this.execute("SELECT nextval('foo')"); -//// System.out.println(list); -// ((ICatalogObject) this.getDTPDatabase()).refresh(); -// -// Schema schema = this.getDefaultCatalog().getSchemaNamed("SEQUENCE_TEST"); -// Sequence sequence = schema.getSequenceNamed("FOO"); -// assertNotNull(sequence); -// assertEquals("foo_seq", sequence.getName()); -// -// this.dropSequence("SEQUENCE_TEST", "FOO"); -// this.dropSchema("SEQUENCE_TEST"); -// -// this.connectionProfile.removeConnectionListener(listener); -// this.connectionProfile.disconnect(); -// } -// -// private void dropSequence(String schemaName, String sequenceName) throws Exception { -// Schema schema= this.getDefaultCatalog().getSchemaNamed(schemaName); -// if (schema != null) { -// if (schema.getSequenceNamed(sequenceName) != null) { -// this.executeUpdate("DROP SEQUENCE " + schemaName + '.' + sequenceName); -// } -// } -// } -// -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SQLServerTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SQLServerTests.java deleted file mode 100644 index cedde5d7c4..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SQLServerTests.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * SQL Server 2005 Driver Test - */ -@SuppressWarnings("nls") -public class SQLServerTests extends DTPPlatformTests { - - public SQLServerTests( String name) { - super( name); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "sqlserver.properties"; - } - - @Override - protected String getDriverName() { - return "Microsoft SQL Server 2005 JDBC Driver"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.Microsoft SQL Server 2005 JDBC Driver"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.enablement.msft.sqlserver.2005.driverTemplate"; - } - - @Override - protected String getDatabaseVendor() { - return "SQLServer"; - } - - @Override - protected String getDatabaseVersion() { - return "2005"; - } - - @Override - protected String getDriverClass() { - return "com.microsoft.sqlserver.jdbc.SQLServerDriver"; - } - - @Override - protected String getProfileName() { - return "SQLServer_2005"; - } - - @Override - protected String getProfileDescription() { - return "Microsoft SQL Server 2005 JDBC Profile [Test]"; - } - - @Override - protected String getProviderID() { - return "org.eclipse.datatools.connectivity.db.generic.connectionProfile"; - } - - @Override - protected boolean supportsCatalogs() { - return true; - } - - @Override - protected boolean executeOfflineTests() { - return true; // haven't actually tried this yet... - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SybaseTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SybaseTests.java deleted file mode 100644 index 41cea99c95..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SybaseTests.java +++ /dev/null @@ -1,443 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.db.tests.internal.platforms; - -import org.eclipse.datatools.connectivity.sqm.core.rte.ICatalogObject; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; - -@SuppressWarnings("nls") -public class SybaseTests extends DTPPlatformTests { - - public SybaseTests( String name) { - super( name); - } - - @Override - protected String getPlatformPropertiesFileName() { - return "sybase.properties"; - } - - @Override - protected String getDriverName() { - return "Sybase JDBC Driver for Sybase ASE 15.x"; - } - - @Override - protected String getDriverDefinitionID() { - return "DriverDefn.Sybase JDBC Driver for Sybase ASE 15.x"; - } - - @Override - protected String getDriverDefinitionType() { - return "org.eclipse.datatools.connectivity.db.sybase.ase.genericDriverTemplate_15"; - } - - @Override - protected String getDatabaseVendor() { - return "Sybase_ASE"; - } - - @Override - protected String getDatabaseVersion() { - return "15.x"; - } - - @Override - protected String getDriverClass() { - return "com.sybase.jdbc3.jdbc.SybDriver"; - } - - @Override - protected String getProfileName() { - return "Sybase_15"; - } - - @Override - protected String getProfileDescription() { - return "Sybase ASE 15 jConnect JDBC Profile [Test]"; - } - - @Override - protected boolean supportsCatalogs() { - return true; - } - - @Override - protected boolean executeOfflineTests() { - // working offline is pretty ugly - return false; - } - - /** - * Sybase "databases" become DTP "catalogs" - */ - public void testCatalog() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdateIgnoreErrors("drop database test1"); - this.executeUpdateIgnoreErrors("drop database test2"); - - this.executeUpdate("create database test1"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Catalog catalog1 = this.getDatabase().getCatalogNamed("test1"); - assertNotNull(catalog1); - Schema schema1 = catalog1.getSchemaNamed("dbo"); - assertNotNull(schema1); - assertSame(schema1, catalog1.getDefaultSchema()); - - this.executeUpdate("create database test2"); - Catalog catalog2 = this.getDatabase().getCatalogNamed("test2"); - assertNull(catalog2); // should be null until refresh - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - assertSame(this.getDatabase(), listener.changedDatabase); - - catalog2 = this.getDatabase().getCatalogNamed("test2"); - assertNotNull(catalog2); - Schema schema2 = catalog2.getDefaultSchema(); - assertNotNull(schema2); - - assertNotSame(catalog1, this.getDatabase().getCatalogNamed("test1")); // we should have a new catalog after the refresh - assertNotSame(schema1, this.getDatabase().getCatalogNamed("test1").getDefaultSchema()); // we should have a new schema after the refresh - - this.executeUpdate("drop database test2"); - this.executeUpdate("drop database test1"); - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testTable() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdateIgnoreErrors("drop database table_test"); - this.executeUpdate("create database table_test"); - this.getJDBCConnection().setCatalog("table_test"); - - this.executeUpdate(this.buildBarDDL()); - this.executeUpdate(this.buildFooDDL()); - this.executeUpdate(this.buildBazDDL()); - this.executeUpdate(this.buildFooBazDDL()); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDatabase().getCatalogNamed("table_test").getDefaultSchema(); - - // foo - Table fooTable = schema.getTableNamed("foo"); - assertEquals(3, fooTable.getColumnsSize()); - assertEquals(1, fooTable.getPrimaryKeyColumnsSize()); - assertEquals(1, fooTable.getForeignKeysSize()); - - Column pkColumn = fooTable.getPrimaryKeyColumn(); - assertEquals("id", pkColumn.getName()); - Column idColumn = fooTable.getColumnNamed("id"); - assertSame(fooTable, idColumn.getTable()); - assertSame(pkColumn, idColumn); - assertTrue(idColumn.isPartOfPrimaryKey()); - assertFalse(idColumn.isPartOfForeignKey()); - assertTrue(idColumn.isPartOfUniqueConstraint()); - assertFalse(idColumn.isNullable()); - - assertEquals("INT", idColumn.getDataTypeName()); - assertTrue(idColumn.isNumeric()); - assertEquals(0, idColumn.getPrecision()); - assertEquals(0, idColumn.getScale()); - assertEquals(-1, idColumn.getLength()); - assertFalse(idColumn.isLOB()); - assertEquals("int", idColumn.getJavaTypeDeclaration()); - - Column nameColumn = fooTable.getColumnNamed("name"); - assertFalse(nameColumn.isPartOfPrimaryKey()); - assertFalse(nameColumn.isPartOfForeignKey()); - assertTrue(nameColumn.isPartOfUniqueConstraint()); - assertFalse(nameColumn.isNullable()); // implied "NOT NULL" ? - - assertEquals("VARCHAR", nameColumn.getDataTypeName()); - assertFalse(nameColumn.isNumeric()); - assertEquals(-1, nameColumn.getPrecision()); - assertEquals(-1, nameColumn.getScale()); - assertEquals(20, nameColumn.getLength()); - assertFalse(nameColumn.isLOB()); - assertEquals("java.lang.String", nameColumn.getJavaTypeDeclaration()); - - Column barColumn = fooTable.getColumnNamed("bar_id"); - assertEquals("INT", barColumn.getDataTypeName()); - assertTrue(barColumn.isPartOfForeignKey()); - assertFalse(barColumn.isPartOfPrimaryKey()); - - ForeignKey barFK = fooTable.getForeignKeys().iterator().next(); // there should only be 1 foreign key - assertEquals(1, barFK.getColumnPairsSize()); - assertEquals("bar", barFK.getAttributeName()); - assertNull(barFK.getJoinColumnAnnotationIdentifier("bar")); - assertEquals("bar_id", barFK.getJoinColumnAnnotationIdentifier("primaryBar")); - assertSame(fooTable, barFK.getBaseTable()); - - assertFalse(fooTable.isPossibleJoinTable()); - assertSame(schema, fooTable.getSchema()); - - // BAR - Table barTable = schema.getTableNamed("bar"); - assertEquals(2, barTable.getColumnsSize()); - assertEquals(1, barTable.getPrimaryKeyColumnsSize()); - assertEquals(0, barTable.getForeignKeysSize()); - assertEquals("id", barTable.getPrimaryKeyColumn().getName()); - assertFalse(barTable.isPossibleJoinTable()); - Column chunkColumn = barTable.getColumnNamed("chunk"); - assertEquals("IMAGE", chunkColumn.getDataTypeName()); - assertFalse(chunkColumn.isNumeric()); - assertTrue(chunkColumn.isLOB()); - assertEquals("byte[]", chunkColumn.getJavaTypeDeclaration()); - assertSame(barTable, barFK.getReferencedTable()); - - // BAZ - Table bazTable = schema.getTableNamed("baz"); - assertEquals(4, bazTable.getColumnsSize()); - assertEquals(1, bazTable.getPrimaryKeyColumnsSize()); - assertEquals(0, bazTable.getForeignKeysSize()); - - Column nicknameColumn = bazTable.getColumnNamed("nickname"); - assertTrue(nicknameColumn.isNullable()); - - Column songColumn = bazTable.getColumnNamed("song"); - assertFalse(songColumn.isNullable()); - - Column salaryColumn = bazTable.getColumnNamed("salary"); - assertFalse(salaryColumn.isPartOfUniqueConstraint()); - assertEquals("DECIMAL", salaryColumn.getDataTypeName()); - assertTrue(salaryColumn.isNumeric()); - assertEquals(10, salaryColumn.getPrecision()); - assertEquals(2, salaryColumn.getScale()); - assertEquals(-1, salaryColumn.getLength()); - assertFalse(salaryColumn.isLOB()); - - // FOO_BAZ - Table foo_bazTable = schema.getTableNamed("foo_baz"); - assertEquals(2, foo_bazTable.getColumnsSize()); - assertEquals(0, foo_bazTable.getPrimaryKeyColumnsSize()); - assertEquals(2, foo_bazTable.getForeignKeysSize()); - assertTrue(foo_bazTable.isPossibleJoinTable()); - assertTrue(foo_bazTable.joinTableNameIsDefault()); - assertTrue(foo_bazTable.getColumnNamed("foo_id").isPartOfForeignKey()); - - this.executeUpdate("drop table foo_baz"); - this.executeUpdate("drop table baz"); - this.executeUpdate("drop table foo"); - this.executeUpdate("drop table bar"); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdate("drop database table_test"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - private static final String CR = System.getProperty("line.separator"); //$NON-NLS-1$ - - private String buildBarDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("create table bar (").append(CR); - sb.append(" id integer primary key,").append(CR); - sb.append(" chunk image").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("create table foo (").append(CR); - sb.append(" id integer primary key,").append(CR); - sb.append(" name varchar(20) unique,").append(CR); - sb.append(" bar_id integer references bar(id)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("create table baz (").append(CR); - sb.append(" id integer primary key,").append(CR); - sb.append(" nickname varchar(20) null,").append(CR); - sb.append(" song varchar(20) not null,").append(CR); - sb.append(" salary decimal(10, 2)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - private String buildFooBazDDL() { - StringBuilder sb = new StringBuilder(200); - sb.append("create table foo_baz (").append(CR); - sb.append(" foo_id integer references foo(id),").append(CR); - sb.append(" baz_id integer references baz(id)").append(CR); - sb.append(")").append(CR); - return sb.toString(); - } - - public void testTableLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdateIgnoreErrors("drop database table_lookup_test"); - this.executeUpdate("create database table_lookup_test"); - this.getJDBCConnection().setCatalog("table_lookup_test"); - - this.executeUpdate("create table test1 (id integer, name varchar(20))"); - this.executeUpdate("create table TEST2 (id integer, name varchar(20))"); - this.executeUpdate("create table [Test3] (id integer, name varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Schema schema = this.getDatabase().getCatalogNamed("table_lookup_test").getDefaultSchema(); - - assertNotNull(schema.getTableNamed("test1")); - assertNotNull(schema.getTableForIdentifier("test1")); - - assertNotNull(schema.getTableNamed("TEST2")); - assertNotNull(schema.getTableForIdentifier("TEST2")); - - assertNotNull(schema.getTableForIdentifier("[Test3]")); - - this.executeUpdate("drop table [Test3]"); - this.executeUpdate("drop table TEST2"); - this.executeUpdate("drop table test1"); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdate("drop database table_lookup_test"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testColumnLookup() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdateIgnoreErrors("drop database column_lookup_test"); - this.executeUpdate("create database column_lookup_test"); - this.getJDBCConnection().setCatalog("column_lookup_test"); - - // lowercase - this.executeUpdate("create table test (id integer, name varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - Table table = this.getDatabase().getCatalogNamed("column_lookup_test").getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnNamed("id")); - assertNotNull(table.getColumnNamed("name")); - - this.executeUpdate("drop table test"); - - // uppercase - this.executeUpdate("create table test (ID integer, NAME varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDatabase().getCatalogNamed("column_lookup_test").getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnForIdentifier("ID")); - assertNotNull(table.getColumnForIdentifier("NAME")); - - this.executeUpdate("drop table test"); - - // mixed case - this.executeUpdate("create table test (Id integer, Name varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDatabase().getCatalogNamed("column_lookup_test").getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnForIdentifier("Id")); - assertNotNull(table.getColumnForIdentifier("Name")); - - this.executeUpdate("drop table test"); - - // delimited - this.executeUpdate("create table test ([Id] integer, [Name] varchar(20))"); - ((ICatalogObject) this.getDTPDatabase()).refresh(); - - table = this.getDatabase().getCatalogNamed("column_lookup_test").getDefaultSchema().getTableNamed("test"); - assertNotNull(table.getColumnForIdentifier("[Id]")); - assertNotNull(table.getColumnForIdentifier("[Name]")); - - this.executeUpdate("drop table test"); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdate("drop database column_lookup_test"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - - public void testCrossSchemaReference() throws Exception { - this.connectionProfile.connect(); - TestConnectionListener listener = new TestConnectionListener(); - this.connectionProfile.addConnectionListener(listener); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdateIgnoreErrors("drop database xref_test2"); - this.executeUpdateIgnoreErrors("drop database xref_test1"); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdate("create database xref_test1"); - this.getJDBCConnection().setCatalog("xref_test1"); - this.executeUpdate("create table org (id integer primary key, name varchar(20))"); - - this.getJDBCConnection().setCatalog("master"); - this.executeUpdate("create database xref_test2"); - this.getJDBCConnection().setCatalog("xref_test2"); - this.executeUpdate("create table emp (id integer primary key, name varchar(20), " + - "org_id integer references xref_test1..org(id))"); - - ((ICatalogObject) this.getDTPDatabase()).refresh(); - Catalog catalog1 = this.getDatabase().getCatalogNamed("xref_test1"); - assertNotNull(catalog1); - Schema schema1 = catalog1.getSchemaNamed("dbo"); - assertNotNull(schema1); - Table orgTable = schema1.getTableNamed("org"); - assertNotNull(orgTable); - - Catalog catalog2 = this.getDatabase().getCatalogNamed("xref_test2"); - assertNotNull(catalog2); - Schema schema2 = catalog2.getSchemaNamed("dbo"); - assertNotNull(schema2); - Table empTable = schema2.getTableNamed("emp"); - assertNotNull(empTable); - assertEquals(1, empTable.getForeignKeysSize()); - ForeignKey fk = empTable.getForeignKeys().iterator().next(); - Table refTable = fk.getReferencedTable(); - assertNotNull(refTable); - assertEquals("org", refTable.getName()); - assertEquals(1, fk.getColumnPairsSize()); - ForeignKey.ColumnPair cp = fk.getColumnPairs().iterator().next(); - Column baseColumn = cp.getBaseColumn(); - assertEquals("org_id", baseColumn.getName()); - Column refColumn = cp.getReferencedColumn(); - assertEquals("id", refColumn.getName()); - - this.getJDBCConnection().setCatalog("xref_test2"); - this.executeUpdate("drop table emp"); - this.getJDBCConnection().setCatalog("xref_test1"); - this.executeUpdate("drop table org"); - this.getJDBCConnection().setCatalog("master"); - this.executeUpdate("drop database xref_test2"); - this.executeUpdate("drop database xref_test1"); - - this.connectionProfile.removeConnectionListener(listener); - this.connectionProfile.disconnect(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath deleted file mode 100644 index db34e47716..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore deleted file mode 100644 index c4ba612bad..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -bin -@dot -temp.folder -build.xml -javaCompiler...args \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project index 26141a5bbf..baaef71e6a 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project @@ -1,28 +1,5 @@ org.eclipse.jpt.eclipselink.core.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - + renamed to org.eclipse.jpt.jpa.eclipselink.core.tests + \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 11155f4708..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Mon Apr 07 14:26:54 EDT 2008 -eclipse.preferences.version=1 -encoding/=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.jdt.core.prefs b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 8bab913c29..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Mon Jul 07 20:13:24 EDT 2008 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF deleted file mode 100644 index 51d36cce1a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,46 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.eclipselink.core.tests -Bundle-Version: 1.4.0.qualifier -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)", - org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)", - org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)", - org.eclipse.jpt.common.core.tests;bundle-version="[1.0.0,2.0.0)", - org.eclipse.jpt.core;bundle-version="[2.0.0,3.0.0)", - org.eclipse.jpt.core.tests;bundle-version="[2.0.0,3.0.0)", - org.eclipse.jpt.eclipselink.core;bundle-version="[1.0.0,2.0.0)", - org.eclipse.jpt.common.utility;bundle-version="[1.2.0,2.0.0)", - org.eclipse.wst.common.emf;bundle-version="[1.1.201,2.0.0)", - org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.201,2.0.0)", - org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.modulecore;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)", - org.junit;bundle-version="3.8.0" -Export-Package: org.eclipse.jpt.eclipselink.core.tests.internal;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.java;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.orm;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.caching;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.connection;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.customization;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.general;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.logging;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.options;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.schema.generation;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.resource;x-internal:=true, - org.eclipse.jpt.eclipselink.core.tests.internal.resource.java;x-internal:=true, - org.eclipse.jpt.eclipselink1_1.core.tests.internal.context;x-internal:=true, - org.eclipse.jpt.eclipselink1_1.core.tests.internal.context.orm;x-internal:=true, - org.eclipse.jpt.eclipselink1_2.core.tests.internal.context;x-internal:=true, - org.eclipse.jpt.eclipselink2_0.core.tests.internal.context;x-internal:=true, - org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.java;x-internal:=true, - org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm;x-internal:=true, - org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.persistence;x-internal:=true diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/about.html b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/about.html deleted file mode 100644 index be534ba44f..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/about.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - -About - - - - - -

About This Content

- -

May 02, 2008

- -

License

- -

The Eclipse Foundation makes available all content in this plug-in -("Content"). Unless otherwise indicated below, the Content is provided to you -under the terms and conditions of the Eclipse Public License Version 1.0 -("EPL"). A copy of the EPL is available at -http://www.eclipse.org/org/documents/epl-v10.php. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the -Content is being redistributed by another party ("Redistributor") and different -terms and conditions may apply to your use of any object code in the Content. -Check the Redistributor's license that was provided with the Content. If no such -license exists, contact the Redistributor. Unless otherwise indicated below, the -terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at -http://www.eclipse.org/.

- - - diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties deleted file mode 100644 index 96de1ee6d2..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties +++ /dev/null @@ -1,18 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 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 -################################################################################ -javacSource = 1.5 -javacTarget = 1.5 -bin.includes = .,\ - META-INF/,\ - about.html,\ - test.xml,\ - plugin.properties -source.. = src/ -output.. = bin/ diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties deleted file mode 100644 index 5b9cfcd182..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 2009 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 -################################################################################ -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName=Dali Java Persistence Tools - EclipseLink Support - Core Tests -providerName=Eclipse Web Tools Platform 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 90888e5de4..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal; - -import java.io.File; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.JptEclipseLinkCoreContextModelTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.resource.JptEclipselinkCoreResourceModelTests; - -/** - * decentralize test creation code - * - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar= - * -Dorg.eclipse.jpt.eclipselink.jar= - */ -@SuppressWarnings("nls") -public class JptEclipseLinkCoreTests -{ - private static final String JPA_JAR_PROPERTY = TestJpaProject.JPA_JAR_NAME_SYSTEM_PROPERTY; - private static final String ECLIPSELINK_JAR_PROPERTY = TestJpaProject.ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY; - - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreTests.class.getPackage().getName()); - suite.addTest(JptEclipselinkCoreResourceModelTests.suite()); - suite.addTest(JptEclipseLinkCoreContextModelTests.suite()); - return suite; - } - - public static boolean requiredJarsExists() { - return jpaJarPropertyExists() - && jpaJarFileExists() - && eclipselinkJarPropertyExists() - && eclipselinkJarFileExists(); - } - - public static boolean jpaJarPropertyExists() { - return getSystemProperty(JPA_JAR_PROPERTY) != null; - } - - public static boolean jpaJarFileExists() { - return (new File(getSystemProperty(JPA_JAR_PROPERTY))).exists(); - } - - public static boolean eclipselinkJarPropertyExists() { - return getSystemProperty(ECLIPSELINK_JAR_PROPERTY) != null; - } - - public static boolean eclipselinkJarFileExists() { - return (new File(getSystemProperty(ECLIPSELINK_JAR_PROPERTY))).exists(); - } - - public static String buildMissingJarErrorMessage() { - if( ! jpaJarPropertyExists()) { - return errorMissingProperty(JPA_JAR_PROPERTY); - } - else if( ! jpaJarFileExists()) { - return errorJarFileDoesNotExist(getSystemProperty(JPA_JAR_PROPERTY)); - } - else if( ! eclipselinkJarPropertyExists()) { - return errorMissingProperty(ECLIPSELINK_JAR_PROPERTY); - } - return errorJarFileDoesNotExist(getSystemProperty(ECLIPSELINK_JAR_PROPERTY)); - } - - /*********** private **********/ - - private static String errorMissingProperty(String propertyName) { - return "missing Java system property: \"" + propertyName + "\""; - } - - private static String errorJarFileDoesNotExist(String propertyValue) { - return "JAR file doesn't exist: \"" + propertyValue + "\""; - } - - private static String getSystemProperty(String propertyName) { - return System.getProperty(propertyName); - } - - private JptEclipseLinkCoreTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java deleted file mode 100644 index 02a8bb78b9..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkContextModelTestCase.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context; - -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaProject; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkEntity; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.platform.EclipseLinkPlatform; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public abstract class EclipseLinkContextModelTestCase - extends ContextModelTestCase -{ - protected EclipseLinkContextModelTestCase(String name) { - super(name); - } - - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(JpaFacetInstallDataModelProperties.PLATFORM, EclipseLinkPlatform.VERSION_1_0); - return dataModel; - } - - @Override - protected EclipseLinkJpaProject getJpaProject() { - return (EclipseLinkJpaProject) super.getJpaProject(); - } - - @Override - protected EclipseLinkPersistenceUnit getPersistenceUnit() { - return (EclipseLinkPersistenceUnit) super.getPersistenceUnit(); - } - - @Override - protected JavaEclipseLinkEntity getJavaEntity() { - return (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkJpaProjectTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkJpaProjectTests.java deleted file mode 100644 index e3dd79ac5e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/EclipseLinkJpaProjectTests.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context; - -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class EclipseLinkJpaProjectTests extends EclipseLinkContextModelTestCase -{ - - public EclipseLinkJpaProjectTests(String name) { - super(name); - } - - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - // don't build orm.xml - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.FALSE); - return dataModel; - } - - public void testGetDefaultOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - //add the orm.xml file with eclipselink orm content type - createDefaultOrmXmlFileWithEclipseLinkContentType(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - - //add the orm.xml file this time with orm content type - createDefaultOrmXmlFile(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - } - - public void testGetDefaultEclipseLinkOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNull(resource); - - //add the eclipselink-orm.xml file - createDefaultEclipseLinkOrmXmlFile(); - resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the eclipselink-orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNull(resource); - } - - private void createDefaultOrmXmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.getDefaultOperation().execute(null, null); - } - - private void createDefaultOrmXmlFileWithEclipseLinkContentType() throws Exception { - createEclipseLinkOrmXmlFile(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.lastSegment()); - } - - private void createDefaultEclipseLinkOrmXmlFile() throws Exception { - createEclipseLinkOrmXmlFile(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH.lastSegment()); - } - - private void createEclipseLinkOrmXmlFile(String fileName) throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, fileName); - config.getDefaultOperation().execute(null, null); - } - - public void testGetMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNull(resource); - - //add the eclipselink-orm.xml file - createDefaultEclipseLinkOrmXmlFile(); - resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the eclipselink-orm.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNull(resource); - } - - public void testGetDifferentlyNamedMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //create the orm2.xml file - createEclipseLinkOrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm2.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //add the orm2.xml file back - createEclipseLinkOrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLink1_0CoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLink1_0CoreContextModelTests.java deleted file mode 100644 index 1960a74cbe..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLink1_0CoreContextModelTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.java.JptEclipseLinkCoreJavaContextModelTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.orm.JptEclipseLinkCoreOrmContextModelTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.JptEclipseLinkCorePersistenceContextModelTests; - -public class JptEclipseLink1_0CoreContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink1_0CoreContextModelTests.class.getName()); - suite.addTestSuite(EclipseLinkJpaProjectTests.class); - suite.addTest(JptEclipseLinkCorePersistenceContextModelTests.suite()); - suite.addTest(JptEclipseLinkCoreJavaContextModelTests.suite()); - suite.addTest(JptEclipseLinkCoreOrmContextModelTests.suite()); - return suite; - } - - private JptEclipseLink1_0CoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLinkCoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLinkCoreContextModelTests.java deleted file mode 100644 index c0a16cde5c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/JptEclipseLinkCoreContextModelTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.eclipselink.core.tests.internal.JptEclipseLinkCoreTests; -import org.eclipse.jpt.eclipselink1_1.core.tests.internal.context.JptEclipseLink1_1CoreContextModelTests; -import org.eclipse.jpt.eclipselink1_2.core.tests.internal.context.JptEclipseLink1_2CoreContextModelTests; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.JptEclipseLink2_0CoreContextModelTests; - -/** - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar= - * -Dorg.eclipse.jpt.eclipselink.jar= - */ -public class JptEclipseLinkCoreContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreContextModelTests.class.getName()); - if(JptEclipseLinkCoreTests.requiredJarsExists()) { - suite.addTest(JptEclipseLink1_0CoreContextModelTests.suite()); - suite.addTest(JptEclipseLink1_1CoreContextModelTests.suite()); - suite.addTest(JptEclipseLink1_2CoreContextModelTests.suite()); - suite.addTest(JptEclipseLink2_0CoreContextModelTests.suite()); - } - else { - suite.addTest(TestSuite.warning(JptEclipseLinkCoreTests.buildMissingJarErrorMessage())); - } - return suite; - } - - private JptEclipseLinkCoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaBasicMappingTests.java deleted file mode 100644 index 97ae862a52..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaBasicMappingTests.java +++ /dev/null @@ -1,322 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkBasicMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMutable; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConvertAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkMutableAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaBasicMappingTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - } - }); - } - - - private ICompilationUnit createTestEntityWithConvert() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"class-instance\")").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableBasic() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, EclipseLink.MUTABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append("@Mutable").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableBasicDate() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, EclipseLink.MUTABLE, "java.util.Date"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Mutable").append(CR); - sb.append(" private Date myDate;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - public EclipseLinkJavaBasicMappingTests(String name) { - super(name); - } - - - public void testGetConvert() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(EclipseLinkConvert.class, basicMapping.getConverter().getType()); - } - - public void testGetConvert2() throws Exception { - createTestEntityWithConvert(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(EclipseLinkConvert.class, basicMapping.getConverter().getType()); - assertEquals(EclipseLinkConvert.CLASS_INSTANCE_CONVERTER, ((EclipseLinkConvert) basicMapping.getConverter()).getConverterName()); - } - - public void testSetConvert() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getConverter().getType()); - - basicMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - basicMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetConvertUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConvertAnnotation convert = (EclipseLinkConvertAnnotation) attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - convert.setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals(EclipseLinkConvert.class, basicMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) basicMapping.getConverter()).getConverterName()); - - attributeResource.removeAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getConverter().getType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getMapping()); - } - - public void testGetSpecifiedMutable() throws Exception { - createTestEntityWithMutableBasic(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkBasicMapping basicMapping = (EclipseLinkBasicMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = basicMapping.getMutable(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - mutableAnnotation.setValue(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - mutableAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - mutableAnnotation.setValue(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, mutable.getSpecifiedMutable()); - - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, mutable.getSpecifiedMutable()); - - attributeResource.addAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - } - - public void testSetSpecifiedMutable() throws Exception { - createTestEntityWithMutableBasic(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkBasicMapping basicMapping = (EclipseLinkBasicMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = basicMapping.getMutable(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(null, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertEquals(null, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(null); - mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(null, mutableAnnotation); - - mutable.setSpecifiedMutable(Boolean.FALSE); - mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - } - - public void testIsDefaultMutable() throws Exception { - createTestEntityWithMutableBasic(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkBasicMapping basicMapping = (EclipseLinkBasicMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = basicMapping.getMutable(); - assertTrue(mutable.isDefaultMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertTrue(mutable.isDefaultMutable()); - - mutable.setSpecifiedMutable(Boolean.FALSE); - assertTrue(mutable.isDefaultMutable()); - - //set mutable default to false in the persistence unit properties, verify default in java still true since this is not a Date/Calendar - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.FALSE); - assertTrue(mutable.isDefaultMutable()); - } - - public void testIsDefaultMutableForDate() throws Exception { - createTestEntityWithMutableBasicDate(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkBasicMapping basicMapping = (EclipseLinkBasicMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = basicMapping.getMutable(); - assertFalse(mutable.isDefaultMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertFalse(mutable.isDefaultMutable()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertFalse(mutable.isDefaultMutable()); - - //set mutable default to false in the persistence unit properties, verify default in java still true since this is not a Date/Calendar - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.TRUE); - assertTrue(mutable.isDefaultMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.FALSE); - assertFalse(mutable.isDefaultMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(null); - assertFalse(mutable.isDefaultMutable()); - } - - public void testIsMutable() throws Exception { - createTestEntityWithMutableBasic(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkBasicMapping basicMapping = (EclipseLinkBasicMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = basicMapping.getMutable(); - assertTrue(mutable.isMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertTrue(mutable.isMutable()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertTrue(mutable.isMutable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaCachingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaCachingTests.java deleted file mode 100644 index 42d7bf7106..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaCachingTests.java +++ /dev/null @@ -1,646 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheCoordinationType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTimeOfDay; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkExistenceType; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkEntity; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCacheAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkExistenceCheckingAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaCachingTests extends EclipseLinkContextModelTestCase -{ - public EclipseLinkJavaCachingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - public void testSetSpecifiedShared() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(true, caching.isShared()); - - caching.setSpecifiedShared(Boolean.FALSE); - - - assertEquals(Boolean.FALSE, entity.getCaching().getSpecifiedShared()); - assertEquals(false, entity.getCaching().isShared()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(Boolean.FALSE, cacheAnnotation.getShared()); - } - - public void testSetSpecifiedSharedFalseUnsetsOtherCacheSettings() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - caching.setSpecifiedType(EclipseLinkCacheType.HARD_WEAK); - caching.setSpecifiedSize(Integer.valueOf(500)); - caching.setSpecifiedAlwaysRefresh(Boolean.FALSE); - caching.setSpecifiedRefreshOnlyIfNewer(Boolean.FALSE); - caching.setSpecifiedDisableHits(Boolean.FALSE); - caching.setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - caching.setExistenceChecking(true); - caching.setSpecifiedExistenceType(EclipseLinkExistenceType.CHECK_CACHE); - caching.setExpiry(Integer.valueOf(8000)); - - caching.setSpecifiedShared(Boolean.FALSE); - - assertEquals(null, caching.getSpecifiedType()); - assertEquals(null, caching.getSpecifiedSize()); - assertEquals(null, caching.getSpecifiedAlwaysRefresh()); - assertEquals(null, caching.getSpecifiedRefreshOnlyIfNewer()); - assertEquals(null, caching.getSpecifiedDisableHits()); - assertEquals(null, caching.getSpecifiedCoordinationType()); - assertEquals(null, caching.getExpiry()); - - - //existence checking is the only thing that isn't unset when shared is set to false - assertTrue(caching.isExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_CACHE, caching.getSpecifiedExistenceType()); - - caching.setSpecifiedShared(null); - EclipseLinkTimeOfDay timeOfDayExpiry = caching.addExpiryTimeOfDay(); - timeOfDayExpiry.setHour(Integer.valueOf(5)); - - caching.setSpecifiedShared(Boolean.FALSE); - assertNull(caching.getExpiryTimeOfDay()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(Boolean.FALSE, cacheAnnotation.getShared()); - assertNull(cacheAnnotation.getExpiryTimeOfDay()); - } - - public void testGetSpecifiedShared() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(true, caching.isShared()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.setShared(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, cacheAnnotation.getShared()); - assertEquals(Boolean.FALSE, entity.getCaching().getSpecifiedShared()); - assertEquals(false, entity.getCaching().isShared()); - } - - public void testSetSpecifiedType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(EclipseLinkCacheType.SOFT_WEAK, caching.getType()); - - caching.setSpecifiedType(EclipseLinkCacheType.HARD_WEAK); - - - assertEquals(EclipseLinkCacheType.HARD_WEAK, entity.getCaching().getSpecifiedType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, entity.getCaching().getType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.HARD_WEAK, cacheAnnotation.getType()); - - - //set specified type to the same as the default, verify it is not set to default - caching.setSpecifiedType(EclipseLinkCacheType.SOFT_WEAK); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, caching.getSpecifiedType()); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.SOFT_WEAK, cacheAnnotation.getType()); - - caching.setSpecifiedType(null); - assertNull(caching.getSpecifiedType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, caching.getType()); - } - - public void testGetSpecifiedType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(EclipseLinkCacheType.SOFT_WEAK, caching.getType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.setType(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.HARD_WEAK); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheType.HARD_WEAK, cacheAnnotation.getType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, entity.getCaching().getSpecifiedType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, entity.getCaching().getType()); - } - - public void testSetSpecifiedAlwaysRefresh() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(false, caching.isAlwaysRefresh()); - - caching.setSpecifiedAlwaysRefresh(Boolean.FALSE); - - - assertEquals(Boolean.FALSE, entity.getCaching().getSpecifiedAlwaysRefresh()); - assertEquals(false, entity.getCaching().isAlwaysRefresh()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(Boolean.FALSE, cacheAnnotation.getAlwaysRefresh()); - } - - public void testGetSpecifiedAlwaysRefresh() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(false, caching.isAlwaysRefresh()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.setAlwaysRefresh(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, cacheAnnotation.getAlwaysRefresh()); - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedAlwaysRefresh()); - assertEquals(true, entity.getCaching().isAlwaysRefresh()); - } - - public void testSetSpecifiedRefreshOnlyIfNewer() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(false, caching.isRefreshOnlyIfNewer()); - - caching.setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - - - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedRefreshOnlyIfNewer()); - assertEquals(true, entity.getCaching().isRefreshOnlyIfNewer()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(Boolean.TRUE, cacheAnnotation.getRefreshOnlyIfNewer()); - } - - public void testGetSpecifiedRefreshOnlyIfNewer() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(false, caching.isRefreshOnlyIfNewer()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.setRefreshOnlyIfNewer(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, cacheAnnotation.getRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedRefreshOnlyIfNewer()); - assertEquals(true, entity.getCaching().isRefreshOnlyIfNewer()); - } - - public void testSetSpecifiedDisableHits() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(false, caching.isDisableHits()); - - caching.setSpecifiedDisableHits(Boolean.TRUE); - - - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedDisableHits()); - assertEquals(true, entity.getCaching().isDisableHits()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(Boolean.TRUE, cacheAnnotation.getDisableHits()); - } - - public void testGetSpecifiedDisableHits() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(false, caching.isDisableHits()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.setDisableHits(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, cacheAnnotation.getDisableHits()); - assertEquals(Boolean.TRUE, entity.getCaching().getSpecifiedDisableHits()); - assertEquals(true, entity.getCaching().isDisableHits()); - } - - public void testSetSpecifiedCoordinationType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, caching.getCoordinationType()); - - caching.setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - - - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getSpecifiedCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getCoordinationType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cacheAnnotation.getCoordinationType()); - - - //set specified coordination type to the same as the default, verify it is not set to default - caching.setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, caching.getSpecifiedCoordinationType()); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.SEND_OBJECT_CHANGES, cacheAnnotation.getCoordinationType()); - - caching.setSpecifiedCoordinationType(null); - assertNull(caching.getSpecifiedCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, caching.getCoordinationType()); - } - - public void testGetSpecifiedCoordinationType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, caching.getCoordinationType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.setCoordinationType(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cacheAnnotation.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getSpecifiedCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, entity.getCaching().getCoordinationType()); - } - - public void testHasExistenceChecking() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(false, caching.isExistenceChecking()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(EclipseLink.EXISTENCE_CHECKING); - getJpaProject().synchronizeContextModel(); - assertEquals(true, caching.isExistenceChecking()); - - typeResource.removeAnnotation(EclipseLink.EXISTENCE_CHECKING); - getJpaProject().synchronizeContextModel(); - assertEquals(false, caching.isExistenceChecking()); - } - - public void testSetExistenceChecking() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(false, caching.isExistenceChecking()); - assertNull(typeResource.getAnnotation(EclipseLink.EXISTENCE_CHECKING)); - - caching.setExistenceChecking(true); - - assertEquals(true, caching.isExistenceChecking()); - assertNotNull(typeResource.getAnnotation(EclipseLink.EXISTENCE_CHECKING)); - } - - public void testGetDefaultExistenceType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, caching.getDefaultExistenceType()); - - caching.setExistenceChecking(true); - assertEquals(EclipseLinkExistenceType.CHECK_CACHE, caching.getDefaultExistenceType()); - } - - public void testGetSpecifiedExistenceType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, caching.getExistenceType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkExistenceCheckingAnnotation existenceCheckingAnnotation = (EclipseLinkExistenceCheckingAnnotation) typeResource.addAnnotation(EclipseLink.EXISTENCE_CHECKING); - existenceCheckingAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.ASSUME_NON_EXISTENCE); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.ASSUME_NON_EXISTENCE, existenceCheckingAnnotation.getValue()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getSpecifiedExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getExistenceType()); - } - - public void testSetSpecifiedExistenceType() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, caching.getExistenceType()); - - caching.setExistenceChecking(true); - caching.setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE); - - - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getSpecifiedExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, entity.getCaching().getExistenceType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkExistenceCheckingAnnotation existenceCheckingAnnotation = (EclipseLinkExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLink.EXISTENCE_CHECKING); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.ASSUME_NON_EXISTENCE, existenceCheckingAnnotation.getValue()); - - - //set specified coordination type to the same as the default, verify it is not set to default - caching.setSpecifiedExistenceType(EclipseLinkExistenceType.CHECK_DATABASE); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, caching.getSpecifiedExistenceType()); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType.CHECK_DATABASE, existenceCheckingAnnotation.getValue()); - - caching.setSpecifiedExistenceType(null); - assertNull(caching.getSpecifiedExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_CACHE, caching.getExistenceType()); - } - - public void testGetExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - - assertNull(entity.getCaching().getExpiry()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - assertNull(entity.getCaching().getExpiry()); - - cacheAnnotation.setExpiry(Integer.valueOf(57)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(57), entity.getCaching().getExpiry()); - - typeResource.removeAnnotation(EclipseLink.CACHE); - getJpaProject().synchronizeContextModel(); - assertNull(entity.getCaching().getExpiry()); - } - - public void testSetExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - caching.setExpiry(Integer.valueOf(58)); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Integer.valueOf(58), cacheAnnotation.getExpiry()); - - - caching.setExpiry(null); - cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertNull(cacheAnnotation.getExpiry()); - } - - public void testSetExpiryUnsetsExpiryTimeOfDay() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - caching.addExpiryTimeOfDay(); - caching.getExpiryTimeOfDay().setHour(Integer.valueOf(5)); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Integer.valueOf(5), cacheAnnotation.getExpiryTimeOfDay().getHour()); - - caching.setExpiry(Integer.valueOf(900)); - - assertNull(caching.getExpiryTimeOfDay()); - assertNull(cacheAnnotation.getExpiryTimeOfDay()); - assertEquals(Integer.valueOf(900), cacheAnnotation.getExpiry()); - assertEquals(Integer.valueOf(900), caching.getExpiry()); - } - - public void testGetTimeOfDayExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertNull(caching.getExpiryTimeOfDay()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - - cacheAnnotation.addExpiryTimeOfDay(); - getJpaProject().synchronizeContextModel(); - - assertNotNull(caching.getExpiryTimeOfDay()); - } - - public void testAddTimeOfDayExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertNull(caching.getExpiryTimeOfDay()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkTimeOfDay timeOfDayExpiry = caching.addExpiryTimeOfDay(); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertNotNull(cacheAnnotation.getExpiryTimeOfDay()); - assertNotNull(caching.getExpiryTimeOfDay()); - assertEquals(timeOfDayExpiry, caching.getExpiryTimeOfDay()); - } - - public void testRemoveTimeOfDayExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertNull(caching.getExpiryTimeOfDay()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.addExpiryTimeOfDay(); - getJpaProject().synchronizeContextModel(); - - assertNotNull(caching.getExpiryTimeOfDay()); - - caching.removeExpiryTimeOfDay(); - getJpaProject().synchronizeContextModel(); - assertNull(caching.getExpiryTimeOfDay()); - } - - public void testAddTimeOfDayExpiryUnsetsExpiry() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - caching.setExpiry(Integer.valueOf(800)); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Integer.valueOf(800), cacheAnnotation.getExpiry()); - - - caching.addExpiryTimeOfDay(); - - - assertNull(caching.getExpiry()); - assertNull(cacheAnnotation.getExpiry()); - assertNotNull(cacheAnnotation.getExpiryTimeOfDay()); - } - - - public void testSetSpecifiedSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(100, caching.getSize()); - - caching.setSpecifiedSize(new Integer(50)); - - - assertEquals(new Integer(50), entity.getCaching().getSpecifiedSize()); - assertEquals(50, entity.getCaching().getSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertEquals(new Integer(50), cacheAnnotation.getSize()); - } - - public void testGetSpecifiedSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEclipseLinkEntity entity = (JavaEclipseLinkEntity) getJavaPersistentType().getMapping(); - JavaEclipseLinkCaching caching = entity.getCaching(); - - assertEquals(100, caching.getSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCacheAnnotation cacheAnnotation = (EclipseLinkCacheAnnotation) typeResource.addAnnotation(EclipseLink.CACHE); - cacheAnnotation.setSize(new Integer(50)); - getJpaProject().synchronizeContextModel(); - - assertEquals(new Integer(50), cacheAnnotation.getSize()); - assertEquals(new Integer(50), entity.getCaching().getSpecifiedSize()); - assertEquals(50, entity.getCaching().getSize()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConvertTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConvertTests.java deleted file mode 100644 index 7439b18e0f..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConvertTests.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConvertAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkStructConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkTypeConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaConvertTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - } - }); - } - - - private ICompilationUnit createTestEntityWithConvert() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"class-instance\")").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndTypeConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"class-instance\")").append(CR); - sb.append(" @TypeConverter"); - } - }); - } - - public EclipseLinkJavaConvertTests(String name) { - super(name); - } - - - public void testGetConverterName() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - - assertEquals(EclipseLinkConvert.NO_CONVERTER, eclipseLinkConvert.getConverterName()); - assertEquals(EclipseLinkConvert.NO_CONVERTER, eclipseLinkConvert.getDefaultConverterName()); - assertEquals(null, eclipseLinkConvert.getSpecifiedConverterName()); - } - - public void testGetConvertName2() throws Exception { - createTestEntityWithConvert(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - - assertEquals(EclipseLinkConvert.CLASS_INSTANCE_CONVERTER, eclipseLinkConvert.getConverterName()); - } - - public void testSetSpecifiedConverterName() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - basicMapping.setConverter(EclipseLinkConvert.class); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - assertEquals(null, eclipseLinkConvert.getSpecifiedConverterName()); - - eclipseLinkConvert.setSpecifiedConverterName("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConvertAnnotation convertAnnotation = (EclipseLinkConvertAnnotation) attributeResource.getAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - - assertEquals("foo", convertAnnotation.getValue()); - - eclipseLinkConvert.setSpecifiedConverterName(null); - convertAnnotation = (EclipseLinkConvertAnnotation) attributeResource.getAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - assertNotNull(convertAnnotation); - assertEquals(null, convertAnnotation.getValue()); - } - - public void testGetConverterNameUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertNull(basicMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConvertAnnotation convert = (EclipseLinkConvertAnnotation) attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - convert.setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals(EclipseLinkConvert.class, basicMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) basicMapping.getConverter()).getConverterName()); - - attributeResource.removeAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(basicMapping.getConverter().getType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getMapping()); - } - - - public void testGetConverter() throws Exception { - createTestEntityWithConvertAndTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - - assertEquals(EclipseLinkTypeConverter.class, eclipseLinkConvert.getConverter().getType()); - } - - public void testSetConverter() throws Exception { - createTestEntityWithConvert(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - - assertEquals(null, eclipseLinkConvert.getConverter()); - - eclipseLinkConvert.setConverter(EclipseLinkTypeConverter.class); - assertEquals(EclipseLinkTypeConverter.class, eclipseLinkConvert.getConverter().getType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME)); - - eclipseLinkConvert.setConverter(EclipseLinkStructConverter.class); - assertEquals(EclipseLinkStructConverter.class, eclipseLinkConvert.getConverter().getType()); - assertNotNull(attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME)); - - eclipseLinkConvert.setConverter(null); - assertEquals(null, eclipseLinkConvert.getConverter()); - assertNull(attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME)); - - eclipseLinkConvert.setConverter(EclipseLinkStructConverter.class); - assertEquals(EclipseLinkStructConverter.class, eclipseLinkConvert.getConverter().getType()); - assertNotNull(attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME)); - - - basicMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME)); - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConverterTests.java deleted file mode 100644 index f8375a5675..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaConverterTests.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaConverterTests extends EclipseLinkContextModelTestCase -{ - - - private ICompilationUnit createTestEntityWithConvertAndConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @Converter(name=\"foo\""); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndConverterClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @Converter(converterClass=Foo.class"); - } - }); - } - - public EclipseLinkJavaConverterTests(String name) { - super(name); - } - - - public void testGetName() throws Exception { - createTestEntityWithConvertAndConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkCustomConverter converter = (EclipseLinkCustomConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithConvertAndConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkCustomConverter converter = (EclipseLinkCustomConverter) eclipseLinkConvert.getConverter(); - assertEquals("foo", converter.getName()); - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConverterAnnotation converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - - - converter.setName(null); - assertEquals(null, converter.getName()); - converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getName()); - - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - } - - public void testGetNameUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkCustomConverter converter = (EclipseLinkCustomConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConverterAnnotation converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", converter.getName()); - - attributeResource.removeAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.addAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", eclipseLinkConvert.getConverter().getName()); - } - - - public void testGetConverterClass() throws Exception { - createTestEntityWithConvertAndConverterClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkCustomConverter converter = (EclipseLinkCustomConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getConverterClass()); - } - - public void testSetConverterClass() throws Exception { - createTestEntityWithConvertAndConverterClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkCustomConverter converter = (EclipseLinkCustomConverter) eclipseLinkConvert.getConverter(); - assertEquals("Foo", converter.getConverterClass()); - - converter.setConverterClass("Bar"); - assertEquals("Bar", converter.getConverterClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConverterAnnotation converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getConverterClass()); - - - converter.setConverterClass(null); - assertEquals(null, converter.getConverterClass()); - converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getConverterClass()); - - - converter.setConverterClass("Bar"); - assertEquals("Bar", converter.getConverterClass()); - converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getConverterClass()); - } - - public void testGetConverterClassUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndConverterClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkCustomConverter converter = (EclipseLinkCustomConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getConverterClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConverterAnnotation converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setConverterClass("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", converter.getConverterClass()); - - attributeResource.removeAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkConverterAnnotation) attributeResource.addAnnotation(EclipseLinkConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setConverterClass("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", ((EclipseLinkCustomConverter) eclipseLinkConvert.getConverter()).getConverterClass()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEmbeddableTests.java deleted file mode 100644 index d0153ca08a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEmbeddableTests.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTracking; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomizer; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkEmbeddable; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkChangeTrackingAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCustomizerAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaEmbeddableTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEmbeddableWithConvertAndCustomizerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE, EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - sb.append(" @Customizer(Foo.class"); - } - }); - } - - private ICompilationUnit createTestEmbeddableWithChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE, EclipseLink.CHANGE_TRACKING); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - sb.append(" @ChangeTracking").append(CR); - } - }); - } - - public EclipseLinkJavaEmbeddableTests(String name) { - super(name); - } - - - public void testGetCustomizerClass() throws Exception { - createTestEmbeddableWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkEmbeddable) getJavaPersistentType().getMapping()).getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - } - - public void testSetCustomizerClass() throws Exception { - createTestEmbeddableWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkEmbeddable) getJavaPersistentType().getMapping()).getCustomizer(); - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - - - customizer.setSpecifiedCustomizerClass(null); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals(null, customizerAnnotation); - - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - } - - public void testGetCustomizerClassUpdatesFromResourceModelChange() throws Exception { - createTestEmbeddableWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkEmbeddable embeddable = (EclipseLinkEmbeddable) getJavaPersistentType().getMapping(); - EclipseLinkCustomizer customizer = embeddable.getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - customizerAnnotation.setValue("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - typeResource.removeAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.addAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation.setValue("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", customizer.getSpecifiedCustomizerClass()); - } - - public void testGetChangeTracking() throws Exception { - createTestEmbeddableWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEmbeddable embeddable = (EclipseLinkEmbeddable) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = embeddable.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change resource to ATTRIBUTE specifically, test context - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change resource to OBJECT specifically, test context - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change resource to DEFERRED specifically, test context - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change resource to AUTO specifically, test context - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove value from resource, test context - resourceChangeTracking.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove annotation, text context - typeResource.removeAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertNull(contextChangeTracking.getSpecifiedType()); - } - - public void testSetChangeTracking() throws Exception { - createTestEmbeddableWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEmbeddable embeddable = (EclipseLinkEmbeddable) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = embeddable.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to ATTRIBUTE specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change context to OBJECT specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change context to DEFERRED specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change context to null, test resource - - contextChangeTracking.setSpecifiedType(null); - - assertNull(typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME)); - assertNull(contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically (this time from no annotation), test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEntityTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEntityTests.java deleted file mode 100644 index c875fdde36..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaEntityTests.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.EclipseLinkMappingKeys; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTracking; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomizer; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkEntity; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkReadOnly; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkChangeTrackingAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCustomizerAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkReadOnlyAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaEntityTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndCustomizerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append(" @Customizer(Foo.class"); - } - }); - } - - private ICompilationUnit createTestEntityWithChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CHANGE_TRACKING); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append(" @ChangeTracking").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithReadOnly() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.READ_ONLY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@ReadOnly").append(CR); - } - }); - } - - public EclipseLinkJavaEntityTests(String name) { - super(name); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) getJavaPersistentType().getMapping(); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.BASIC_COLLECTION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.BASIC_MAP_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.TRANSFORMATION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.VARIABLE_ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - } - - - public void testGetCustomizerClass() throws Exception { - createTestEntityWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkEntity) getJavaPersistentType().getMapping()).getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - } - - public void testSetCustomizerClass() throws Exception { - createTestEntityWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkEntity) getJavaPersistentType().getMapping()).getCustomizer(); - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - - - customizer.setSpecifiedCustomizerClass(null); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals(null, customizerAnnotation); - - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - } - - public void testGetCustomizerClassUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkEntity entity = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkCustomizer customizer = entity.getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - customizerAnnotation.setValue("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - typeResource.removeAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.addAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation.setValue("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", customizer.getSpecifiedCustomizerClass()); - } - - public void testGetChangeTracking() throws Exception { - createTestEntityWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity entity = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = entity.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change resource to ATTRIBUTE specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change resource to OBJECT specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change resource to DEFERRED specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change resource to AUTO specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove value from resource, test context - - resourceChangeTracking.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove annotation, text context - - typeResource.removeAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertNull(contextChangeTracking.getSpecifiedType()); - } - - public void testSetChangeTracking() throws Exception { - createTestEntityWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity entity = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = entity.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to ATTRIBUTE specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change context to OBJECT specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change context to DEFERRED specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change context to null, test resource - - contextChangeTracking.setSpecifiedType(null); - - assertNull(typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME)); - assertNull(contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically (this time from no annotation), test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - } - - public void testGetReadOnly() throws Exception { - createTestEntityWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity mappedSuperclass = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(true, readOnly.isReadOnly()); - } - - public void testGetSpecifiedReadOnly() throws Exception { - createTestEntityWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity mappedSuperclass = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - } - - //TODO test inheriting a default readonly from you superclass - public void testGetDefaultReadOnly() throws Exception { - createTestEntityWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity mappedSuperclass = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(false, readOnly.isDefaultReadOnly()); - } - - public void testSetSpecifiedReadOnly() throws Exception { - createTestEntityWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity mappedSuperclass = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(true, readOnly.isReadOnly()); - - readOnly.setSpecifiedReadOnly(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertNull(readOnly.getSpecifiedReadOnly());//Boolean.FALSE and null really mean the same thing since there are only 2 states in the java resource model - - readOnly.setSpecifiedReadOnly(Boolean.TRUE); - assertNotNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - - readOnly.setSpecifiedReadOnly(null); - assertNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertNull(readOnly.getSpecifiedReadOnly());//Boolean.FALSE and null really mean the same thing since there are only 2 states in the java resource model - } - - public void testSpecifiedReadOnlyUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity mappedSuperclass = (EclipseLinkEntity) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.removeAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(readOnly.getSpecifiedReadOnly()); - assertEquals(false, readOnly.isDefaultReadOnly()); - - typeResource.addAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - } - - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaIdMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaIdMappingTests.java deleted file mode 100644 index 23f1191f22..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaIdMappingTests.java +++ /dev/null @@ -1,323 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkIdMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMutable; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConvertAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkMutableAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaIdMappingTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - } - }); - } - - - private ICompilationUnit createTestEntityWithConvert() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, EclipseLink.CONVERT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@Convert(\"class-instance\")").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableId() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, EclipseLink.MUTABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@Mutable").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableIdDate() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, EclipseLink.MUTABLE, "java.util.Date"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append(" @Mutable").append(CR); - sb.append(" private Date myDate;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - public EclipseLinkJavaIdMappingTests(String name) { - super(name); - } - - - public void testGetConvert() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertEquals(EclipseLinkConvert.class, idMapping.getConverter().getType()); - } - - public void testGetConvert2() throws Exception { - createTestEntityWithConvert(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertEquals(EclipseLinkConvert.class, idMapping.getConverter().getType()); - assertEquals(EclipseLinkConvert.CLASS_INSTANCE_CONVERTER, ((EclipseLinkConvert) idMapping.getConverter()).getConverterName()); - } - - public void testSetConvert() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertNull(idMapping.getConverter().getType()); - - idMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - idMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetConvertUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - - assertNull(idMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConvertAnnotation convert = (EclipseLinkConvertAnnotation) attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - convert.setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals(EclipseLinkConvert.class, idMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) idMapping.getConverter()).getConverterName()); - - attributeResource.removeAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(idMapping.getConverter().getType()); - assertFalse(idMapping.isDefault()); - assertSame(idMapping, persistentAttribute.getMapping()); - } - - public void testGetSpecifiedMutable() throws Exception { - createTestEntityWithMutableId(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkIdMapping idMapping = (EclipseLinkIdMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = idMapping.getMutable(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - mutableAnnotation.setValue(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - mutableAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - mutableAnnotation.setValue(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, mutable.getSpecifiedMutable()); - - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, mutable.getSpecifiedMutable()); - - attributeResource.addAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - } - - public void testSetSpecifiedMutable() throws Exception { - createTestEntityWithMutableId(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkIdMapping idMapping = (EclipseLinkIdMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = idMapping.getMutable(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(null, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertEquals(null, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(null); - mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(null, mutableAnnotation); - - mutable.setSpecifiedMutable(Boolean.FALSE); - mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - } - - public void testIsDefaultMutable() throws Exception { - createTestEntityWithMutableId(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkIdMapping idMapping = (EclipseLinkIdMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = idMapping.getMutable(); - assertTrue(mutable.isDefaultMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertTrue(mutable.isDefaultMutable()); - - mutable.setSpecifiedMutable(Boolean.FALSE); - assertTrue(mutable.isDefaultMutable()); - - //set mutable default to false in the persistence unit properties, verify default in java still true since this is not a Date/Calendar - (getPersistenceUnit()).getOptions().setTemporalMutable(Boolean.FALSE); - assertTrue(mutable.isDefaultMutable()); - } - - public void testIsDefaultMutableForDate() throws Exception { - createTestEntityWithMutableIdDate(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkIdMapping idMapping = (EclipseLinkIdMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = idMapping.getMutable(); - assertFalse(mutable.isDefaultMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertFalse(mutable.isDefaultMutable()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertFalse(mutable.isDefaultMutable()); - - //set mutable default to false in the persistence unit properties, verify default in java still true since this is not a Date/Calendar - (getPersistenceUnit()).getOptions().setTemporalMutable(Boolean.TRUE); - assertTrue(mutable.isDefaultMutable()); - - (getPersistenceUnit()).getOptions().setTemporalMutable(Boolean.FALSE); - assertFalse(mutable.isDefaultMutable()); - - (getPersistenceUnit()).getOptions().setTemporalMutable(null); - assertFalse(mutable.isDefaultMutable()); - } - - public void testIsMutable() throws Exception { - createTestEntityWithMutableId(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkIdMapping idMapping = (EclipseLinkIdMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = idMapping.getMutable(); - assertTrue(mutable.isMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertTrue(mutable.isMutable()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertTrue(mutable.isMutable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToManyMappingTests.java deleted file mode 100644 index 66ca64a76c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToManyMappingTests.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetch; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJoinFetchAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - - -@SuppressWarnings("nls") -public class EclipseLinkJavaManyToManyMappingTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithJoinFetchManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, EclipseLink.JOIN_FETCH); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - sb.append("@JoinFetch").append(CR); - } - }); - } - - public EclipseLinkJavaManyToManyMappingTests(String name) { - super(name); - } - - - public void testGetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to INNER specifically, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to OUTER, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // remove value from resource, test context - - joinFetchAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // remove annotation, text context - - attributeResource.removeAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertNull(contextJoinFetch.getValue()); - } - - public void testSetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to INNER specifically, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to OUTER, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // set context to null, test resource - - contextJoinFetch.setValue(null); - - assertNull(attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME)); - assertNull(contextJoinFetch.getValue()); - - // change context to INNER specifically (this time from no annotation), test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToOneMappingTests.java deleted file mode 100644 index 922c46221d..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToOneMappingTests.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetch; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJoinFetchAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaManyToOneMappingTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithJoinFetchManyToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, EclipseLink.JOIN_FETCH); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - sb.append("@JoinFetch").append(CR); - } - }); - } - - public EclipseLinkJavaManyToOneMappingTests(String name) { - super(name); - } - - - public void testGetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchManyToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to INNER specifically, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to OUTER, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // remove value from resource, test context - - joinFetchAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // remove annotation, text context - - attributeResource.removeAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertNull(contextJoinFetch.getValue()); - } - - public void testSetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchManyToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to INNER specifically, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to OUTER, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // set context to null, test resource - - contextJoinFetch.setValue(null); - - assertNull(attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME)); - assertNull(contextJoinFetch.getValue()); - - // change context to INNER specifically (this time from no annotation), test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaMappedSuperclassTests.java deleted file mode 100644 index 792b1b65d4..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaMappedSuperclassTests.java +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTracking; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomizer; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkReadOnly; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkChangeTrackingAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCustomizerAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkReadOnlyAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaMappedSuperclassTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestMappedSuperclassWithReadOnly() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.READ_ONLY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - sb.append("@ReadOnly").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassWithConvertAndCustomizerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - sb.append(" @Customizer(Foo.class"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassWithChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CHANGE_TRACKING); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - sb.append(" @ChangeTracking").append(CR); - } - }); - } - - public EclipseLinkJavaMappedSuperclassTests(String name) { - super(name); - } - - - public void testGetReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(true, readOnly.isReadOnly()); - } - - public void testGetSpecifiedReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - } - - //TODO test inheriting a default readonly from you superclass - public void testGetDefaultReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(false, readOnly.isDefaultReadOnly()); - } - - public void testSetSpecifiedReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(true, readOnly.isReadOnly()); - - readOnly.setSpecifiedReadOnly(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertNull(readOnly.getSpecifiedReadOnly());//Boolean.FALSE and null really mean the same thing since there are only 2 states in the java resource model - - readOnly.setSpecifiedReadOnly(Boolean.TRUE); - assertNotNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - - readOnly.setSpecifiedReadOnly(null); - assertNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertNull(readOnly.getSpecifiedReadOnly());//Boolean.FALSE and null really mean the same thing since there are only 2 states in the java resource model - } - - public void testSpecifiedReadOnlyUpdatesFromResourceModelChange() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.removeAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(readOnly.getSpecifiedReadOnly()); - assertEquals(false, readOnly.isDefaultReadOnly()); - - typeResource.addAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - } - - public void testGetCustomizerClass() throws Exception { - createTestMappedSuperclassWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping()).getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - } - - public void testSetCustomizerClass() throws Exception { - createTestMappedSuperclassWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping()).getCustomizer(); - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - - - customizer.setSpecifiedCustomizerClass(null); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals(null, customizerAnnotation); - - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - } - - public void testGetCustomizerClassUpdatesFromResourceModelChange() throws Exception { - createTestMappedSuperclassWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkCustomizer customizer = mappedSuperclass.getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - customizerAnnotation.setValue("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - typeResource.removeAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.addAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation.setValue("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", customizer.getSpecifiedCustomizerClass()); - } - - public void testGetChangeTracking() throws Exception { - createTestMappedSuperclassWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = mappedSuperclass.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change resource to ATTRIBUTE specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change resource to OBJECT specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change resource to DEFERRED specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change resource to AUTO specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove value from resource, test context - - resourceChangeTracking.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove annotation, text context - - typeResource.removeAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertNull(contextChangeTracking.getSpecifiedType()); - } - - public void testSetChangeTracking() throws Exception { - createTestMappedSuperclassWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = mappedSuperclass.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to ATTRIBUTE specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change context to OBJECT specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change context to DEFERRED specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change context to null, test resource - - contextChangeTracking.setSpecifiedType(null); - - assertNull(typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME)); - assertNull(contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically (this time from no annotation), test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaObjectTypeConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaObjectTypeConverterTests.java deleted file mode 100644 index 70097ad2a3..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaObjectTypeConverterTests.java +++ /dev/null @@ -1,644 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConversionValue; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConversionValueAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkObjectTypeConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaObjectTypeConverterTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithConvertAndObjectTypeConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.OBJECT_TYPE_CONVERTER, EclipseLink.CONVERSION_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @ObjectTypeConverter(name=\"foo\", defaultObjectValue=\"bar\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndDataType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @ObjectTypeConverter(dataType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndObjectType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @ObjectTypeConverter(objectType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndObjectTypeConverterConversionValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.OBJECT_TYPE_CONVERTER, EclipseLink.CONVERSION_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @ObjectTypeConverter(name=\"foo\", defaultObjectValue=\"bar\", conversionValues = @ConversionValue(dataValue=\"f\", objectValue=\"female\"))"); - } - }); - } - - public EclipseLinkJavaObjectTypeConverterTests(String name) { - super(name); - } - - - public void testGetName() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - assertEquals("foo", converter.getName()); - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - - - converter.setName(null); - assertEquals(null, converter.getName()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getName()); - - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - } - - public void testGetNameUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", converter.getName()); - - attributeResource.removeAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.addAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", eclipseLinkConvert.getConverter().getName()); - } - - public void testGetDataType() throws Exception { - createTestEntityWithConvertAndDataType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getDataType()); - } - - public void testSetDataType() throws Exception { - createTestEntityWithConvertAndDataType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getDataType()); - - - converter.setDataType(null); - assertEquals(null, converter.getDataType()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getDataType()); - - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getDataType()); - } - - public void testGetDataTypeUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndDataType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getDataType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setDataType("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", converter.getDataType()); - - attributeResource.removeAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.addAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setDataType("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", ((EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter()).getDataType()); - } - - public void testGetObjectType() throws Exception { - createTestEntityWithConvertAndObjectType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getObjectType()); - } - - public void testSetObjectType() throws Exception { - createTestEntityWithConvertAndObjectType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getObjectType()); - - - converter.setObjectType(null); - assertEquals(null, converter.getObjectType()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getObjectType()); - - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getObjectType()); - } - - public void testGetObjectTypeUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndObjectType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getObjectType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setObjectType("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", converter.getObjectType()); - - attributeResource.removeAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.addAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setObjectType("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", ((EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter()).getObjectType()); - } - - - public void testAddConversionValue() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - - EclipseLinkConversionValue conversionValue = converter.addConversionValue(0); - conversionValue.setDataValue("F"); - conversionValue.setObjectValue("female"); - - ListIterator resourceConversionValues = converterAnnotation.conversionValues(); - EclipseLinkConversionValueAnnotation resourceConversionValue = resourceConversionValues.next(); - assertEquals("F", resourceConversionValue.getDataValue()); - assertEquals("female", resourceConversionValue.getObjectValue()); - - EclipseLinkConversionValue conversionValue2 = converter.addConversionValue(0); - conversionValue2.setDataValue("M"); - conversionValue2.setObjectValue("male"); - - resourceConversionValues = converterAnnotation.conversionValues(); - resourceConversionValue = resourceConversionValues.next(); - assertEquals("M", resourceConversionValue.getDataValue()); - assertEquals("male", resourceConversionValue.getObjectValue()); - resourceConversionValue = resourceConversionValues.next(); - assertEquals("F", resourceConversionValue.getDataValue()); - assertEquals("female", resourceConversionValue.getObjectValue()); - - EclipseLinkConversionValue conversionValue3 = converter.addConversionValue(1); - conversionValue3.setDataValue("O"); - conversionValue3.setObjectValue("male"); - - resourceConversionValues = converterAnnotation.conversionValues(); - resourceConversionValue = resourceConversionValues.next(); - assertEquals("M", resourceConversionValue.getDataValue()); - assertEquals("male", resourceConversionValue.getObjectValue()); - resourceConversionValue = resourceConversionValues.next(); - assertEquals("O", resourceConversionValue.getDataValue()); - assertEquals("male", resourceConversionValue.getObjectValue()); - resourceConversionValue = resourceConversionValues.next(); - assertEquals("F", resourceConversionValue.getDataValue()); - assertEquals("female", resourceConversionValue.getObjectValue()); - - ListIterator conversionValues = converter.conversionValues(); - assertEquals(conversionValue2, conversionValues.next()); - assertEquals(conversionValue3, conversionValues.next()); - assertEquals(conversionValue, conversionValues.next()); - - conversionValues = converter.conversionValues(); - assertEquals("M", conversionValues.next().getDataValue()); - assertEquals("O", conversionValues.next().getDataValue()); - assertEquals("F", conversionValues.next().getDataValue()); - } - - public void testRemoveConversionValue() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - - converter.addConversionValue(0).setDataValue("F"); - converter.addConversionValue(1).setDataValue("M"); - converter.addConversionValue(2).setDataValue("O"); - - ListIterator resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals(3, CollectionTools.size(resourceConversionValues)); - - converter.removeConversionValue(0); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals(2, CollectionTools.size(resourceConversionValues)); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals("M", resourceConversionValues.next().getDataValue()); - assertEquals("O", resourceConversionValues.next().getDataValue()); - - converter.removeConversionValue(0); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals(1, CollectionTools.size(resourceConversionValues)); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals("O", resourceConversionValues.next().getDataValue()); - - converter.removeConversionValue(0); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals(0, CollectionTools.size(resourceConversionValues)); - } - - public void testMoveConversionValue() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - - converter.addConversionValue(0).setDataValue("F"); - converter.addConversionValue(1).setDataValue("M"); - converter.addConversionValue(2).setDataValue("O"); - - ListIterator resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals(3, CollectionTools.size(resourceConversionValues)); - - converter.moveConversionValue(2,0); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals(3, CollectionTools.size(resourceConversionValues)); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals("M", resourceConversionValues.next().getDataValue()); - assertEquals("O", resourceConversionValues.next().getDataValue()); - assertEquals("F", resourceConversionValues.next().getDataValue()); - - converter.moveConversionValue(0,1); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals(3, CollectionTools.size(resourceConversionValues)); - resourceConversionValues = converterAnnotation.conversionValues(); - assertEquals("O", resourceConversionValues.next().getDataValue()); - assertEquals("M", resourceConversionValues.next().getDataValue()); - assertEquals("F", resourceConversionValues.next().getDataValue()); - } - - public void testUpdateConversionValues() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - - converterAnnotation.addConversionValue(0).setDataValue("F"); - converterAnnotation.addConversionValue(1).setDataValue("M"); - converterAnnotation.addConversionValue(2).setDataValue("O"); - getJpaProject().synchronizeContextModel(); - - ListIterator conversionValues = converter.conversionValues(); - assertEquals("F", conversionValues.next().getDataValue()); - assertEquals("M", conversionValues.next().getDataValue()); - assertEquals("O", conversionValues.next().getDataValue()); - assertFalse(conversionValues.hasNext()); - - converterAnnotation.moveConversionValue(2, 0); - getJpaProject().synchronizeContextModel(); - conversionValues = converter.conversionValues(); - assertEquals("M", conversionValues.next().getDataValue()); - assertEquals("O", conversionValues.next().getDataValue()); - assertEquals("F", conversionValues.next().getDataValue()); - assertFalse(conversionValues.hasNext()); - - converterAnnotation.moveConversionValue(0, 1); - getJpaProject().synchronizeContextModel(); - conversionValues = converter.conversionValues(); - assertEquals("O", conversionValues.next().getDataValue()); - assertEquals("M", conversionValues.next().getDataValue()); - assertEquals("F", conversionValues.next().getDataValue()); - assertFalse(conversionValues.hasNext()); - - converterAnnotation.removeConversionValue(1); - getJpaProject().synchronizeContextModel(); - conversionValues = converter.conversionValues(); - assertEquals("O", conversionValues.next().getDataValue()); - assertEquals("F", conversionValues.next().getDataValue()); - assertFalse(conversionValues.hasNext()); - - converterAnnotation.removeConversionValue(1); - getJpaProject().synchronizeContextModel(); - conversionValues = converter.conversionValues(); - assertEquals("O", conversionValues.next().getDataValue()); - assertFalse(conversionValues.hasNext()); - - converterAnnotation.removeConversionValue(0); - getJpaProject().synchronizeContextModel(); - conversionValues = converter.conversionValues(); - assertFalse(conversionValues.hasNext()); - } - - public void testConversionValuesSize() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - - assertEquals(0, converter.conversionValuesSize()); - - converterAnnotation.addConversionValue(0).setDataValue("F"); - converterAnnotation.addConversionValue(1).setDataValue("M"); - converterAnnotation.addConversionValue(2).setDataValue("O"); - - this.getJpaProject().synchronizeContextModel(); - assertEquals(3, converter.conversionValuesSize()); - } - - - public void testGetDefaultObjectValue() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("bar", converter.getDefaultObjectValue()); - } - - public void testSetDefaultObjectValue() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - assertEquals("bar", converter.getDefaultObjectValue()); - - converter.setDefaultObjectValue("baz"); - assertEquals("baz", converter.getDefaultObjectValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("baz", converterAnnotation.getDefaultObjectValue()); - - - converter.setDefaultObjectValue(null); - assertEquals(null, converter.getDefaultObjectValue()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getDefaultObjectValue()); - - - converter.setDefaultObjectValue("bar"); - assertEquals("bar", converter.getDefaultObjectValue()); - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getDefaultObjectValue()); - } - - public void testGetDefaultObjectValueUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndObjectTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("bar", converter.getDefaultObjectValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkObjectTypeConverterAnnotation converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setDefaultObjectValue("baz"); - getJpaProject().synchronizeContextModel(); - assertEquals("baz", converter.getDefaultObjectValue()); - - attributeResource.removeAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.addAnnotation(EclipseLinkObjectTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setDefaultObjectValue("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", ((EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter()).getDefaultObjectValue()); - } - - public void testInitializeConversionValues() throws Exception { - createTestEntityWithConvertAndObjectTypeConverterConversionValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals(1, converter.conversionValuesSize()); - assertEquals("f", converter.conversionValues().next().getDataValue()); - assertEquals("female", converter.conversionValues().next().getObjectValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java deleted file mode 100644 index 36a0d0f51e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java +++ /dev/null @@ -1,579 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetch; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyRelationship; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkPrivateOwned; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJoinFetchAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkPrivateOwnedAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaOneToManyMappingTests extends EclipseLinkContextModelTestCase -{ - private ICompilationUnit createTestEntityWithOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithPrivateOwnedOneToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, EclipseLink.PRIVATE_OWNED); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - sb.append("@PrivateOwned").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithJoinFetchOneToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, EclipseLink.JOIN_FETCH); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - sb.append("@JoinFetch").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithDefaultOneToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("implements java.io.Serializable"); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private java.util.Collection<" + TYPE_NAME + "> myTypes;").append(CR); - sb.append(CR); - } - }); - } - - public EclipseLinkJavaOneToManyMappingTests(String name) { - super(name); - } - - - public void testGetPrivateOwned() throws Exception { - createTestEntityWithPrivateOwnedOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - EclipseLinkPrivateOwned privateOwnable = oneToManyMapping.getPrivateOwned(); - assertEquals(true, privateOwnable.isPrivateOwned()); - } - - public void testSetPrivateOwned() throws Exception { - createTestEntityWithPrivateOwnedOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - EclipseLinkPrivateOwned privateOwnable = oneToManyMapping.getPrivateOwned(); - assertEquals(true, privateOwnable.isPrivateOwned()); - - privateOwnable.setPrivateOwned(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME)); - assertEquals(false, privateOwnable.isPrivateOwned()); - - privateOwnable.setPrivateOwned(true); - assertNotNull(attributeResource.getAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME)); - assertEquals(true, privateOwnable.isPrivateOwned()); - } - - public void testPrivateOwnedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithPrivateOwnedOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - EclipseLinkPrivateOwned privateOwnable = oneToManyMapping.getPrivateOwned(); - assertEquals(true, privateOwnable.isPrivateOwned()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(false, privateOwnable.isPrivateOwned()); - - attributeResource.addAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(true, privateOwnable.isPrivateOwned()); - } - - public void testGetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to INNER specifically, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to OUTER, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // remove value from resource, test context - - joinFetchAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // remove annotation, text context - - attributeResource.removeAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertNull(contextJoinFetch.getValue()); - } - - public void testSetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to INNER specifically, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to OUTER, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // set context to null, test resource - - contextJoinFetch.setValue(null); - - assertNull(attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME)); - assertNull(contextJoinFetch.getValue()); - - // change context to INNER specifically (this time from no annotation), test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToManyMapping mapping = (EclipseLinkOneToManyMapping) contextAttribute.getMapping(); - EclipseLinkOneToManyRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToManyMapping mapping = (EclipseLinkOneToManyMapping) contextAttribute.getMapping(); - EclipseLinkOneToManyRelationship rel = mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testDefaultOneToMany() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, attributes.next().getDefaultMappingKey()); - } - - public void testDefaultOneToManySetFetch() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setSpecifiedFetch(FetchType.LAZY); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(FetchType.LAZY, specifiedOneToManyMapping.getFetch()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, annotation.getFetch()); - } - - public void testDefaultOneToManySetTargetEntity() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setSpecifiedTargetEntity("Foo"); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals("Foo", specifiedOneToManyMapping.getSpecifiedTargetEntity()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals("Foo", annotation.getTargetEntity()); - } - - public void testDefaultOneToManySetMappedBy() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("Foo"); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals("Foo", specifiedOneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals("Foo", annotation.getMappedBy()); - } - - public void testDefaultOneToManySetCascadeAll() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getCascade().setAll(true); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToManyMapping.getCascade().isAll()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadeAll()); - } - - public void testDefaultOneToManySetCascadeMerge() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getCascade().setMerge(true); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToManyMapping.getCascade().isMerge()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadeMerge()); - } - - public void testDefaultOneToManySetCascadePersist() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getCascade().setPersist(true); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToManyMapping.getCascade().isPersist()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadePersist()); - } - - public void testDefaultOneToManySetCascadeRefresh() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getCascade().setRefresh(true); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToManyMapping.getCascade().isRefresh()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertEquals(true, annotation.isCascadeRefresh()); - } - - public void testDefaultOneToManySetCascadeRemove() throws Exception { - createTestEntityWithDefaultOneToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getCascade().setRemove(true); - - EclipseLinkOneToManyMapping specifiedOneToManyMapping = (EclipseLinkOneToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToManyMapping.getCascade().isRemove()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation annotation = - (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadeRemove()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java deleted file mode 100644 index 2829d115d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java +++ /dev/null @@ -1,449 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetch; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkPrivateOwned; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJoinFetchAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkPrivateOwnedAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaOneToOneMappingTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithPrivateOwnedOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, EclipseLink.PRIVATE_OWNED); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - sb.append("@PrivateOwned").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithJoinFetchOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, EclipseLink.JOIN_FETCH); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - sb.append("@JoinFetch").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithDefaultOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("implements java.io.Serializable"); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private " + TYPE_NAME + " myType;").append(CR); - sb.append(CR); - } - }); - } - - public EclipseLinkJavaOneToOneMappingTests(String name) { - super(name); - } - - - public void testGetPrivateOwned() throws Exception { - createTestEntityWithPrivateOwnedOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - EclipseLinkPrivateOwned privateOwnable = oneToOneMapping.getPrivateOwned(); - assertEquals(true, privateOwnable.isPrivateOwned()); - } - - public void testSetPrivateOwned() throws Exception { - createTestEntityWithPrivateOwnedOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - EclipseLinkPrivateOwned privateOwnable = oneToOneMapping.getPrivateOwned(); - assertEquals(true, privateOwnable.isPrivateOwned()); - - privateOwnable.setPrivateOwned(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME)); - assertEquals(false, privateOwnable.isPrivateOwned()); - - privateOwnable.setPrivateOwned(true); - assertNotNull(attributeResource.getAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME)); - assertEquals(true, privateOwnable.isPrivateOwned()); - } - - public void testPrivateOwnedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithPrivateOwnedOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - EclipseLinkPrivateOwned privateOwnable = oneToOneMapping.getPrivateOwned(); - assertEquals(true, privateOwnable.isPrivateOwned()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(false, privateOwnable.isPrivateOwned()); - - attributeResource.addAnnotation(EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(true, privateOwnable.isPrivateOwned()); - } - - public void testGetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to INNER specifically, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to OUTER, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // remove value from resource, test context - - joinFetchAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // remove annotation, text context - - attributeResource.removeAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertNull(contextJoinFetch.getValue()); - } - - public void testSetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to INNER specifically, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to OUTER, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // set context to null, test resource - - contextJoinFetch.setValue(null); - - assertNull(attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME)); - assertNull(contextJoinFetch.getValue()); - - // change context to INNER specifically (this time from no annotation), test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - } - - public void testDefaultOneToOne() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, attributes.next().getDefaultMappingKey()); - } - - public void testDefaultOneToOneSetFetch() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.setSpecifiedFetch(FetchType.LAZY); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(FetchType.LAZY, specifiedOneToOneMapping.getFetch()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, annotation.getFetch()); - } - - public void testDefaultOneToOneSetTargetEntity() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.setSpecifiedTargetEntity("Foo"); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals("Foo", specifiedOneToOneMapping.getSpecifiedTargetEntity()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals("Foo", annotation.getTargetEntity()); - } - - public void testDefaultOneToOneSetMappedBy() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("Foo"); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals("Foo", specifiedOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals("Foo", annotation.getMappedBy()); - } - - public void testDefaultOneToOneSetCascadeAll() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.getCascade().setAll(true); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToOneMapping.getCascade().isAll()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadeAll()); - } - - public void testDefaultOneToOneSetCascadeMerge() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.getCascade().setMerge(true); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToOneMapping.getCascade().isMerge()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadeMerge()); - } - - public void testDefaultOneToOneSetCascadePersist() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.getCascade().setPersist(true); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToOneMapping.getCascade().isPersist()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadePersist()); - } - - public void testDefaultOneToOneSetCascadeRefresh() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.getCascade().setRefresh(true); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToOneMapping.getCascade().isRefresh()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadeRefresh()); - } - - public void testDefaultOneToOneSetCascadeRemove() throws Exception { - createTestEntityWithDefaultOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute persistentAttribute = attributes.next(); - assertTrue(persistentAttribute.getMapping().isDefault()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - - EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.getCascade().setRemove(true); - - EclipseLinkOneToOneMapping specifiedOneToOneMapping = (EclipseLinkOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(true, specifiedOneToOneMapping.getCascade().isRemove()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = - (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - assertNotNull(annotation); - assertEquals(true, annotation.isCascadeRemove()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaStructConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaStructConverterTests.java deleted file mode 100644 index e319ab678a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaStructConverterTests.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkStructConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaStructConverterTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithConvertAndStructConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.STRUCT_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @StructConverter(name=\"foo\""); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndStructConverterClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.STRUCT_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @StructConverter(converter=\"Foo\""); - } - }); - } - - public EclipseLinkJavaStructConverterTests(String name) { - super(name); - } - - - public void testGetName() throws Exception { - createTestEntityWithConvertAndStructConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkStructConverter converter = (EclipseLinkStructConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithConvertAndStructConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkStructConverter converter = (EclipseLinkStructConverter) eclipseLinkConvert.getConverter(); - assertEquals("foo", converter.getName()); - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkStructConverterAnnotation converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - - - converter.setName(null); - assertEquals(null, converter.getName()); - converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getName()); - - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - } - - public void testGetNameUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndStructConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkStructConverter converter = (EclipseLinkStructConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkStructConverterAnnotation converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", converter.getName()); - - attributeResource.removeAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.addAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", eclipseLinkConvert.getConverter().getName()); - } - - - public void testGetConverterClass() throws Exception { - createTestEntityWithConvertAndStructConverterClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkStructConverter converter = (EclipseLinkStructConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getConverterClass()); - } - - public void testSetConverterClass() throws Exception { - createTestEntityWithConvertAndStructConverterClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkStructConverter converter = (EclipseLinkStructConverter) eclipseLinkConvert.getConverter(); - assertEquals("Foo", converter.getConverterClass()); - - converter.setConverterClass("Bar"); - assertEquals("Bar", converter.getConverterClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkStructConverterAnnotation converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getConverter()); - - - converter.setConverterClass(null); - assertEquals(null, converter.getConverterClass()); - converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getConverter()); - - - converter.setConverterClass("Bar"); - assertEquals("Bar", converter.getConverterClass()); - converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getConverter()); - } - - public void testGetConverterClassUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndStructConverterClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkStructConverter converter = (EclipseLinkStructConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getConverterClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkStructConverterAnnotation converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setConverter("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", converter.getConverterClass()); - - attributeResource.removeAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkStructConverterAnnotation) attributeResource.addAnnotation(EclipseLinkStructConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setConverter("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", ((EclipseLinkStructConverter) eclipseLinkConvert.getConverter()).getConverterClass()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaTypeConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaTypeConverterTests.java deleted file mode 100644 index 2d201d4ad9..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaTypeConverterTests.java +++ /dev/null @@ -1,313 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkTypeConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaTypeConverterTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithConvertAndTypeConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @TypeConverter(name=\"foo\""); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndDataType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @TypeConverter(dataType=Foo.class"); - } - }); - } - - private ICompilationUnit createTestEntityWithConvertAndObjectType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @TypeConverter(objectType=Foo.class"); - } - }); - } - - public EclipseLinkJavaTypeConverterTests(String name) { - super(name); - } - - - public void testGetName() throws Exception { - createTestEntityWithConvertAndTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithConvertAndTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - assertEquals("foo", converter.getName()); - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkTypeConverterAnnotation converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - - - converter.setName(null); - assertEquals(null, converter.getName()); - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getName()); - - - converter.setName("bar"); - assertEquals("bar", converter.getName()); - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("bar", converterAnnotation.getName()); - } - - public void testGetNameUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndTypeConverter(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("foo", converter.getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkTypeConverterAnnotation converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", converter.getName()); - - attributeResource.removeAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.addAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", eclipseLinkConvert.getConverter().getName()); - } - - public void testGetDataType() throws Exception { - createTestEntityWithConvertAndDataType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getDataType()); - } - - public void testSetDataType() throws Exception { - createTestEntityWithConvertAndDataType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkTypeConverterAnnotation converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getDataType()); - - - converter.setDataType(null); - assertEquals(null, converter.getDataType()); - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getDataType()); - - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getDataType()); - } - - public void testGetDataTypeUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndDataType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getDataType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkTypeConverterAnnotation converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setDataType("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", converter.getDataType()); - - attributeResource.removeAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.addAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setDataType("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", ((EclipseLinkTypeConverter) eclipseLinkConvert.getConverter()).getDataType()); - } - - public void testGetObjectType() throws Exception { - createTestEntityWithConvertAndObjectType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getObjectType()); - } - - public void testSetObjectType() throws Exception { - createTestEntityWithConvertAndObjectType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkTypeConverterAnnotation converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getObjectType()); - - - converter.setObjectType(null); - assertEquals(null, converter.getObjectType()); - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals(null, converterAnnotation.getObjectType()); - - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - assertEquals("Bar", converterAnnotation.getObjectType()); - } - - public void testGetObjectTypeUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithConvertAndObjectType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) basicMapping.getConverter(); - EclipseLinkTypeConverter converter = (EclipseLinkTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals("Foo", converter.getObjectType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkTypeConverterAnnotation converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - converterAnnotation.setObjectType("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", converter.getObjectType()); - - attributeResource.removeAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, eclipseLinkConvert.getConverter()); - - converterAnnotation = (EclipseLinkTypeConverterAnnotation) attributeResource.addAnnotation(EclipseLinkTypeConverterAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNotNull(eclipseLinkConvert.getConverter()); - - converterAnnotation.setObjectType("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", ((EclipseLinkTypeConverter) eclipseLinkConvert.getConverter()).getObjectType()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaVersionMappingTests.java deleted file mode 100644 index c7a3f6e8c7..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaVersionMappingTests.java +++ /dev/null @@ -1,322 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMutable; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkVersionMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConvertAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkMutableAnnotation; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLinkJavaVersionMappingTests extends EclipseLinkContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithVersionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - } - }); - } - - - private ICompilationUnit createTestEntityWithConvert() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION, EclipseLink.CONVERT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - sb.append("@Convert(\"class-instance\")").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableVersion() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION, EclipseLink.MUTABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - sb.append("@Mutable").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableVersionDate() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION, EclipseLink.MUTABLE, "java.util.Date"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - sb.append(" @Mutable").append(CR); - sb.append(" private Date myDate;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - public EclipseLinkJavaVersionMappingTests(String name) { - super(name); - } - - public void testGetConvert() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - - assertEquals(EclipseLinkConvert.class, versionMapping.getConverter().getType()); - } - - public void testGetConvert2() throws Exception { - createTestEntityWithConvert(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - - assertEquals(EclipseLinkConvert.class, versionMapping.getConverter().getType()); - assertEquals(EclipseLinkConvert.CLASS_INSTANCE_CONVERTER, ((EclipseLinkConvert) versionMapping.getConverter()).getConverterName()); - } - - public void testSetConvert() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertNull(versionMapping.getConverter().getType()); - - versionMapping.setConverter(TemporalConverter.class); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - versionMapping.setConverter(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetConvertUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - - assertNull(versionMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkConvertAnnotation convert = (EclipseLinkConvertAnnotation) attributeResource.addAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - convert.setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals(EclipseLinkConvert.class, versionMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) versionMapping.getConverter()).getConverterName()); - - attributeResource.removeAnnotation(EclipseLinkConvertAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(versionMapping.getConverter().getType()); - assertFalse(versionMapping.isDefault()); - assertSame(versionMapping, persistentAttribute.getMapping()); - } - - public void testGetSpecifiedMutable() throws Exception { - createTestEntityWithMutableVersion(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkVersionMapping versionMapping = (EclipseLinkVersionMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = versionMapping.getMutable(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - mutableAnnotation.setValue(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - mutableAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - mutableAnnotation.setValue(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, mutable.getSpecifiedMutable()); - - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, mutable.getSpecifiedMutable()); - - attributeResource.addAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - } - - public void testSetSpecifiedMutable() throws Exception { - createTestEntityWithMutableVersion(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkVersionMapping versionMapping = (EclipseLinkVersionMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = versionMapping.getMutable(); - assertEquals(Boolean.TRUE, mutable.getSpecifiedMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(null, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertEquals(null, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(null); - mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(null, mutableAnnotation); - - mutable.setSpecifiedMutable(Boolean.FALSE); - mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, mutableAnnotation.getValue()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - } - - public void testIsDefaultMutable() throws Exception { - createTestEntityWithMutableVersion(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkVersionMapping versionMapping = (EclipseLinkVersionMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = versionMapping.getMutable(); - assertTrue(mutable.isDefaultMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertTrue(mutable.isDefaultMutable()); - - mutable.setSpecifiedMutable(Boolean.FALSE); - assertTrue(mutable.isDefaultMutable()); - - //set mutable default to false in the persistence unit properties, verify default in java still true since this is not a Date/Calendar - (getPersistenceUnit()).getOptions().setTemporalMutable(Boolean.FALSE); - assertTrue(mutable.isDefaultMutable()); - } - - public void testIsDefaultMutableForDate() throws Exception { - createTestEntityWithMutableVersionDate(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkVersionMapping versionMapping = (EclipseLinkVersionMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = versionMapping.getMutable(); - assertFalse(mutable.isDefaultMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertFalse(mutable.isDefaultMutable()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertFalse(mutable.isDefaultMutable()); - - //set mutable default to false in the persistence unit properties, verify default in java still true since this is not a Date/Calendar - (getPersistenceUnit()).getOptions().setTemporalMutable(Boolean.TRUE); - assertTrue(mutable.isDefaultMutable()); - - (getPersistenceUnit()).getOptions().setTemporalMutable(Boolean.FALSE); - assertFalse(mutable.isDefaultMutable()); - - (getPersistenceUnit()).getOptions().setTemporalMutable(null); - assertFalse(mutable.isDefaultMutable()); - } - - public void testIsMutable() throws Exception { - createTestEntityWithMutableVersion(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkVersionMapping versionMapping = (EclipseLinkVersionMapping) persistentAttribute.getMapping(); - EclipseLinkMutable mutable = versionMapping.getMutable(); - assertTrue(mutable.isMutable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.removeAnnotation(EclipseLinkMutableAnnotation.ANNOTATION_NAME); - assertTrue(mutable.isMutable()); - - mutable.setSpecifiedMutable(Boolean.TRUE); - assertTrue(mutable.isMutable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java deleted file mode 100644 index 415bf4fd14..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLinkCoreJavaContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreJavaContextModelTests.class.getName()); - suite.addTestSuite(EclipseLinkJavaBasicMappingTests.class); - suite.addTestSuite(EclipseLinkJavaCachingTests.class); - suite.addTestSuite(EclipseLinkJavaConverterTests.class); - suite.addTestSuite(EclipseLinkJavaConvertTests.class); - suite.addTestSuite(EclipseLinkJavaEmbeddableTests.class); - suite.addTestSuite(EclipseLinkJavaEntityTests.class); - suite.addTestSuite(EclipseLinkJavaIdMappingTests.class); - suite.addTestSuite(EclipseLinkJavaManyToManyMappingTests.class); - suite.addTestSuite(EclipseLinkJavaManyToOneMappingTests.class); - suite.addTestSuite(EclipseLinkJavaMappedSuperclassTests.class); - suite.addTestSuite(EclipseLinkJavaObjectTypeConverterTests.class); - suite.addTestSuite(EclipseLinkJavaOneToManyMappingTests.class); - suite.addTestSuite(EclipseLinkJavaOneToOneMappingTests.class); - suite.addTestSuite(EclipseLinkJavaStructConverterTests.class); - suite.addTestSuite(EclipseLinkJavaTypeConverterTests.class); - suite.addTestSuite(EclipseLinkJavaVersionMappingTests.class); - return suite; - } - - private JptEclipseLinkCoreJavaContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkEntityMappingsTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkEntityMappingsTests.java deleted file mode 100644 index 758fd5d4d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkEntityMappingsTests.java +++ /dev/null @@ -1,675 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkConverterContainer; -import org.eclipse.jpt.eclipselink.core.context.orm.EclipseLinkEntityMappings; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlStructConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTypeConverter; - -@SuppressWarnings("nls") -public class EclipseLinkEntityMappingsTests extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkEntityMappingsTests(String name) { - super(name); - } - - - public void testUpdateCustomConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceEntityMappings.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlConverter resourceConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceEntityMappings.getConverters().add(resourceConverter); - resourceConverter.setClassName("Foo"); - resourceConverter.setName("myConverter"); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, resourceEntityMappings.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlConverter resourceConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceEntityMappings.getConverters().add(0, resourceConverter2); - resourceConverter2.setClassName("Foo2"); - resourceConverter2.setName("myConverter2"); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, resourceEntityMappings.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntityMappings.getConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, resourceEntityMappings.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, resourceEntityMappings.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getConverters().remove(resourceConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyCustomConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceEntityMappings.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter = ormContextConverterHolder.addCustomConverter(0); - contextConverter.setConverterClass("Foo"); - contextConverter.setName("myConverter"); - - assertEquals(1, resourceEntityMappings.getConverters().size()); - assertEquals("Foo", resourceEntityMappings.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceEntityMappings.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter2 = ormContextConverterHolder.addCustomConverter(0); - contextConverter2.setConverterClass("Foo2"); - contextConverter2.setName("myConverter2"); - - assertEquals(2, resourceEntityMappings.getConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceEntityMappings.getConverters().get(0).getName()); - assertEquals("Foo", resourceEntityMappings.getConverters().get(1).getClassName()); - assertEquals("myConverter", resourceEntityMappings.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveCustomConverter(0, 1); - - assertEquals(2, resourceEntityMappings.getConverters().size()); - assertEquals("Foo", resourceEntityMappings.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceEntityMappings.getConverters().get(0).getName()); - assertEquals("Foo2", resourceEntityMappings.getConverters().get(1).getClassName()); - assertEquals("myConverter2", resourceEntityMappings.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(0); - - assertEquals(1, resourceEntityMappings.getConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceEntityMappings.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(contextConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateTypeConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceEntityMappings.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceEntityMappings.getTypeConverters().add(resourceTypeConverter); - resourceTypeConverter.setDataType("Foo"); - resourceTypeConverter.setName("myTypeConverter"); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, resourceEntityMappings.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceEntityMappings.getTypeConverters().add(0, resourceTypeConverter2); - resourceTypeConverter2.setDataType("Foo2"); - resourceTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, resourceEntityMappings.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntityMappings.getTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, resourceEntityMappings.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, resourceEntityMappings.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getTypeConverters().remove(resourceTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyTypeConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceEntityMappings.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter.setDataType("Foo"); - contextTypeConverter.setName("myTypeConverter"); - - assertEquals(1, resourceEntityMappings.getTypeConverters().size()); - assertEquals("Foo", resourceEntityMappings.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceEntityMappings.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter2 = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter2.setDataType("Foo2"); - contextTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, resourceEntityMappings.getTypeConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceEntityMappings.getTypeConverters().get(0).getName()); - assertEquals("Foo", resourceEntityMappings.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter", resourceEntityMappings.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveTypeConverter(0, 1); - - assertEquals(2, resourceEntityMappings.getTypeConverters().size()); - assertEquals("Foo", resourceEntityMappings.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceEntityMappings.getTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceEntityMappings.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter2", resourceEntityMappings.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(0); - - assertEquals(1, resourceEntityMappings.getTypeConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceEntityMappings.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(contextTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateObjectTypeConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceEntityMappings.getObjectTypeConverters().add(resourceObjectTypeConverter); - resourceObjectTypeConverter.setDataType("Foo"); - resourceObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceEntityMappings.getObjectTypeConverters().add(0, resourceObjectTypeConverter2); - resourceObjectTypeConverter2.setDataType("Foo2"); - resourceObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntityMappings.getObjectTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getObjectTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getObjectTypeConverters().remove(resourceObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyObjectTypeConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter.setDataType("Foo"); - contextObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals("Foo", resourceEntityMappings.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceEntityMappings.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter2 = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter2.setDataType("Foo2"); - contextObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEntityMappings.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo", resourceEntityMappings.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter", resourceEntityMappings.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveObjectTypeConverter(0, 1); - - assertEquals(2, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals("Foo", resourceEntityMappings.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceEntityMappings.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceEntityMappings.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEntityMappings.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(0); - - assertEquals(1, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEntityMappings.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(contextObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateStructConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceEntityMappings.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlStructConverter resourceStructConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceEntityMappings.getStructConverters().add(resourceStructConverter); - resourceStructConverter.setConverter("Foo"); - resourceStructConverter.setName("myStructConverter"); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, resourceEntityMappings.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlStructConverter resourceStructConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceEntityMappings.getStructConverters().add(0, resourceStructConverter2); - resourceStructConverter2.setConverter("Foo2"); - resourceStructConverter2.setName("myStructConverter2"); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, resourceEntityMappings.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntityMappings.getStructConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, resourceEntityMappings.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getStructConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, resourceEntityMappings.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntityMappings.getStructConverters().remove(resourceStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyStructConverters() throws Exception { - XmlEntityMappings resourceEntityMappings = getXmlEntityMappings(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - EclipseLinkEntityMappings contextEntityMappings = getEntityMappings(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = contextEntityMappings.getConverterContainer(); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceEntityMappings.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter = ormContextConverterHolder.addStructConverter(0); - contextStructConverter.setConverterClass("Foo"); - contextStructConverter.setName("myStructConverter"); - - assertEquals(1, resourceEntityMappings.getStructConverters().size()); - assertEquals("Foo", resourceEntityMappings.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceEntityMappings.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter2 = ormContextConverterHolder.addStructConverter(0); - contextStructConverter2.setConverterClass("Foo2"); - contextStructConverter2.setName("myStructConverter2"); - - assertEquals(2, resourceEntityMappings.getStructConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceEntityMappings.getStructConverters().get(0).getName()); - assertEquals("Foo", resourceEntityMappings.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter", resourceEntityMappings.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveStructConverter(0, 1); - - assertEquals(2, resourceEntityMappings.getStructConverters().size()); - assertEquals("Foo", resourceEntityMappings.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceEntityMappings.getStructConverters().get(0).getName()); - assertEquals("Foo2", resourceEntityMappings.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter2", resourceEntityMappings.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(0); - - assertEquals(1, resourceEntityMappings.getStructConverters().size()); - assertEquals("Foo2", resourceEntityMappings.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceEntityMappings.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(contextStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceEntityMappings.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmBasicMappingTests.java deleted file mode 100644 index e8bf13822f..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmBasicMappingTests.java +++ /dev/null @@ -1,389 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkBasicMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkBasicMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlBasic; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; - -@SuppressWarnings("nls") -public class EclipseLinkOrmBasicMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableBasicDate() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, EclipseLink.MUTABLE, "java.util.Date"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Mutable").append(CR); - sb.append(" private Date myDate;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - public EclipseLinkOrmBasicMappingTests(String name) { - super(name); - } - - - public void testUpdateMutable() throws Exception { - createTestEntityWithBasicMapping(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmEclipseLinkBasicMapping contextBasic = - (OrmEclipseLinkBasicMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlBasic resourceBasic = - (XmlBasic) resourceEntity.getAttributes().getBasics().get(0); - EclipseLinkBasicMapping javaBasicMapping = (EclipseLinkBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - // check defaults - - assertNull(resourceBasic.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceBasic.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceBasic.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceBasic.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceBasic.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceBasic.setMutable(null); - - assertNull(resourceBasic.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - - // TODO - test defaults for java serializable and date/time types, - // with and without persistence property - - // set mutable on java basic mapping - - javaBasicMapping.getMutable().setSpecifiedMutable(Boolean.FALSE); - assertNull(resourceBasic.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - assertFalse(javaBasicMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - EclipseLinkBasicMapping virtualContextBasic = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - - assertNull(resourceBasic.getMutable()); - assertTrue(virtualContextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, virtualContextBasic.getMutable().getSpecifiedMutable()); - assertFalse(virtualContextBasic.getMutable().isMutable()); - assertFalse(javaBasicMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualContextBasic = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(resourceBasic.getMutable()); - assertTrue(virtualContextBasic.getMutable().isDefaultMutable()); - assertNull(virtualContextBasic.getMutable().getSpecifiedMutable()); - assertTrue(virtualContextBasic.getMutable().isMutable()); - assertFalse(javaBasicMapping.getMutable().isMutable()); - } - - public void testUpdateMutableDate() throws Exception { - createTestEntityWithMutableBasicDate(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "myDate"); - OrmEclipseLinkBasicMapping contextBasic = - (OrmEclipseLinkBasicMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlBasic resourceBasic = - (XmlBasic) resourceEntity.getAttributes().getBasics().get(0); - EclipseLinkBasicMapping javaBasicMapping = (EclipseLinkBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("myDate").getMapping(); - - // check defaults - - assertNull(resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceBasic.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceBasic.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceBasic.setMutable(null); - - assertNull(resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.TRUE); - assertNull(resourceBasic.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.FALSE); - assertNull(resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(null); - assertNull(resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - // set mutable on java basic mapping - - javaBasicMapping.getMutable().setSpecifiedMutable(Boolean.TRUE); - assertNull(resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - assertTrue(javaBasicMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("myDate"); - EclipseLinkBasicMapping virtualContextBasic = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - - assertNull(resourceBasic.getMutable()); - assertFalse(virtualContextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, virtualContextBasic.getMutable().getSpecifiedMutable()); - assertTrue(virtualContextBasic.getMutable().isMutable()); - assertTrue(javaBasicMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("myDate"); - virtualContextBasic = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(resourceBasic.getMutable()); - assertFalse(virtualContextBasic.getMutable().isDefaultMutable()); - assertNull(virtualContextBasic.getMutable().getSpecifiedMutable()); - assertFalse(virtualContextBasic.getMutable().isMutable()); - assertTrue(javaBasicMapping.getMutable().isMutable()); - } - - public void testModifyMutable() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - OrmEclipseLinkBasicMapping contextBasic = - (OrmEclipseLinkBasicMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlBasic resourceBasic = - (XmlBasic) resourceEntity.getAttributes().getBasics().get(0); - - // check defaults - - assertNull(resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - // set context mutable to true, check resource - - contextBasic.getMutable().setSpecifiedMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - - // set context mutable to false, check resource - - contextBasic.getMutable().setSpecifiedMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - - // set context mutable to null, check resource - - contextBasic.getMutable().setSpecifiedMutable(null); - - assertNull(resourceBasic.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - } - - public void testUpdateConvert() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = (XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(ormBasicMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob in the resource model, verify context model updated - basicResource.setConvert("myConvert"); - assertEquals(EclipseLinkConvert.class, ormBasicMapping.getConverter().getType()); - assertEquals("myConvert", basicResource.getConvert()); - - //set lob to null in the resource model - basicResource.setConvert(null); - assertNull(ormBasicMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - - javaBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) javaBasicMapping.getConverter()).setSpecifiedConverterName("foo"); - - assertNull(ormBasicMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaBasicMapping.getConverter()).getSpecifiedConverterName()); - - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - EclipseLinkBasicMapping virtualBasicMapping = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - - assertEquals(EclipseLinkConvert.class, virtualBasicMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaBasicMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) javaBasicMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals(EclipseLinkConvert.class, virtualBasicMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("bar", ((EclipseLinkConvert) javaBasicMapping.getConverter()).getSpecifiedConverterName()); - - javaBasicMapping.setConverter(null); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - assertNull(javaBasicMapping.getConverter().getType()); - } - - public void testModifyConvert() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = (XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob in the context model, verify resource model updated - ormBasicMapping.setConverter(EclipseLinkConvert.class); - assertEquals("", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.class, ormBasicMapping.getConverter().getType()); - - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals("bar", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.class, ormBasicMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) ormBasicMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setSpecifiedConverterName(null); - - assertNull(ormBasicMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob to false in the context model - ormBasicMapping.setConverter(null); - assertNull(ormBasicMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmContextModelTestCase.java deleted file mode 100644 index c1802e4d33..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmContextModelTestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.eclipselink.core.context.orm.EclipseLinkEntityMappings; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationOperation; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public abstract class EclipseLinkOrmContextModelTestCase - extends EclipseLinkContextModelTestCase -{ - protected JpaXmlResource eclipseLinkOrmXmlResource; - - - protected EclipseLinkOrmContextModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.eclipseLinkOrmXmlResource = getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - } - - @Override - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) throws Exception { - TestJpaProject testJpaProject = super.buildJpaProject(projectName, autoBuild, jpaConfig); - - EclipseLinkOrmFileCreationOperation operation = - new EclipseLinkOrmFileCreationOperation(buildEclipseLinkOrmConfig(testJpaProject)); - operation.execute(null, null); - - return testJpaProject; - } - - protected IDataModel buildEclipseLinkOrmConfig(TestJpaProject testJpaProject) { - IDataModel dataModel = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - dataModel.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - testJpaProject.getProject().getFolder("src/META-INF").getFullPath()); - dataModel.setProperty(JpaFileCreationDataModelProperties.VERSION, EclipseLink.SCHEMA_VERSION); - dataModel.setProperty(OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT, Boolean.TRUE); - return dataModel; - } - - @Override - protected void tearDown() throws Exception { - this.eclipseLinkOrmXmlResource = null; - super.tearDown(); - } - - @Override - protected JpaXmlResource getOrmXmlResource() { - return this.eclipseLinkOrmXmlResource; - } - - @Override - protected XmlEntityMappings getXmlEntityMappings() { - return (XmlEntityMappings) super.getXmlEntityMappings(); - } - - @Override - protected EclipseLinkEntityMappings getEntityMappings() { - return (EclipseLinkEntityMappings) super.getEntityMappings(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmConverterTests.java deleted file mode 100644 index 4e649f67a6..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmConverterTests.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlBasic; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConverter; - -@SuppressWarnings("nls") -public class EclipseLinkOrmConverterTests - extends EclipseLinkOrmContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, EclipseLink.CONVERT, EclipseLink.CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Convert(name=\"foo\")").append(CR); - sb.append(" @Converter"); - } - }); - } - - - public EclipseLinkOrmConverterTests(String name) { - super(name); - } - - - public void testUpdateConverterClass() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkCustomConverter.class); - OrmEclipseLinkCustomConverter ormConverter = (OrmEclipseLinkCustomConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getClassName()); - - //set converter class name in the resource model, verify context model updated - converterResource.setClassName("myConvert"); - assertEquals("myConvert", ormConverter.getConverterClass()); - assertEquals("myConvert", converterResource.getClassName()); - - //set converter class name to null in the resource model - converterResource.setClassName(null); - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getClassName()); - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - EclipseLinkCustomConverter virtualConverter = (EclipseLinkCustomConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkCustomConverter javaConverter = ((EclipseLinkCustomConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setConverterClass("bar"); - assertEquals("bar", virtualConverter.getConverterClass()); - assertEquals("bar", javaConverter.getConverterClass()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getConverterClass()); - } - - public void testModifyConverterClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkCustomConverter.class); - OrmEclipseLinkCustomConverter ormConverter = (OrmEclipseLinkCustomConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getConverter(); - - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getClassName()); - - //set converter class in the context model, verify resource model updated - ormConverter.setConverterClass("foo"); - assertEquals("foo", ormConverter.getConverterClass()); - assertEquals("foo", converterResource.getClassName()); - - ormConverter.setConverterClass(null); - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getClassName()); - } - - public void testUpdateName() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkCustomConverter.class); - OrmEclipseLinkCustomConverter ormConverter = (OrmEclipseLinkCustomConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class name in the resource model, verify context model updated - converterResource.setName("myConvert"); - assertEquals("myConvert", ormConverter.getName()); - assertEquals("myConvert", converterResource.getName()); - - //set converter class name to null in the resource model - converterResource.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - EclipseLinkCustomConverter virtualConverter = (EclipseLinkCustomConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkCustomConverter javaConverter = ((EclipseLinkCustomConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setName("bar"); - assertEquals("bar", virtualConverter.getName()); - assertEquals("bar", javaConverter.getName()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkCustomConverter.class); - OrmEclipseLinkCustomConverter ormConverter = (OrmEclipseLinkCustomConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getConverter(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class in the context model, verify resource model updated - ormConverter.setName("foo"); - assertEquals("foo", ormConverter.getName()); - assertEquals("foo", converterResource.getName()); - - ormConverter.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEmbeddableTests.java deleted file mode 100644 index 713b69111a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEmbeddableTests.java +++ /dev/null @@ -1,1035 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkEmbeddable; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkConverterContainer; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkEmbeddable; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlStructConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTypeConverter; - -@SuppressWarnings("nls") -public class EclipseLinkOrmEmbeddableTests extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmEmbeddableTests(String name) { - super(name); - } - - private ICompilationUnit createTestEmbeddableForCustomizer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE, EclipseLink.CUSTOMIZER); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - } - }); - } - - private ICompilationUnit createTestEmbeddableForChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE, EclipseLink.CHANGE_TRACKING); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - } - }); - } - - private ICompilationUnit createTestEmbeddableForCustomConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - } - }); - } - - private ICompilationUnit createTestEmbeddableForTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - } - }); - } - - private ICompilationUnit createTestEmbeddableForObjectTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - } - }); - } - - private ICompilationUnit createTestEmbeddableForStructConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable").append(CR); - } - }); - } - - public void testUpdateCustomizerClass() throws Exception { - createTestEmbeddableForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkEmbeddable javaContextEmbeddable = (JavaEclipseLinkEmbeddable) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - - // check defaults - - assertNull(resourceEmbeddable.getCustomizer()); - assertNull(javaContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - // set xml customizer, check defaults - resourceEmbeddable.setCustomizer(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(resourceEmbeddable.getCustomizer().getClassName()); - assertNull(javaContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - - // set xml customizer class, check override - - resourceEmbeddable.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceEmbeddable.getCustomizer().getClassName()); - assertNull(javaContextEmbeddable.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - // clear xml customizer class, set java customizer class, check defaults - - resourceEmbeddable.getCustomizer().setClassName(null); - javaContextEmbeddable.getCustomizer().setSpecifiedCustomizerClass("bar"); - - assertNull(resourceEmbeddable.getCustomizer().getClassName()); - assertEquals("bar", javaContextEmbeddable.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - // set metadataComplete to True, check defaults not from java - - ormContextEmbeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceEmbeddable.getCustomizer().getClassName()); - assertEquals("bar", javaContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - ormContextEmbeddable.setSpecifiedMetadataComplete(null); - - // set xml customizer class, check override - - resourceEmbeddable.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceEmbeddable.getCustomizer().getClassName()); - assertEquals("bar", javaContextEmbeddable.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - //set xml customizer null - javaContextEmbeddable.getCustomizer().setSpecifiedCustomizerClass(null); - resourceEmbeddable.setCustomizer(null); - assertNull(resourceEmbeddable.getCustomizer()); - assertNull(javaContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - } - - public void testModifyCustomizerClass() throws Exception { - createTestEmbeddableForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - // check defaults - - assertNull(resourceEmbeddable.getCustomizer()); - assertNull(ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer, check resource - - ormContextEmbeddable.getCustomizer().setSpecifiedCustomizerClass("foo"); - - assertEquals("foo", resourceEmbeddable.getCustomizer().getClassName()); - assertEquals("foo", ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer to null, check resource - - ormContextEmbeddable.getCustomizer().setSpecifiedCustomizerClass(null); - - assertNull(resourceEmbeddable.getCustomizer()); - assertNull(ormContextEmbeddable.getCustomizer().getCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEmbeddable.getCustomizer().getSpecifiedCustomizerClass()); - } - - public void testUpdateChangeTracking() throws Exception { - createTestEmbeddableForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkEmbeddable javaContextEmbeddable = (JavaEclipseLinkEmbeddable) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - // check defaults - - assertNull(resourceEmbeddable.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertNull(ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set xml type to ATTRIBUTE, check context - - resourceEmbeddable.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceEmbeddable.getChangeTracking().setType(XmlChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set xml type to OBJECT, check context - - resourceEmbeddable.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set xml type to DEFERRED, check context - - resourceEmbeddable.getChangeTracking().setType(XmlChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set xml type to AUTO, check context - - resourceEmbeddable.getChangeTracking().setType(XmlChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // clear xml change tracking, set java change tracking, check defaults - - resourceEmbeddable.setChangeTracking(null); - javaContextEmbeddable.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertNull(resourceEmbeddable.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertNull(ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set metadataComplete to True, check defaults not from java - - ormContextEmbeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceEmbeddable.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertNull(ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // unset metadataComplete, set xml change tracking to OBJECT, check context - - ormContextEmbeddable.setSpecifiedMetadataComplete(null); - resourceEmbeddable.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceEmbeddable.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - } - - public void testModifyChangeTracking() throws Exception { - createTestEmbeddableForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - // check defaults - - assertNull(resourceEmbeddable.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertNull(ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set context change tracking to ATTRIBUTE, check resource - - ormContextEmbeddable.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set context change tracking to OBJECT, check resource - - ormContextEmbeddable.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set context change tracking to DEFERRED, check resource - - ormContextEmbeddable.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set context change tracking to AUTO, check resource - - ormContextEmbeddable.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - - // set context change tracking to null, check resource - - ormContextEmbeddable.getChangeTracking().setSpecifiedType(null); - - assertNull(resourceEmbeddable.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEmbeddable.getChangeTracking().getDefaultType()); - assertNull(ormContextEmbeddable.getChangeTracking().getSpecifiedType()); - } - - public void testUpdateCustomConverters() throws Exception { - createTestEmbeddableForCustomConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceEmbeddable.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlConverter resourceConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceEmbeddable.getConverters().add(resourceConverter); - resourceConverter.setClassName("Foo"); - resourceConverter.setName("myConverter"); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, resourceEmbeddable.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlConverter resourceConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceEmbeddable.getConverters().add(0, resourceConverter2); - resourceConverter2.setClassName("Foo2"); - resourceConverter2.setName("myConverter2"); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, resourceEmbeddable.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEmbeddable.getConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, resourceEmbeddable.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, resourceEmbeddable.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getConverters().remove(resourceConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyCustomConverters() throws Exception { - createTestEmbeddableForCustomConverters(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceEmbeddable.getConverters().size()); - - //add a converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter = ormContextConverterHolder.addCustomConverter(0); - contextConverter.setConverterClass("Foo"); - contextConverter.setName("myConverter"); - - assertEquals(1, resourceEmbeddable.getConverters().size()); - assertEquals("Foo", resourceEmbeddable.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceEmbeddable.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - - //add another converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter2 = ormContextConverterHolder.addCustomConverter(0); - contextConverter2.setConverterClass("Foo2"); - contextConverter2.setName("myConverter2"); - - assertEquals(2, resourceEmbeddable.getConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceEmbeddable.getConverters().get(0).getName()); - assertEquals("Foo", resourceEmbeddable.getConverters().get(1).getClassName()); - assertEquals("myConverter", resourceEmbeddable.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveCustomConverter(0, 1); - - assertEquals(2, resourceEmbeddable.getConverters().size()); - assertEquals("Foo", resourceEmbeddable.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceEmbeddable.getConverters().get(0).getName()); - assertEquals("Foo2", resourceEmbeddable.getConverters().get(1).getClassName()); - assertEquals("myConverter2", resourceEmbeddable.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(0); - - assertEquals(1, resourceEmbeddable.getConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceEmbeddable.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(contextConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getConverters().size()); - } - - public void testUpdateTypeConverters() throws Exception { - createTestEmbeddableForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceEmbeddable.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceEmbeddable.getTypeConverters().add(resourceTypeConverter); - resourceTypeConverter.setDataType("Foo"); - resourceTypeConverter.setName("myTypeConverter"); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, resourceEmbeddable.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceEmbeddable.getTypeConverters().add(0, resourceTypeConverter2); - resourceTypeConverter2.setDataType("Foo2"); - resourceTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, resourceEmbeddable.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEmbeddable.getTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, resourceEmbeddable.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, resourceEmbeddable.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getTypeConverters().remove(resourceTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyTypeConverters() throws Exception { - createTestEmbeddableForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceEmbeddable.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter.setDataType("Foo"); - contextTypeConverter.setName("myTypeConverter"); - - assertEquals(1, resourceEmbeddable.getTypeConverters().size()); - assertEquals("Foo", resourceEmbeddable.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceEmbeddable.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter2 = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter2.setDataType("Foo2"); - contextTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, resourceEmbeddable.getTypeConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceEmbeddable.getTypeConverters().get(0).getName()); - assertEquals("Foo", resourceEmbeddable.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter", resourceEmbeddable.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveTypeConverter(0, 1); - - assertEquals(2, resourceEmbeddable.getTypeConverters().size()); - assertEquals("Foo", resourceEmbeddable.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceEmbeddable.getTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceEmbeddable.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter2", resourceEmbeddable.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(0); - - assertEquals(1, resourceEmbeddable.getTypeConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceEmbeddable.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(contextTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateObjectTypeConverters() throws Exception { - createTestEmbeddableForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceEmbeddable.getObjectTypeConverters().add(resourceObjectTypeConverter); - resourceObjectTypeConverter.setDataType("Foo"); - resourceObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceEmbeddable.getObjectTypeConverters().add(0, resourceObjectTypeConverter2); - resourceObjectTypeConverter2.setDataType("Foo2"); - resourceObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEmbeddable.getObjectTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getObjectTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getObjectTypeConverters().remove(resourceObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyObjectTypeConverters() throws Exception { - createTestEmbeddableForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter.setDataType("Foo"); - contextObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals("Foo", resourceEmbeddable.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceEmbeddable.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter2 = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter2.setDataType("Foo2"); - contextObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEmbeddable.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo", resourceEmbeddable.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter", resourceEmbeddable.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveObjectTypeConverter(0, 1); - - assertEquals(2, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals("Foo", resourceEmbeddable.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceEmbeddable.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceEmbeddable.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEmbeddable.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(0); - - assertEquals(1, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEmbeddable.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(contextObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateStructConverters() throws Exception { - createTestEmbeddableForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceEmbeddable.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlStructConverter resourceStructConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceEmbeddable.getStructConverters().add(resourceStructConverter); - resourceStructConverter.setConverter("Foo"); - resourceStructConverter.setName("myStructConverter"); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, resourceEmbeddable.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlStructConverter resourceStructConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceEmbeddable.getStructConverters().add(0, resourceStructConverter2); - resourceStructConverter2.setConverter("Foo2"); - resourceStructConverter2.setName("myStructConverter2"); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, resourceEmbeddable.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEmbeddable.getStructConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, resourceEmbeddable.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getStructConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, resourceEmbeddable.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEmbeddable.getStructConverters().remove(resourceStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyStructConverters() throws Exception { - createTestEmbeddableForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEmbeddable ormContextEmbeddable = (OrmEclipseLinkEmbeddable) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEmbeddable.getConverterContainer(); - XmlEmbeddable resourceEmbeddable = (XmlEmbeddable) getXmlEntityMappings().getEmbeddables().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceEmbeddable.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter = ormContextConverterHolder.addStructConverter(0); - contextStructConverter.setConverterClass("Foo"); - contextStructConverter.setName("myStructConverter"); - - assertEquals(1, resourceEmbeddable.getStructConverters().size()); - assertEquals("Foo", resourceEmbeddable.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceEmbeddable.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter2 = ormContextConverterHolder.addStructConverter(0); - contextStructConverter2.setConverterClass("Foo2"); - contextStructConverter2.setName("myStructConverter2"); - - assertEquals(2, resourceEmbeddable.getStructConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceEmbeddable.getStructConverters().get(0).getName()); - assertEquals("Foo", resourceEmbeddable.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter", resourceEmbeddable.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveStructConverter(0, 1); - - assertEquals(2, resourceEmbeddable.getStructConverters().size()); - assertEquals("Foo", resourceEmbeddable.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceEmbeddable.getStructConverters().get(0).getName()); - assertEquals("Foo2", resourceEmbeddable.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter2", resourceEmbeddable.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(0); - - assertEquals(1, resourceEmbeddable.getStructConverters().size()); - assertEquals("Foo2", resourceEmbeddable.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceEmbeddable.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(contextStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceEmbeddable.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEntityTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEntityTests.java deleted file mode 100644 index 254d1cf170..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmEntityTests.java +++ /dev/null @@ -1,2394 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheCoordinationType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkExistenceType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTimeOfDay; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkEntity; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkConverterContainer; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkEntity; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlStructConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTypeConverter; - -@SuppressWarnings("nls") -public class EclipseLinkOrmEntityTests extends EclipseLinkOrmContextModelTestCase -{ - - - public EclipseLinkOrmEntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityForReadOnly() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.READ_ONLY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityForCustomizer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityForChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CHANGE_TRACKING); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityForCaching() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityForConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityForTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityForObjectTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityForStructConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - public void testUpdateReadOnly() throws Exception { - createTestEntityForReadOnly(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkEntity javaContextEntity = (JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertNull(resourceEntity.getReadOnly()); - assertFalse(javaContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to false, check override - - resourceEntity.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceEntity.getReadOnly()); - assertFalse(javaContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceEntity.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceEntity.getReadOnly()); - assertFalse(javaContextEntity.getReadOnly().isReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // clear xml read only, set java read only to true, check defaults - - resourceEntity.setReadOnly(null); - javaContextEntity.getReadOnly().setSpecifiedReadOnly(Boolean.TRUE); - - assertNull(resourceEntity.getReadOnly()); - assertTrue(javaContextEntity.getReadOnly().isReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceEntity.getReadOnly()); - assertTrue(javaContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - ormContextEntity.setSpecifiedMetadataComplete(null); - - // set xml read only to false, check override - - resourceEntity.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceEntity.getReadOnly()); - assertTrue(javaContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceEntity.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceEntity.getReadOnly()); - assertTrue(javaContextEntity.getReadOnly().isReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // clear xml read only, set java read only to false, check defaults - - resourceEntity.setReadOnly(null); - javaContextEntity.getReadOnly().setSpecifiedReadOnly(Boolean.FALSE); - - assertNull(resourceEntity.getReadOnly()); - assertFalse(javaContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - - - // set xml read only to false, check override - - resourceEntity.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceEntity.getReadOnly()); - assertFalse(javaContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceEntity.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceEntity.getReadOnly()); - assertFalse(javaContextEntity.getReadOnly().isReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - } - - public void testModifyReadOnly() throws Exception { - createTestEntityForReadOnly(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertNull(resourceEntity.getReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to true, check resource - - ormContextEntity.getReadOnly().setSpecifiedReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceEntity.getReadOnly()); - assertTrue(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to false, check resource - - ormContextEntity.getReadOnly().setSpecifiedReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceEntity.getReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to null, check resource - - ormContextEntity.getReadOnly().setSpecifiedReadOnly(null); - - assertNull(resourceEntity.getReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isReadOnly()); - assertFalse(ormContextEntity.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextEntity.getReadOnly().getSpecifiedReadOnly()); - } - - - public void testUpdateCustomizerClass() throws Exception { - createTestEntityForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkEntity javaContextEntity = (JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertNull(resourceEntity.getCustomizer()); - assertNull(javaContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - // set xml customizer, check defaults - resourceEntity.setCustomizer(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(resourceEntity.getCustomizer().getClassName()); - assertNull(javaContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - - // set xml customizer class, check override - - resourceEntity.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceEntity.getCustomizer().getClassName()); - assertNull(javaContextEntity.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - // clear xml customizer class, set java customizer class, check defaults - - resourceEntity.getCustomizer().setClassName(null); - javaContextEntity.getCustomizer().setSpecifiedCustomizerClass("bar"); - - assertNull(resourceEntity.getCustomizer().getClassName()); - assertEquals("bar", javaContextEntity.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextEntity.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceEntity.getCustomizer().getClassName()); - assertEquals("bar", javaContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - ormContextEntity.setSpecifiedMetadataComplete(null); - - // set xml customizer class, check override - - resourceEntity.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceEntity.getCustomizer().getClassName()); - assertEquals("bar", javaContextEntity.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextEntity.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - //set xml customizer null - javaContextEntity.getCustomizer().setSpecifiedCustomizerClass(null); - resourceEntity.setCustomizer(null); - assertNull(resourceEntity.getCustomizer()); - assertNull(javaContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - } - - public void testModifyCustomizerClass() throws Exception { - createTestEntityForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertNull(resourceEntity.getCustomizer()); - assertNull(ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer, check resource - - ormContextEntity.getCustomizer().setSpecifiedCustomizerClass("foo"); - - assertEquals("foo", resourceEntity.getCustomizer().getClassName()); - assertEquals("foo", ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer to null, check resource - - ormContextEntity.getCustomizer().setSpecifiedCustomizerClass(null); - - assertNull(resourceEntity.getCustomizer()); - assertNull(ormContextEntity.getCustomizer().getCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextEntity.getCustomizer().getSpecifiedCustomizerClass()); - } - - public void testUpdateChangeTracking() throws Exception { - createTestEntityForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkEntity javaContextEntity = (JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertNull(resourceEntity.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertNull(ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set xml type to ATTRIBUTE, check context - - resourceEntity.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceEntity.getChangeTracking().setType(XmlChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set xml type to OBJECT, check context - - resourceEntity.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set xml type to DEFERRED, check context - - resourceEntity.getChangeTracking().setType(XmlChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set xml type to AUTO, check context - - resourceEntity.getChangeTracking().setType(XmlChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // clear xml change tracking, set java change tracking, check defaults - - resourceEntity.setChangeTracking(null); - javaContextEntity.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertNull(resourceEntity.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEntity.getChangeTracking().getDefaultType()); - assertNull(ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceEntity.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertNull(ormContextEntity.getChangeTracking().getSpecifiedType()); - - // unset metadataComplete, set xml change tracking to OBJECT, check context - - ormContextEntity.setSpecifiedMetadataComplete(null); - resourceEntity.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceEntity.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEntity.getChangeTracking().getSpecifiedType()); - } - - public void testModifyChangeTracking() throws Exception { - createTestEntityForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertNull(resourceEntity.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertNull(ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set context change tracking to ATTRIBUTE, check resource - - ormContextEntity.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set context change tracking to OBJECT, check resource - - ormContextEntity.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set context change tracking to DEFERRED, check resource - - ormContextEntity.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set context change tracking to AUTO, check resource - - ormContextEntity.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getSpecifiedType()); - - // set context change tracking to null, check resource - - ormContextEntity.getChangeTracking().setSpecifiedType(null); - - assertNull(resourceEntity.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextEntity.getChangeTracking().getDefaultType()); - assertNull(ormContextEntity.getChangeTracking().getSpecifiedType()); - } - - public void testUpdateCacheType() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // set xml cache type, check settings - resourceEntity.getCache().setType(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL, resourceEntity.getCache().getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getSpecifiedType()); - - - // set java cache type, check defaults - - javaContextCaching.setSpecifiedType(EclipseLinkCacheType.WEAK); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL, resourceEntity.getCache().getType()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getSpecifiedType()); - - // clear xml cache type, check defaults - resourceEntity.getCache().setType(null); - - assertEquals(null, resourceEntity.getCache().getType()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - ormContextEntity.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheType() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - // set context cache type, check resource - - ormContextEntity.getCaching().setSpecifiedType(EclipseLinkCacheType.HARD_WEAK); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.HARD_WEAK, resourceEntity.getCache().getType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, ormContextCaching.getSpecifiedType()); - - // set context customizer to null, check resource - - ormContextEntity.getCaching().setSpecifiedType(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - } - - public void testUpdateCacheCoordinationType() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // set xml cache type, check settings - resourceEntity.getCache().setCoordinationType(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, resourceEntity.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getSpecifiedCoordinationType()); - - - // set java cache type, check defaults - - javaContextCaching.setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, resourceEntity.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getSpecifiedCoordinationType()); - - // clear xml cache type, check defaults - resourceEntity.getCache().setCoordinationType(null); - - assertEquals(null, resourceEntity.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - ormContextEntity.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheCoordinationType() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - // set context cache coordination type, check resource - - ormContextEntity.getCaching().setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, resourceEntity.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getSpecifiedCoordinationType()); - - // set context coordination type to null, check resource - - ormContextEntity.getCaching().setSpecifiedCoordinationType(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - } - - - public void testUpdateCacheSize() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity xmlEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, xmlEntity.getCache()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - // set xml cache, check defaults - xmlEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, xmlEntity.getCache().getSize()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // set xml cache size, check settings - xmlEntity.getCache().setSize(new Integer(105)); - assertEquals(new Integer(105), xmlEntity.getCache().getSize()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(105, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(105), ormContextCaching.getSpecifiedSize()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedSize(new Integer(50)); - - assertEquals(new Integer(105), xmlEntity.getCache().getSize()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(105, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(105), ormContextCaching.getSpecifiedSize()); - - // clear xml cache size, check defaults - xmlEntity.getCache().setSize(null); - - assertEquals(null, xmlEntity.getCache().getSize()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // clear xml cache, check defaults - xmlEntity.setCache(null); - - assertEquals(null, xmlEntity.getCache()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(50, ormContextCaching.getSize()); - assertEquals(50, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, xmlEntity.getCache()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - ormContextEntity.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheSize() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - // set context cache size, check resource - - ormContextEntity.getCaching().setSpecifiedSize(new Integer(50)); - assertEquals(new Integer(50), resourceEntity.getCache().getSize()); - assertEquals(50, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(50), ormContextCaching.getSpecifiedSize()); - - // set context cache size to null, check resource - - ormContextEntity.getCaching().setSpecifiedSize(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - } - - public void testUpdateCacheAlwaysRefresh() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getAlwaysRefresh()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set xml cache always refresh, check settings - resourceEntity.getCache().setAlwaysRefresh(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceEntity.getCache().getAlwaysRefresh()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set java cache always refresh, check defaults - - javaContextCaching.setSpecifiedAlwaysRefresh(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceEntity.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set xml cache always refresh to false - resourceEntity.getCache().setAlwaysRefresh(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceEntity.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // clear xml cache always refresh, check defaults - resourceEntity.getCache().setAlwaysRefresh(null); - - assertEquals(null, resourceEntity.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set metadataComplete back to null, check defaults from java - ormContextEntity.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - } - - public void testModifyCacheAlwaysRefresh() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set context cache size, check resource - - ormContextEntity.getCaching().setSpecifiedAlwaysRefresh(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceEntity.getCache().getAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set context cache size to null, check resource - - ormContextEntity.getCaching().setSpecifiedAlwaysRefresh(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - } - - public void testUpdateCacheRefreshOnlyIfNewer() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getRefreshOnlyIfNewer()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set xml cache size, check settings - resourceEntity.getCache().setRefreshOnlyIfNewer(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceEntity.getCache().getRefreshOnlyIfNewer()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceEntity.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set xml cache always refresh to false - resourceEntity.getCache().setRefreshOnlyIfNewer(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceEntity.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // clear xml cache always refresh, check defaults - resourceEntity.getCache().setRefreshOnlyIfNewer(null); - - assertEquals(null, resourceEntity.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set metadataComplete back to null, check defaults from java - ormContextEntity.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - } - - public void testModifyCacheRefreshOnlyIfNewer() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set context cache size, check resource - - ormContextEntity.getCaching().setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceEntity.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set context cache size to null, check resource - - ormContextEntity.getCaching().setSpecifiedRefreshOnlyIfNewer(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - } - - public void testUpdateCacheDisableHits() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getDisableHits()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set xml cache size, check settings - resourceEntity.getCache().setDisableHits(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceEntity.getCache().getDisableHits()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedDisableHits(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceEntity.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - // set xml cache always refresh to false - resourceEntity.getCache().setDisableHits(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceEntity.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedDisableHits()); - - // clear xml cache always refresh, check defaults - resourceEntity.getCache().setDisableHits(null); - - assertEquals(null, resourceEntity.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set metadataComplete back to null, check defaults from java - ormContextEntity.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - } - - public void testModifyCacheDisableHits() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - // set context cache size, check resource - - ormContextEntity.getCaching().setSpecifiedDisableHits(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceEntity.getCache().getDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - // set context cache size to null, check resource - - ormContextEntity.getCaching().setSpecifiedDisableHits(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - } - - public void testUpdateCacheShared() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getShared()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set xml cache size, check settings - resourceEntity.getCache().setShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceEntity.getCache().getShared()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedShared(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceEntity.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - // set xml cache always refresh to false - resourceEntity.getCache().setShared(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceEntity.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedShared()); - - // clear xml cache always refresh, check defaults - resourceEntity.getCache().setShared(null); - - assertEquals(null, resourceEntity.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(false, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set metadataComplete back to null, check defaults from java - ormContextEntity.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(false, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - } - - public void testModifyCacheShared() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - // set context cache size, check resource - - ormContextEntity.getCaching().setSpecifiedShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceEntity.getCache().getShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - // set context cache size to null, check resource - - ormContextEntity.getCaching().setSpecifiedShared(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - } - public void testSetSpecifiedSharedFalseUnsetsOtherCacheSettings() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - ormContextCaching.setSpecifiedType(EclipseLinkCacheType.HARD_WEAK); - ormContextCaching.setSpecifiedSize(Integer.valueOf(500)); - ormContextCaching.setSpecifiedAlwaysRefresh(Boolean.FALSE); - ormContextCaching.setSpecifiedRefreshOnlyIfNewer(Boolean.FALSE); - ormContextCaching.setSpecifiedDisableHits(Boolean.FALSE); - ormContextCaching.setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - ormContextCaching.setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE); - ormContextCaching.setExpiry(Integer.valueOf(8000)); - - ormContextCaching.setSpecifiedShared(Boolean.FALSE); - - assertEquals(null, ormContextCaching.getSpecifiedType()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - assertEquals(null, ormContextCaching.getExpiry()); - - - //existence checking is the only thing that isn't unset when shared is set to false - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - ormContextCaching.setSpecifiedShared(null); - EclipseLinkTimeOfDay timeOfDayExpiry = ormContextCaching.addExpiryTimeOfDay(); - timeOfDayExpiry.setHour(Integer.valueOf(5)); - - ormContextCaching.setSpecifiedShared(Boolean.FALSE); - assertNull(ormContextCaching.getExpiryTimeOfDay()); - assertEquals(Boolean.FALSE, resourceEntity.getCache().getShared()); - assertNull(resourceEntity.getCache().getExpiryTimeOfDay()); - } - - public void testUpdateExistenceChecking() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set xml existence checking, check settings - resourceEntity.setExistenceChecking(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - - // set java cache existence checking, check defaults - - javaContextCaching.setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - // clear xml existence checking, check defaults - resourceEntity.setExistenceChecking(null); - - assertEquals(null, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - ormContextEntity.setSpecifiedMetadataComplete(null); - } - - public void testModifyExistenceChecking() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set context cache existence checking, check resource - - ormContextEntity.getCaching().setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_EXISTENCE); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - // set context existence checking to null, check resource - - ormContextEntity.getCaching().setSpecifiedExistenceType(null); - - assertEquals(null, resourceEntity.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - } - - public void testUpdateCacheExpiry() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(null, javaContextCaching.getExpiry()); - assertEquals(null, ormContextCaching.getExpiry()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getExpiry()); - assertEquals(null, javaContextCaching.getExpiry()); - assertEquals(null, ormContextCaching.getExpiry()); - - - // set xml cache expiry, check settings - resourceEntity.getCache().setExpiry(new Integer(45)); - assertEquals(new Integer(45), resourceEntity.getCache().getExpiry()); - assertEquals(null, javaContextCaching.getExpiry()); - assertEquals(new Integer(45), ormContextCaching.getExpiry()); - - - // set java cache expiry, check defaults - - javaContextCaching.setExpiry(new Integer(55)); - - assertEquals(new Integer(45), resourceEntity.getCache().getExpiry()); - assertEquals(new Integer(55), javaContextCaching.getExpiry()); - assertEquals(new Integer(45), ormContextCaching.getExpiry()); - - // clear xml cache expiry to null, check defaults - resourceEntity.getCache().setExpiry(null); - - assertEquals(null, resourceEntity.getCache().getExpiry()); - assertEquals(new Integer(55), javaContextCaching.getExpiry()); - assertEquals(null, ormContextCaching.getExpiry()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(new Integer(55), javaContextCaching.getExpiry()); - assertEquals(null, ormContextCaching.getExpiry()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(new Integer(55), javaContextCaching.getExpiry()); - assertEquals(null, ormContextCaching.getExpiry()); - - - // set metadataComplete back to null, check defaults from java - ormContextEntity.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(new Integer(55), javaContextCaching.getExpiry()); - assertEquals(null, ormContextCaching.getExpiry()); - } - - public void testModifyCacheExpiry() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(null, ormContextCaching.getExpiry()); - - // set context cache expiry, check resource - - ormContextEntity.getCaching().setExpiry(new Integer(60)); - assertEquals(new Integer(60), resourceEntity.getCache().getExpiry()); - assertEquals(new Integer(60), ormContextCaching.getExpiry()); - - // set context cache size to null, check resource - - ormContextEntity.getCaching().setExpiry(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(null, ormContextCaching.getExpiry()); - } - - public void testUpdateCacheExpiryTimeOfDay() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkEntity) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(null, javaContextCaching.getExpiryTimeOfDay()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - - // set xml cache, check defaults - resourceEntity.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceEntity.getCache().getExpiryTimeOfDay()); - assertEquals(null, javaContextCaching.getExpiryTimeOfDay()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - - - // set xml cache expiry, check settings - resourceEntity.getCache().setExpiryTimeOfDay(EclipseLinkOrmFactory.eINSTANCE.createXmlTimeOfDay()); - resourceEntity.getCache().getExpiryTimeOfDay().setHour(new Integer(10)); - assertEquals(new Integer(10), resourceEntity.getCache().getExpiryTimeOfDay().getHour()); - assertEquals(null, javaContextCaching.getExpiryTimeOfDay()); - assertEquals(new Integer(10), ormContextCaching.getExpiryTimeOfDay().getHour()); - - - // set java cache expiry, check defaults - - javaContextCaching.addExpiryTimeOfDay(); - javaContextCaching.getExpiryTimeOfDay().setHour(new Integer(12)); - - assertEquals(new Integer(10), resourceEntity.getCache().getExpiryTimeOfDay().getHour()); - assertEquals(new Integer(12), javaContextCaching.getExpiryTimeOfDay().getHour()); - assertEquals(new Integer(10), ormContextCaching.getExpiryTimeOfDay().getHour()); - - // clear xml cache expiry to null, check defaults - resourceEntity.getCache().setExpiryTimeOfDay(null); - - assertEquals(null, resourceEntity.getCache().getExpiryTimeOfDay()); - assertEquals(new Integer(12), javaContextCaching.getExpiryTimeOfDay().getHour()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - - - // clear xml cache, check defaults - resourceEntity.setCache(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(new Integer(12), javaContextCaching.getExpiryTimeOfDay().getHour()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - - - // set metadataComplete to True, check defaults not from java - - ormContextEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(new Integer(12), javaContextCaching.getExpiryTimeOfDay().getHour()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - - - // set metadataComplete back to null, check defaults from java - ormContextEntity.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceEntity.getCache()); - assertEquals(new Integer(12), javaContextCaching.getExpiryTimeOfDay().getHour()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - } - - public void testModifyCacheExpiryTimeOfDay() throws Exception { - createTestEntityForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextEntity.getCaching(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - // check defaults - - assertEquals(null, resourceEntity.getCache()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - - // set context cache expiry, check resource - - ormContextEntity.getCaching().addExpiryTimeOfDay().setHour(new Integer(12)); - assertEquals(new Integer(12), resourceEntity.getCache().getExpiryTimeOfDay().getHour()); - assertEquals(new Integer(12), ormContextCaching.getExpiryTimeOfDay().getHour()); - - // set context expiry time of day minute, check resource - - ormContextEntity.getCaching().getExpiryTimeOfDay().setMinute(new Integer(35)); - - assertEquals(new Integer(12), resourceEntity.getCache().getExpiryTimeOfDay().getHour()); - assertEquals(new Integer(12), ormContextCaching.getExpiryTimeOfDay().getHour()); - assertEquals(new Integer(35), resourceEntity.getCache().getExpiryTimeOfDay().getMinute()); - assertEquals(new Integer(35), ormContextCaching.getExpiryTimeOfDay().getMinute()); - - // set context expiry time of day null, check resource - - ormContextEntity.getCaching().removeExpiryTimeOfDay(); - assertEquals(null, resourceEntity.getCache()); - assertEquals(null, ormContextCaching.getExpiryTimeOfDay()); - } - - public void testUpdateCustomConverters() throws Exception { - createTestEntityForConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceEntity.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlConverter resourceConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceEntity.getConverters().add(resourceConverter); - resourceConverter.setClassName("Foo"); - resourceConverter.setName("myConverter"); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, resourceEntity.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlConverter resourceConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceEntity.getConverters().add(0, resourceConverter2); - resourceConverter2.setClassName("Foo2"); - resourceConverter2.setName("myConverter2"); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, resourceEntity.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntity.getConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, resourceEntity.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, resourceEntity.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getConverters().remove(resourceConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceEntity.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyCustomConverters() throws Exception { - createTestEntityForConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceEntity.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter = ormContextConverterHolder.addCustomConverter(0); - contextConverter.setConverterClass("Foo"); - contextConverter.setName("myConverter"); - - assertEquals(1, resourceEntity.getConverters().size()); - assertEquals("Foo", resourceEntity.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceEntity.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter2 = ormContextConverterHolder.addCustomConverter(0); - contextConverter2.setConverterClass("Foo2"); - contextConverter2.setName("myConverter2"); - - assertEquals(2, resourceEntity.getConverters().size()); - assertEquals("Foo2", resourceEntity.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceEntity.getConverters().get(0).getName()); - assertEquals("Foo", resourceEntity.getConverters().get(1).getClassName()); - assertEquals("myConverter", resourceEntity.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveCustomConverter(0, 1); - - assertEquals(2, resourceEntity.getConverters().size()); - assertEquals("Foo", resourceEntity.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceEntity.getConverters().get(0).getName()); - assertEquals("Foo2", resourceEntity.getConverters().get(1).getClassName()); - assertEquals("myConverter2", resourceEntity.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(0); - - assertEquals(1, resourceEntity.getConverters().size()); - assertEquals("Foo2", resourceEntity.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceEntity.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(contextConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceEntity.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateTypeConverters() throws Exception { - createTestEntityForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceEntity.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceEntity.getTypeConverters().add(resourceTypeConverter); - resourceTypeConverter.setDataType("Foo"); - resourceTypeConverter.setName("myTypeConverter"); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, resourceEntity.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceEntity.getTypeConverters().add(0, resourceTypeConverter2); - resourceTypeConverter2.setDataType("Foo2"); - resourceTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, resourceEntity.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntity.getTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, resourceEntity.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, resourceEntity.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getTypeConverters().remove(resourceTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceEntity.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyTypeConverters() throws Exception { - createTestEntityForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceEntity.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter.setDataType("Foo"); - contextTypeConverter.setName("myTypeConverter"); - - assertEquals(1, resourceEntity.getTypeConverters().size()); - assertEquals("Foo", resourceEntity.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceEntity.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter2 = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter2.setDataType("Foo2"); - contextTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, resourceEntity.getTypeConverters().size()); - assertEquals("Foo2", resourceEntity.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceEntity.getTypeConverters().get(0).getName()); - assertEquals("Foo", resourceEntity.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter", resourceEntity.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveTypeConverter(0, 1); - - assertEquals(2, resourceEntity.getTypeConverters().size()); - assertEquals("Foo", resourceEntity.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceEntity.getTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceEntity.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter2", resourceEntity.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(0); - - assertEquals(1, resourceEntity.getTypeConverters().size()); - assertEquals("Foo2", resourceEntity.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceEntity.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(contextTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceEntity.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateObjectTypeConverters() throws Exception { - createTestEntityForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceEntity.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceEntity.getObjectTypeConverters().add(resourceObjectTypeConverter); - resourceObjectTypeConverter.setDataType("Foo"); - resourceObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceEntity.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceEntity.getObjectTypeConverters().add(0, resourceObjectTypeConverter2); - resourceObjectTypeConverter2.setDataType("Foo2"); - resourceObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceEntity.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntity.getObjectTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceEntity.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getObjectTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceEntity.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getObjectTypeConverters().remove(resourceObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceEntity.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyObjectTypeConverters() throws Exception { - createTestEntityForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceEntity.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter.setDataType("Foo"); - contextObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, resourceEntity.getObjectTypeConverters().size()); - assertEquals("Foo", resourceEntity.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceEntity.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter2 = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter2.setDataType("Foo2"); - contextObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, resourceEntity.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceEntity.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEntity.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo", resourceEntity.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter", resourceEntity.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveObjectTypeConverter(0, 1); - - assertEquals(2, resourceEntity.getObjectTypeConverters().size()); - assertEquals("Foo", resourceEntity.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceEntity.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceEntity.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEntity.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(0); - - assertEquals(1, resourceEntity.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceEntity.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceEntity.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(contextObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceEntity.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateStructConverters() throws Exception { - createTestEntityForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceEntity.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlStructConverter resourceStructConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceEntity.getStructConverters().add(resourceStructConverter); - resourceStructConverter.setConverter("Foo"); - resourceStructConverter.setName("myStructConverter"); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, resourceEntity.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlStructConverter resourceStructConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceEntity.getStructConverters().add(0, resourceStructConverter2); - resourceStructConverter2.setConverter("Foo2"); - resourceStructConverter2.setName("myStructConverter2"); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, resourceEntity.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceEntity.getStructConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, resourceEntity.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getStructConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, resourceEntity.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceEntity.getStructConverters().remove(resourceStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceEntity.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyStructConverters() throws Exception { - createTestEntityForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkEntity ormContextEntity = (OrmEclipseLinkEntity) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextEntity.getConverterContainer(); - XmlEntity resourceEntity = (XmlEntity) getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceEntity.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter = ormContextConverterHolder.addStructConverter(0); - contextStructConverter.setConverterClass("Foo"); - contextStructConverter.setName("myStructConverter"); - - assertEquals(1, resourceEntity.getStructConverters().size()); - assertEquals("Foo", resourceEntity.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceEntity.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter2 = ormContextConverterHolder.addStructConverter(0); - contextStructConverter2.setConverterClass("Foo2"); - contextStructConverter2.setName("myStructConverter2"); - - assertEquals(2, resourceEntity.getStructConverters().size()); - assertEquals("Foo2", resourceEntity.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceEntity.getStructConverters().get(0).getName()); - assertEquals("Foo", resourceEntity.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter", resourceEntity.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveStructConverter(0, 1); - - assertEquals(2, resourceEntity.getStructConverters().size()); - assertEquals("Foo", resourceEntity.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceEntity.getStructConverters().get(0).getName()); - assertEquals("Foo2", resourceEntity.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter2", resourceEntity.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(0); - - assertEquals(1, resourceEntity.getStructConverters().size()); - assertEquals("Foo2", resourceEntity.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceEntity.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(contextStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceEntity.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java deleted file mode 100644 index 411ace0d79..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java +++ /dev/null @@ -1,389 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkBasicMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkIdMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkIdMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlId; - -@SuppressWarnings("nls") -public class EclipseLinkOrmIdMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmIdMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableIdDate() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, EclipseLink.MUTABLE, "java.util.Date"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append(" @Mutable").append(CR); - sb.append(" private Date myDate;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - public void testUpdateMutable() throws Exception { - createTestEntityWithIdMapping(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - OrmEclipseLinkIdMapping contextId = - (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlId resourceId = - (XmlId) resourceEntity.getAttributes().getIds().get(0); - EclipseLinkIdMapping javaIdMapping = (EclipseLinkIdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - // check defaults - - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceId.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceId.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceId.setMutable(null); - - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // TODO - test defaults for java serializable and date/time types, - // with and without persistence property - - // set mutable on java basic mapping - - javaIdMapping.getMutable().setSpecifiedMutable(Boolean.FALSE); - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - assertFalse(javaIdMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - EclipseLinkIdMapping virtualIdMapping = (EclipseLinkIdMapping) ormPersistentAttribute2.getMapping(); - - assertNull(resourceId.getMutable()); - assertTrue(virtualIdMapping.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, virtualIdMapping.getMutable().getSpecifiedMutable()); - assertFalse(virtualIdMapping.getMutable().isMutable()); - assertFalse(javaIdMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - EclipseLinkBasicMapping virtualBasicMapping = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(resourceId.getMutable()); - assertTrue(virtualBasicMapping.getMutable().isDefaultMutable()); - assertNull(virtualBasicMapping.getMutable().getSpecifiedMutable()); - assertTrue(virtualBasicMapping.getMutable().isMutable()); - assertFalse(javaIdMapping.getMutable().isMutable()); - } - - public void testUpdateMutableDate() throws Exception { - createTestEntityWithMutableIdDate(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "myDate"); - OrmEclipseLinkIdMapping contextId = - (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlId resourceId = - (XmlId) resourceEntity.getAttributes().getIds().get(0); - EclipseLinkIdMapping javaIdMapping = (EclipseLinkIdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("myDate").getMapping(); - - // check defaults - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceId.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceId.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceId.setMutable(null); - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.TRUE); - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.FALSE); - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(null); - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set mutable on java id mapping - - javaIdMapping.getMutable().setSpecifiedMutable(Boolean.TRUE); - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - assertTrue(javaIdMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("myDate"); - EclipseLinkIdMapping virtualIdMapping = (EclipseLinkIdMapping) ormPersistentAttribute2.getMapping(); - - assertNull(resourceId.getMutable()); - assertFalse(virtualIdMapping.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, virtualIdMapping.getMutable().getSpecifiedMutable()); - assertTrue(virtualIdMapping.getMutable().isMutable()); - assertTrue(javaIdMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("myDate"); - EclipseLinkBasicMapping virtualBasicMapping = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(resourceId.getMutable()); - assertFalse(virtualBasicMapping.getMutable().isDefaultMutable()); - assertNull(virtualBasicMapping.getMutable().getSpecifiedMutable()); - assertFalse(virtualBasicMapping.getMutable().isMutable()); - assertTrue(javaIdMapping.getMutable().isMutable()); - } - - public void testModifyMutable() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "basic"); - OrmEclipseLinkIdMapping contextId = - (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlId resourceId = - (XmlId) resourceEntity.getAttributes().getIds().get(0); - - // check defaults - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set context mutable to true, check resource - - contextId.getMutable().setSpecifiedMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // set context mutable to false, check resource - - contextId.getMutable().setSpecifiedMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set context read only to null, check resource - - contextId.getMutable().setSpecifiedMutable(null); - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - } - - public void testUpdateConvert() throws Exception { - createTestEntityWithIdMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId basicResource = (XmlId) getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - JavaIdMapping javaIdMapping = (JavaIdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob in the resource model, verify context model updated - basicResource.setConvert("myConvert"); - assertEquals(EclipseLinkConvert.class, ormIdMapping.getConverter().getType()); - assertEquals("myConvert", basicResource.getConvert()); - - //set lob to null in the resource model - basicResource.setConvert(null); - assertNull(ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - - javaIdMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) javaIdMapping.getConverter()).setSpecifiedConverterName("foo"); - - assertNull(ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaIdMapping.getConverter()).getSpecifiedConverterName()); - - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - IdMapping virtualIdMapping = (IdMapping) ormPersistentAttribute2.getMapping(); - - assertEquals(EclipseLinkConvert.class, virtualIdMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) virtualIdMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaIdMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) javaIdMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals(EclipseLinkConvert.class, virtualIdMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) virtualIdMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("bar", ((EclipseLinkConvert) javaIdMapping.getConverter()).getSpecifiedConverterName()); - - javaIdMapping.setConverter(null); - assertNull(virtualIdMapping.getConverter().getType()); - assertNull(basicResource.getConvert()); - assertNull(javaIdMapping.getConverter().getType()); - } - - public void testModifyConvert() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId basicResource = (XmlId) getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getConverter().getType()); - assertNull(basicResource.getConvert()); - - //set lob in the context model, verify resource model updated - ormIdMapping.setConverter(EclipseLinkConvert.class); - assertEquals("", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.class, ormIdMapping.getConverter().getType()); - - ((EclipseLinkConvert) ormIdMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals("bar", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.class, ormIdMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) ormIdMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) ormIdMapping.getConverter()).setSpecifiedConverterName(null); - - assertNull(ormIdMapping.getConverter().getType()); - assertNull(basicResource.getConvert()); - - //set lob to false in the context model - ormIdMapping.setConverter(null); - assertNull(ormIdMapping.getConverter().getType()); - assertNull(basicResource.getConvert()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java deleted file mode 100644 index 15e409bafd..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java +++ /dev/null @@ -1,383 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkManyToManyMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlManyToMany; - -@SuppressWarnings("nls") -public class EclipseLinkOrmManyToManyMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmManyToManyMappingTests(String name) { - super(name); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("import java.util.Collection;"); - sb.append(CR); - sb.append("import ").append(JPA.MANY_TO_MANY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.JOIN_TABLE).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.JOIN_COLUMN).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" @JoinTable(name=\"DEP_EMP\", joinColumns=@JoinColumn(name=\"DEPT_ID\"), inverseJoinColumns=@JoinColumn(name=\"EMP_ID\"))").append(CR); - sb.append(" private Collection employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - public void testUpdateJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - EclipseLinkRelationshipMapping contextManyToMany = - (EclipseLinkRelationshipMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity) getXmlEntityMappings().getEntities().get(0); - XmlManyToMany resourceManyToMany = - (XmlManyToMany) resourceEntity.getAttributes().getManyToManys().get(0); - - // check defaults - - assertNull(resourceManyToMany.getJoinFetch()); - assertNull(contextManyToMany.getJoinFetch().getValue()); - - // set xml join fetch to INNER, check context - - resourceManyToMany.setJoinFetch(XmlJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceManyToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextManyToMany.getJoinFetch().getValue()); - - // set xml join fetch to OUTER, check context - - resourceManyToMany.setJoinFetch(XmlJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceManyToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextManyToMany.getJoinFetch().getValue()); - - // set xml join fetch to null, check context - - resourceManyToMany.setJoinFetch(null); - - assertNull(resourceManyToMany.getJoinFetch()); - assertNull(contextManyToMany.getJoinFetch().getValue()); - } - - public void testModifyJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - EclipseLinkRelationshipMapping contextManyToMany = - (EclipseLinkRelationshipMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlManyToMany resourceManyToMany = - (XmlManyToMany) resourceEntity.getAttributes().getManyToManys().get(0); - - // check defaults - - assertNull(resourceManyToMany.getJoinFetch()); - assertNull(contextManyToMany.getJoinFetch().getValue()); - - // set context join fetch to INNER, check resource - - contextManyToMany.getJoinFetch().setValue(EclipseLinkJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceManyToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextManyToMany.getJoinFetch().getValue()); - - // set context join fetch to OUTER, check resource - - contextManyToMany.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceManyToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextManyToMany.getJoinFetch().getValue()); - - // set context join fetch to null, check resource - - contextManyToMany.getJoinFetch().setValue(null); - - assertNull(resourceManyToMany.getJoinFetch()); - assertNull(contextManyToMany.getJoinFetch().getValue()); - } - - public void testJoinFetchDefault() throws Exception { - createTestEmployee(); - createTestDepartment(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Department"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Employee"); - - OrmPersistentType departmentPersistentType = getEntityMappings().getPersistentTypes().iterator().next(); - EclipseLinkRelationshipMapping manyToMany = (EclipseLinkRelationshipMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - - assertNull(manyToMany.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - EclipseLinkOneToManyMapping oneToMany = (EclipseLinkOneToManyMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - assertNull(oneToMany.getJoinFetch().getValue()); - - - EclipseLinkRelationshipMapping javaRelationshipMapping = (EclipseLinkRelationshipMapping) departmentPersistentType.getJavaPersistentType().getAttributeNamed("employees").getMapping(); - javaRelationshipMapping.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - assertNull(oneToMany.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - manyToMany = (EclipseLinkRelationshipMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - assertEquals(EclipseLinkJoinFetchType.OUTER, manyToMany.getJoinFetch().getValue()); - } - - public void testDefaultJoinTable() throws Exception { - createTestEmployee(); - createTestDepartment(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Department"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Employee"); - - OrmPersistentType departmentPersistentType = getEntityMappings().getPersistentTypes().iterator().next(); - OrmReadOnlyPersistentAttribute attribute = departmentPersistentType.getAttributeNamed("employees"); - ManyToManyMapping manyToMany = (ManyToManyMapping) attribute.getMapping(); - - assertEquals(true, attribute.isVirtual()); - JoinTable ormJoinTable = manyToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("DEP_EMP", ormJoinTable.getName()); - assertEquals("DEPT_ID", ormJoinTable.specifiedJoinColumns().next().getName()); - assertEquals("id", ormJoinTable.specifiedJoinColumns().next().getReferencedColumnName()); - assertEquals("EMP_ID", ormJoinTable.specifiedInverseJoinColumns().next().getName()); - assertEquals("empId", ormJoinTable.specifiedInverseJoinColumns().next().getReferencedColumnName()); - - //set metadata-complete and verify JoinTable info is not taken from the java - departmentPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - departmentPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - attribute = departmentPersistentType.getAttributeNamed("employees"); - OneToManyMapping oneToMany = (OneToManyMapping) attribute.getMapping(); - - assertEquals(true, attribute.isVirtual()); - ormJoinTable = oneToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("Department_Employee", ormJoinTable.getName()); - assertEquals("Department_id", ormJoinTable.getDefaultJoinColumn().getName()); - assertEquals("id", ormJoinTable.getDefaultJoinColumn().getReferencedColumnName()); - assertEquals("employees_empId", ormJoinTable.getDefaultInverseJoinColumn().getName()); - assertEquals("empId", ormJoinTable.getDefaultInverseJoinColumn().getReferencedColumnName()); - - //set metadata-complete to false, add mapping to orm.xml verify JoinTable info is not taken from the java - departmentPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); - attribute = departmentPersistentType.getAttributeNamed("employees"); - manyToMany = (ManyToManyMapping) attribute.getMapping(); - assertEquals(true, attribute.isVirtual()); - ormJoinTable = manyToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("DEP_EMP", ormJoinTable.getName()); - assertEquals("DEPT_ID", ormJoinTable.specifiedJoinColumns().next().getName()); - assertEquals("id", ormJoinTable.specifiedJoinColumns().next().getReferencedColumnName()); - assertEquals("EMP_ID", ormJoinTable.specifiedInverseJoinColumns().next().getName()); - assertEquals("empId", ormJoinTable.specifiedInverseJoinColumns().next().getReferencedColumnName()); - - - departmentPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "employees"); - attribute = departmentPersistentType.getAttributeNamed("employees"); - manyToMany = (ManyToManyMapping) attribute.getMapping(); - assertEquals(false, attribute.isVirtual()); - ormJoinTable = manyToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("Department_Employee", ormJoinTable.getName()); - assertEquals(0, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals("Department_id", ormJoinTable.getDefaultJoinColumn().getName()); - assertEquals("id", ormJoinTable.getDefaultJoinColumn().getReferencedColumnName()); - assertEquals(0, ormJoinTable.specifiedInverseJoinColumnsSize()); - assertEquals("employees_empId", ormJoinTable.getDefaultInverseJoinColumn().getName()); - assertEquals("empId", ormJoinTable.getDefaultInverseJoinColumn().getReferencedColumnName()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualManyToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualManyToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualManyToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = virtualManyToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - - assertTrue(virtualManyToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertEquals(EclipseLinkJoinFetchType.INNER, ((EclipseLinkJoinFetchMapping) virtualManyToManyMapping).getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - OrmPersistentAttribute ormPersistentAttribute = virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - - OrmEclipseLinkManyToManyMapping ormManyToManyMapping = (OrmEclipseLinkManyToManyMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch()); - assertEquals("test.Address", ormManyToManyMapping.getTargetEntity()); - assertNull(ormManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = ormManyToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertEquals(null, ormManyToManyMapping.getJoinFetch().getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java deleted file mode 100644 index c1b3df42f5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java +++ /dev/null @@ -1,321 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkManyToOneMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlManyToOne; - -@SuppressWarnings("nls") -public class EclipseLinkOrmManyToOneMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmManyToOneMappingTests(String name) { - super(name); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import ").append(JPA.MANY_TO_ONE).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Employee employee;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - public void testUpdateJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOne"); - EclipseLinkRelationshipMapping contextManyToOne = - (EclipseLinkRelationshipMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity) getXmlEntityMappings().getEntities().get(0); - XmlManyToOne resourceManyToOne = - (XmlManyToOne) resourceEntity.getAttributes().getManyToOnes().get(0); - - // check defaults - - assertNull(resourceManyToOne.getJoinFetch()); - assertNull(contextManyToOne.getJoinFetch().getValue()); - - // set xml join fetch to INNER, check context - - resourceManyToOne.setJoinFetch(XmlJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceManyToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextManyToOne.getJoinFetch().getValue()); - - // set xml join fetch to OUTER, check context - - resourceManyToOne.setJoinFetch(XmlJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceManyToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextManyToOne.getJoinFetch().getValue()); - - // set xml join fetch to null, check context - - resourceManyToOne.setJoinFetch(null); - - assertNull(resourceManyToOne.getJoinFetch()); - assertNull(contextManyToOne.getJoinFetch().getValue()); - } - - public void testModifyJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOne"); - EclipseLinkRelationshipMapping contextManyToOne = - (EclipseLinkRelationshipMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlManyToOne resourceManyToOne = - (XmlManyToOne) resourceEntity.getAttributes().getManyToOnes().get(0); - - // check defaults - - assertNull(resourceManyToOne.getJoinFetch()); - assertNull(contextManyToOne.getJoinFetch().getValue()); - - // set context join fetch to INNER, check resource - - contextManyToOne.getJoinFetch().setValue(EclipseLinkJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceManyToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextManyToOne.getJoinFetch().getValue()); - - // set context join fetch to OUTER, check resource - - contextManyToOne.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceManyToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextManyToOne.getJoinFetch().getValue()); - - // set context join fetch to null, check resource - - contextManyToOne.getJoinFetch().setValue(null); - - assertNull(resourceManyToOne.getJoinFetch()); - assertNull(contextManyToOne.getJoinFetch().getValue()); - } - - public void testJoinFetchDefaultFromJava() throws Exception { - createTestEmployee(); - createTestDepartment(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Department"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Employee"); - - OrmPersistentType departmentPersistentType = getEntityMappings().getPersistentTypes().iterator().next(); - EclipseLinkRelationshipMapping manyToOneMapping = (EclipseLinkRelationshipMapping) departmentPersistentType.getAttributeNamed("employee").getMapping(); - - assertNull(manyToOneMapping.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - EclipseLinkOneToOneMapping oneToOne = (EclipseLinkOneToOneMapping) departmentPersistentType.getAttributeNamed("employee").getMapping(); - assertNull(oneToOne.getJoinFetch().getValue()); - - - EclipseLinkRelationshipMapping javaRelationshipMapping = (EclipseLinkRelationshipMapping) departmentPersistentType.getJavaPersistentType().getAttributeNamed("employee").getMapping(); - javaRelationshipMapping.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - manyToOneMapping = (EclipseLinkRelationshipMapping) departmentPersistentType.getAttributeNamed("employee").getMapping(); - assertNull(manyToOneMapping.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - manyToOneMapping = (EclipseLinkRelationshipMapping) departmentPersistentType.getAttributeNamed("employee").getMapping(); - assertEquals(EclipseLinkJoinFetchType.OUTER, manyToOneMapping.getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToOneMapping virtualManyToOneMapping = (ManyToOneMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualManyToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualManyToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualManyToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualManyToOneMapping.getSpecifiedTargetEntity()); - - JoinColumn virtualJoinColumn = virtualManyToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", virtualJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", virtualJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, virtualJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", virtualJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", virtualJoinColumn.getSpecifiedTable()); - - Cascade cascade = virtualManyToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - - assertEquals(EclipseLinkJoinFetchType.INNER, ((EclipseLinkJoinFetchMapping) virtualManyToOneMapping).getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - OrmEclipseLinkManyToOneMapping ormManyToOneMapping = (OrmEclipseLinkManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch()); - assertEquals(true, ormManyToOneMapping.isDefaultOptional()); - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - - assertEquals(null, ormManyToOneMapping.getJoinFetch().getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmMappedSuperclassTests.java deleted file mode 100644 index eabb32b8be..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmMappedSuperclassTests.java +++ /dev/null @@ -1,2147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheCoordinationType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkExistenceType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkConverterContainer; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlStructConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTypeConverter; - -@SuppressWarnings("nls") -public class EclipseLinkOrmMappedSuperclassTests extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmMappedSuperclassTests(String name) { - super(name); - } - - - private ICompilationUnit createTestMappedSuperclassForReadOnly() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.READ_ONLY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForCustomizer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CHANGE_TRACKING); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForCaching() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForObjectTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForStructConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - public void testUpdateReadOnly() throws Exception { - createTestMappedSuperclassForReadOnly(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkMappedSuperclass javaContextMappedSuperclass = (JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to false, check override - - resourceMappedSuperclass.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceMappedSuperclass.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // clear xml read only, set java read only to true, check defaults - - resourceMappedSuperclass.setReadOnly(null); - javaContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - // set xml read only to false, check override - - resourceMappedSuperclass.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceMappedSuperclass.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // clear xml read only, set java read only to false, check defaults - - resourceMappedSuperclass.setReadOnly(null); - javaContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.FALSE); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to false, check override - - resourceMappedSuperclass.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceMappedSuperclass.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - } - - public void testModifyReadOnly() throws Exception { - createTestMappedSuperclassForReadOnly(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to true, check resource - - ormContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to false, check resource - - ormContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to null, check resource - - ormContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(null); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - } - - public void testUpdateCustomizerClass() throws Exception { - createTestMappedSuperclassForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkMappedSuperclass javaContextMappedSuperclass = (JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set xml customizer, check defaults - resourceMappedSuperclass.setCustomizer(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(resourceMappedSuperclass.getCustomizer().getClassName()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - - // set xml customizer class, check override - - resourceMappedSuperclass.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceMappedSuperclass.getCustomizer().getClassName()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // clear xml customizer class, set java customizer class, check defaults - - resourceMappedSuperclass.getCustomizer().setClassName(null); - javaContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass("bar"); - - assertNull(resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("bar", javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("bar", javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - // set xml customizer class, check override - - resourceMappedSuperclass.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("bar", javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - //set xml customizer null - javaContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass(null); - resourceMappedSuperclass.setCustomizer(null); - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - } - - public void testModifyCustomizerClass() throws Exception { - createTestMappedSuperclassForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer, check resource - - ormContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass("foo"); - - assertEquals("foo", resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer to null, check resource - - ormContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass(null); - - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - } - - public void testUpdateChangeTracking() throws Exception { - createTestMappedSuperclassForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkMappedSuperclass javaContextMappedSuperclass = (JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to ATTRIBUTE, check context - - resourceMappedSuperclass.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to OBJECT, check context - - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to DEFERRED, check context - - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to AUTO, check context - - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // clear xml change tracking, set java change tracking, check defaults - - resourceMappedSuperclass.setChangeTracking(null); - javaContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // unset metadataComplete, set xml change tracking to OBJECT, check context - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - resourceMappedSuperclass.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - } - - public void testModifyChangeTracking() throws Exception { - createTestMappedSuperclassForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to ATTRIBUTE, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to OBJECT, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to DEFERRED, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to AUTO, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to null, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(null); - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - } - - public void testUpdateCacheType() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // set xml cache type, check settings - resourceMappedSuperclass.getCache().setType(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getSpecifiedType()); - - - // set java cache type, check defaults - - javaContextCaching.setSpecifiedType(EclipseLinkCacheType.WEAK); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getSpecifiedType()); - - // clear xml cache type, check defaults - resourceMappedSuperclass.getCache().setType(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheType() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - // set context cache type, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedType(EclipseLinkCacheType.HARD_WEAK); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.HARD_WEAK, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, ormContextCaching.getSpecifiedType()); - - // set context customizer to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedType(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - } - - public void testUpdateCacheCoordinationType() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // set xml cache type, check settings - resourceMappedSuperclass.getCache().setCoordinationType(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getSpecifiedCoordinationType()); - - - // set java cache type, check defaults - - javaContextCaching.setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getSpecifiedCoordinationType()); - - // clear xml cache type, check defaults - resourceMappedSuperclass.getCache().setCoordinationType(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheCoordinationType() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - // set context cache coordination type, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getSpecifiedCoordinationType()); - - // set context coordination type to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedCoordinationType(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - } - - - public void testUpdateCacheSize() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getSize()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // set xml cache size, check settings - resourceMappedSuperclass.getCache().setSize(new Integer(105)); - assertEquals(new Integer(105), resourceMappedSuperclass.getCache().getSize()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(105, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(105), ormContextCaching.getSpecifiedSize()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedSize(new Integer(50)); - - assertEquals(new Integer(105), resourceMappedSuperclass.getCache().getSize()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(105, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(105), ormContextCaching.getSpecifiedSize()); - - // clear xml cache size, check defaults - resourceMappedSuperclass.getCache().setSize(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getSize()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(50, ormContextCaching.getSize()); - assertEquals(50, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheSize() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedSize(new Integer(50)); - assertEquals(new Integer(50), resourceMappedSuperclass.getCache().getSize()); - assertEquals(50, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(50), ormContextCaching.getSpecifiedSize()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedSize(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - } - - public void testUpdateCacheAlwaysRefresh() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set xml cache always refresh, check settings - resourceMappedSuperclass.getCache().setAlwaysRefresh(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set java cache always refresh, check defaults - - javaContextCaching.setSpecifiedAlwaysRefresh(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setAlwaysRefresh(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setAlwaysRefresh(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - } - - public void testModifyCacheAlwaysRefresh() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedAlwaysRefresh(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedAlwaysRefresh(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - } - - public void testUpdateCacheRefreshOnlyIfNewer() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set xml cache size, check settings - resourceMappedSuperclass.getCache().setRefreshOnlyIfNewer(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setRefreshOnlyIfNewer(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setRefreshOnlyIfNewer(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - } - - public void testModifyCacheRefreshOnlyIfNewer() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedRefreshOnlyIfNewer(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - } - - public void testUpdateCacheDisableHits() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set xml cache size, check settings - resourceMappedSuperclass.getCache().setDisableHits(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedDisableHits(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setDisableHits(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedDisableHits()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setDisableHits(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - } - - public void testModifyCacheDisableHits() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedDisableHits(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedDisableHits(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - } - - public void testUpdateCacheShared() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getShared()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set xml cache size, check settings - resourceMappedSuperclass.getCache().setShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedShared(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setShared(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedShared()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setShared(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(false, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(false, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - } - - public void testModifyCacheShared() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedShared(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - } - - public void testUpdateExistenceChecking() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set xml existence checking, check settings - resourceMappedSuperclass.setExistenceChecking(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - - // set java cache existence checking, check defaults - - javaContextCaching.setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - // clear xml existence checking, check defaults - resourceMappedSuperclass.setExistenceChecking(null); - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyExistenceChecking() throws Exception { - createTestMappedSuperclassForCaching(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set context cache existence checking, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_EXISTENCE); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - // set context existence checking to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedExistenceType(null); - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - } - public void testUpdateCustomConverters() throws Exception { - createTestMappedSuperclassForConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlConverter resourceConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceMappedSuperclass.getConverters().add(resourceConverter); - resourceConverter.setClassName("Foo"); - resourceConverter.setName("myConverter"); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlConverter resourceConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceMappedSuperclass.getConverters().add(0, resourceConverter2); - resourceConverter2.setClassName("Foo2"); - resourceConverter2.setName("myConverter2"); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getConverters().remove(resourceConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyCustomConverters() throws Exception { - createTestMappedSuperclassForConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter = ormContextConverterHolder.addCustomConverter(0); - contextConverter.setConverterClass("Foo"); - contextConverter.setName("myConverter"); - - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter2 = ormContextConverterHolder.addCustomConverter(0); - contextConverter2.setConverterClass("Foo2"); - contextConverter2.setName("myConverter2"); - - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getConverters().get(1).getClassName()); - assertEquals("myConverter", resourceMappedSuperclass.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveCustomConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getConverters().get(1).getClassName()); - assertEquals("myConverter2", resourceMappedSuperclass.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(0); - - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(contextConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateTypeConverters() throws Exception { - createTestMappedSuperclassForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceMappedSuperclass.getTypeConverters().add(resourceTypeConverter); - resourceTypeConverter.setDataType("Foo"); - resourceTypeConverter.setName("myTypeConverter"); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceMappedSuperclass.getTypeConverters().add(0, resourceTypeConverter2); - resourceTypeConverter2.setDataType("Foo2"); - resourceTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getTypeConverters().remove(resourceTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyTypeConverters() throws Exception { - createTestMappedSuperclassForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter.setDataType("Foo"); - contextTypeConverter.setName("myTypeConverter"); - - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter2 = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter2.setDataType("Foo2"); - contextTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter", resourceMappedSuperclass.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveTypeConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter2", resourceMappedSuperclass.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(0); - - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(contextTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateObjectTypeConverters() throws Exception { - createTestMappedSuperclassForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceMappedSuperclass.getObjectTypeConverters().add(resourceObjectTypeConverter); - resourceObjectTypeConverter.setDataType("Foo"); - resourceObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceMappedSuperclass.getObjectTypeConverters().add(0, resourceObjectTypeConverter2); - resourceObjectTypeConverter2.setDataType("Foo2"); - resourceObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getObjectTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getObjectTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getObjectTypeConverters().remove(resourceObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyObjectTypeConverters() throws Exception { - createTestMappedSuperclassForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter.setDataType("Foo"); - contextObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter2 = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter2.setDataType("Foo2"); - contextObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter", resourceMappedSuperclass.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveObjectTypeConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter2", resourceMappedSuperclass.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(0); - - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(contextObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateStructConverters() throws Exception { - createTestMappedSuperclassForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlStructConverter resourceStructConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceMappedSuperclass.getStructConverters().add(resourceStructConverter); - resourceStructConverter.setConverter("Foo"); - resourceStructConverter.setName("myStructConverter"); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlStructConverter resourceStructConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceMappedSuperclass.getStructConverters().add(0, resourceStructConverter2); - resourceStructConverter2.setConverter("Foo2"); - resourceStructConverter2.setName("myStructConverter2"); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getStructConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getStructConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getStructConverters().remove(resourceStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyStructConverters() throws Exception { - createTestMappedSuperclassForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter = ormContextConverterHolder.addStructConverter(0); - contextStructConverter.setConverterClass("Foo"); - contextStructConverter.setName("myStructConverter"); - - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter2 = ormContextConverterHolder.addStructConverter(0); - contextStructConverter2.setConverterClass("Foo2"); - contextStructConverter2.setName("myStructConverter2"); - - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter", resourceMappedSuperclass.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveStructConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter2", resourceMappedSuperclass.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(0); - - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(contextStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmObjectTypeConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmObjectTypeConverterTests.java deleted file mode 100644 index 7be1566945..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmObjectTypeConverterTests.java +++ /dev/null @@ -1,569 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConversionValue; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.internal.context.java.JavaEclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlBasic; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConversionValue; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlObjectTypeConverter; - -@SuppressWarnings("nls") -public class EclipseLinkOrmObjectTypeConverterTests - extends EclipseLinkOrmContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, EclipseLink.CONVERT, EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Convert(name=\"foo\")").append(CR); - sb.append(" @ObjectTypeConverter"); - } - }); - } - - - private ICompilationUnit createTestEntityWithConvertAndObjectTypeConverterConversionValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, EclipseLink.CONVERT, EclipseLink.OBJECT_TYPE_CONVERTER, EclipseLink.CONVERSION_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(\"foo\")").append(CR); - sb.append(" @ObjectTypeConverter(name=\"foo\", defaultObjectValue=\"bar\", conversionValues = @ConversionValue(dataValue=\"f\", objectValue=\"female\"))"); - } - }); - } - - public EclipseLinkOrmObjectTypeConverterTests(String name) { - super(name); - } - - - public void testUpdateDataType() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - - //set converter class name in the resource model, verify context model updated - converterResource.setDataType("myConvert"); - assertEquals("myConvert", ormConverter.getDataType()); - assertEquals("myConvert", converterResource.getDataType()); - - //set converter class name to null in the resource model - converterResource.setDataType(null); - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkObjectTypeConverter javaConverter = ((EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setDataType("bar"); - assertEquals("bar", ormConverter.getDataType()); - assertEquals("bar", javaConverter.getDataType()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getDataType()); - } - - public void testModifyDataType() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - - //set converter class in the context model, verify resource model updated - ormConverter.setDataType("foo"); - assertEquals("foo", ormConverter.getDataType()); - assertEquals("foo", converterResource.getDataType()); - - ormConverter.setDataType(null); - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - } - - public void testUpdateObjectType() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - - //set converter class name in the resource model, verify context model updated - converterResource.setObjectType("myConvert"); - assertEquals("myConvert", ormConverter.getObjectType()); - assertEquals("myConvert", converterResource.getObjectType()); - - //set converter class name to null in the resource model - converterResource.setObjectType(null); - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkObjectTypeConverter javaConverter = ((EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setObjectType("bar"); - assertEquals("bar", ormConverter.getObjectType()); - assertEquals("bar", javaConverter.getObjectType()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getObjectType()); - } - - public void testModifyObjectType() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - - //set converter class in the context model, verify resource model updated - ormConverter.setObjectType("foo"); - assertEquals("foo", ormConverter.getObjectType()); - assertEquals("foo", converterResource.getObjectType()); - - ormConverter.setObjectType(null); - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - } - - public void testUpdateName() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - OrmEclipseLinkObjectTypeConverter ormConverter = (OrmEclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class name in the resource model, verify context model updated - converterResource.setName("myConvert"); - assertEquals("myConvert", ormConverter.getName()); - assertEquals("myConvert", converterResource.getName()); - - //set converter class name to null in the resource model - converterResource.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - - //remove the specified persistent attribute, test virtual mapping - - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - EclipseLinkObjectTypeConverter virtualConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkObjectTypeConverter javaConverter = ((EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setName("bar"); - assertEquals("bar", virtualConverter.getName()); - assertEquals("bar", javaConverter.getName()); - - - //set metadata-complete, test virtual mapping - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - OrmEclipseLinkObjectTypeConverter ormConverter = (OrmEclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class in the context model, verify resource model updated - ormConverter.setName("foo"); - assertEquals("foo", ormConverter.getName()); - assertEquals("foo", converterResource.getName()); - - ormConverter.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - } - - public void testUpdateDefaultObjectValue() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getDefaultObjectValue()); - assertEquals(null, converterResource.getDefaultObjectValue()); - - //set converter class name in the resource model, verify context model updated - converterResource.setDefaultObjectValue("myConvert"); - assertEquals("myConvert", ormConverter.getDefaultObjectValue()); - assertEquals("myConvert", converterResource.getDefaultObjectValue()); - - //set converter class name to null in the resource model - converterResource.setDefaultObjectValue(null); - assertEquals(null, ormConverter.getDefaultObjectValue()); - assertEquals(null, converterResource.getDefaultObjectValue()); - - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkObjectTypeConverter javaConverter = ((EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setDefaultObjectValue("bar"); - assertEquals("bar", ormConverter.getDefaultObjectValue()); - assertEquals("bar", javaConverter.getDefaultObjectValue()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getDefaultObjectValue()); - } - - public void testModifyDefaultObjectValue() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - - assertEquals(null, ormConverter.getDefaultObjectValue()); - assertEquals(null, converterResource.getDefaultObjectValue()); - - //set converter class in the context model, verify resource model updated - ormConverter.setDefaultObjectValue("foo"); - assertEquals("foo", ormConverter.getDefaultObjectValue()); - assertEquals("foo", converterResource.getDefaultObjectValue()); - - ormConverter.setDefaultObjectValue(null); - assertEquals(null, ormConverter.getDefaultObjectValue()); - assertEquals(null, converterResource.getDefaultObjectValue()); - } - - - public void testUpdateConversionValues() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(0, ormConverter.conversionValuesSize()); - assertEquals(0, converterResource.getConversionValues().size()); - - //add conversion value to resource model, check context model - XmlConversionValue resourceConversionValue = EclipseLinkOrmFactory.eINSTANCE.createXmlConversionValue(); - converterResource.getConversionValues().add(resourceConversionValue); - resourceConversionValue.setDataValue("foo"); - resourceConversionValue.setObjectValue("bar"); - - assertEquals(1, ormConverter.conversionValuesSize()); - ListIterator contextConversionValues = ormConverter.conversionValues(); - EclipseLinkConversionValue contextConversionValue = contextConversionValues.next(); - assertEquals("foo", contextConversionValue.getDataValue()); - assertEquals("bar", contextConversionValue.getObjectValue()); - assertEquals(1, converterResource.getConversionValues().size()); - assertEquals("foo", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar", converterResource.getConversionValues().get(0).getObjectValue()); - - //add a conversion to the beginning of the resource model list - XmlConversionValue xmlConversionValue2 = EclipseLinkOrmFactory.eINSTANCE.createXmlConversionValue(); - converterResource.getConversionValues().add(0, xmlConversionValue2); - xmlConversionValue2.setDataValue("foo2"); - xmlConversionValue2.setObjectValue("bar2"); - - assertEquals(2, ormConverter.conversionValuesSize()); - contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo2", contextConversionValue.getDataValue()); - assertEquals("bar2", contextConversionValue.getObjectValue()); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo", contextConversionValue.getDataValue()); - assertEquals("bar", contextConversionValue.getObjectValue()); - assertEquals(2, converterResource.getConversionValues().size()); - assertEquals("foo2", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar2", converterResource.getConversionValues().get(0).getObjectValue()); - assertEquals("foo", converterResource.getConversionValues().get(1).getDataValue()); - assertEquals("bar", converterResource.getConversionValues().get(1).getObjectValue()); - - //move a conversion value in the resource model list - - converterResource.getConversionValues().move(0, 1); - assertEquals(2, ormConverter.conversionValuesSize()); - contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo", contextConversionValue.getDataValue()); - assertEquals("bar", contextConversionValue.getObjectValue()); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo2", contextConversionValue.getDataValue()); - assertEquals("bar2", contextConversionValue.getObjectValue()); - assertEquals(2, converterResource.getConversionValues().size()); - assertEquals("foo", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar", converterResource.getConversionValues().get(0).getObjectValue()); - assertEquals("foo2", converterResource.getConversionValues().get(1).getDataValue()); - assertEquals("bar2", converterResource.getConversionValues().get(1).getObjectValue()); - - //remove a conversion value from the resource model list - - converterResource.getConversionValues().remove(0); - assertEquals(1, ormConverter.conversionValuesSize()); - contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo2", contextConversionValue.getDataValue()); - assertEquals("bar2", contextConversionValue.getObjectValue()); - assertEquals(1, converterResource.getConversionValues().size()); - assertEquals("foo2", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar2", converterResource.getConversionValues().get(0).getObjectValue()); - - //clear the conversion value resource model list - converterResource.getConversionValues().clear(); - assertEquals(0, ormConverter.conversionValuesSize()); - assertEquals(0, converterResource.getConversionValues().size()); - - //add conversion value to java context model, verify does not affect orm context model - - EclipseLinkObjectTypeConverter javaConverter = (EclipseLinkObjectTypeConverter) ((JavaEclipseLinkConvert) javaBasicMapping.getConverter()).getConverter(); - EclipseLinkConversionValue javaConversionValue = javaConverter.addConversionValue(); - javaConversionValue.setDataValue("baz"); - - assertEquals(0, ormConverter.conversionValuesSize()); - assertEquals(0, converterResource.getConversionValues().size()); - assertEquals(1, javaConverter.conversionValuesSize()); - - //remove orm attribute mapping, verify virtual mapping has conversion values from java - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - assertEquals(1, ormConverter.conversionValuesSize()); - contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("baz", contextConversionValue.getDataValue()); - assertEquals(0, converterResource.getConversionValues().size()); - assertEquals(1, javaConverter.conversionValuesSize()); - - //set metadata-complete to true, verify virtual mapping ignores the conversion values from java - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - } - - public void testModifyConversionValues() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkObjectTypeConverter.class); - EclipseLinkObjectTypeConverter ormConverter = (EclipseLinkObjectTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlObjectTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getObjectTypeConverter(); - - assertEquals(0, ormConverter.conversionValuesSize()); - assertEquals(0, converterResource.getConversionValues().size()); - - //add conversion value to context model, check resource model - EclipseLinkConversionValue contextConversionValue = ormConverter.addConversionValue(); - contextConversionValue.setDataValue("foo"); - contextConversionValue.setObjectValue("bar"); - - assertEquals(1, ormConverter.conversionValuesSize()); - ListIterator contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo", contextConversionValue.getDataValue()); - assertEquals("bar", contextConversionValue.getObjectValue()); - assertEquals(1, converterResource.getConversionValues().size()); - assertEquals("foo", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar", converterResource.getConversionValues().get(0).getObjectValue()); - - //add a conversion to the beginning of the context model list - EclipseLinkConversionValue contextConversionValue2 = ormConverter.addConversionValue(0); - contextConversionValue2.setDataValue("foo2"); - contextConversionValue2.setObjectValue("bar2"); - - assertEquals(2, ormConverter.conversionValuesSize()); - contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo2", contextConversionValue.getDataValue()); - assertEquals("bar2", contextConversionValue.getObjectValue()); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo", contextConversionValue.getDataValue()); - assertEquals("bar", contextConversionValue.getObjectValue()); - assertEquals(2, converterResource.getConversionValues().size()); - assertEquals("foo2", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar2", converterResource.getConversionValues().get(0).getObjectValue()); - assertEquals("foo", converterResource.getConversionValues().get(1).getDataValue()); - assertEquals("bar", converterResource.getConversionValues().get(1).getObjectValue()); - - //move a conversion value in the context model list - - ormConverter.moveConversionValue(0, 1); - assertEquals(2, ormConverter.conversionValuesSize()); - contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo", contextConversionValue.getDataValue()); - assertEquals("bar", contextConversionValue.getObjectValue()); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo2", contextConversionValue.getDataValue()); - assertEquals("bar2", contextConversionValue.getObjectValue()); - assertEquals(2, converterResource.getConversionValues().size()); - assertEquals("foo", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar", converterResource.getConversionValues().get(0).getObjectValue()); - assertEquals("foo2", converterResource.getConversionValues().get(1).getDataValue()); - assertEquals("bar2", converterResource.getConversionValues().get(1).getObjectValue()); - - //remove a conversion value from the context model list - - ormConverter.removeConversionValue(0); - assertEquals(1, ormConverter.conversionValuesSize()); - contextConversionValues = ormConverter.conversionValues(); - contextConversionValue = contextConversionValues.next(); - assertEquals("foo2", contextConversionValue.getDataValue()); - assertEquals("bar2", contextConversionValue.getObjectValue()); - assertEquals(1, converterResource.getConversionValues().size()); - assertEquals("foo2", converterResource.getConversionValues().get(0).getDataValue()); - assertEquals("bar2", converterResource.getConversionValues().get(0).getObjectValue()); - - //clear the conversion value resource model list - ormConverter.removeConversionValue(0); - assertEquals(0, ormConverter.conversionValuesSize()); - assertEquals(0, converterResource.getConversionValues().size()); - } - - public void testInitializeConversionValues() throws Exception { - createTestEntityWithConvertAndObjectTypeConverterConversionValue(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - BasicMapping ormBasicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - EclipseLinkConvert eclipseLinkConvert = (EclipseLinkConvert) ormBasicMapping.getConverter(); - EclipseLinkObjectTypeConverter converter = (EclipseLinkObjectTypeConverter) eclipseLinkConvert.getConverter(); - - assertEquals(1, converter.conversionValuesSize()); - assertEquals("f", converter.conversionValues().next().getDataValue()); - assertEquals("female", converter.conversionValues().next().getObjectValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java deleted file mode 100644 index fd5d6f1b8a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java +++ /dev/null @@ -1,747 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyMapping; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.eclipselink.core.v2_0.context.EclipseLinkOneToManyRelationship2_0; - -@SuppressWarnings("nls") -public class EclipseLinkOrmOneToManyMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmOneToManyMappingTests(String name) { - super(name); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("import java.util.Collection;"); - sb.append(CR); - sb.append("import ").append(JPA.JOIN_TABLE).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.JOIN_COLUMN).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @JoinTable(name=\"DEP_EMP\", joinColumns=@JoinColumn(name=\"DEPT_ID\"), inverseJoinColumns=@JoinColumn(name=\"EMP_ID\"))").append(CR); - sb.append(" private Collection employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityWithOneToManyMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testUpdatePrivateOwned() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - EclipseLinkOneToManyMapping contextOneToMany = - (EclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity) getXmlEntityMappings().getEntities().get(0); - XmlOneToMany resourceOneToMany = - (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); - - // check defaults - - assertFalse(resourceOneToMany.isPrivateOwned()); - assertFalse(contextOneToMany.getPrivateOwned().isPrivateOwned()); - - // set xml private owned to true, check context - - resourceOneToMany.setPrivateOwned(true); - - assertTrue(resourceOneToMany.isPrivateOwned()); - assertTrue(contextOneToMany.getPrivateOwned().isPrivateOwned()); - - // set xml private owned back to false, check context - - resourceOneToMany.setPrivateOwned(false); - - assertFalse(resourceOneToMany.isPrivateOwned()); - assertFalse(contextOneToMany.getPrivateOwned().isPrivateOwned()); - } - - public void testModifyPrivateOwned() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - EclipseLinkOneToManyMapping contextOneToMany = - (EclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlOneToMany resourceOneToMany = - (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); - - // check defaults - - assertFalse(resourceOneToMany.isPrivateOwned()); - assertFalse(contextOneToMany.getPrivateOwned().isPrivateOwned()); - - // set context private owned to true, check resource - - contextOneToMany.getPrivateOwned().setPrivateOwned(true); - - assertTrue(resourceOneToMany.isPrivateOwned()); - assertTrue(contextOneToMany.getPrivateOwned().isPrivateOwned()); - - // set context private owned back to false, check resource - - contextOneToMany.getPrivateOwned().setPrivateOwned(false); - - assertFalse(resourceOneToMany.isPrivateOwned()); - assertFalse(contextOneToMany.getPrivateOwned().isPrivateOwned()); - } - - public void testUpdateJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - EclipseLinkOneToManyMapping contextOneToMany = - (EclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity) getXmlEntityMappings().getEntities().get(0); - XmlOneToMany resourceOneToMany = - (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); - - // check defaults - - assertNull(resourceOneToMany.getJoinFetch()); - assertNull(contextOneToMany.getJoinFetch().getValue()); - - // set xml join fetch to INNER, check context - - resourceOneToMany.setJoinFetch(XmlJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceOneToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextOneToMany.getJoinFetch().getValue()); - - // set xml join fetch to OUTER, check context - - resourceOneToMany.setJoinFetch(XmlJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceOneToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextOneToMany.getJoinFetch().getValue()); - - // set xml join fetch to null, check context - - resourceOneToMany.setJoinFetch(null); - - assertNull(resourceOneToMany.getJoinFetch()); - assertNull(contextOneToMany.getJoinFetch().getValue()); - } - - public void testModifyJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - EclipseLinkOneToManyMapping contextOneToMany = - (EclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlOneToMany resourceOneToMany = - (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); - - // check defaults - - assertNull(resourceOneToMany.getJoinFetch()); - assertNull(contextOneToMany.getJoinFetch().getValue()); - - // set context join fetch to INNER, check resource - - contextOneToMany.getJoinFetch().setValue(EclipseLinkJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceOneToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextOneToMany.getJoinFetch().getValue()); - - // set context join fetch to OUTER, check resource - - contextOneToMany.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceOneToMany.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextOneToMany.getJoinFetch().getValue()); - - // set context join fetch to null, check resource - - contextOneToMany.getJoinFetch().setValue(null); - - assertNull(resourceOneToMany.getJoinFetch()); - assertNull(contextOneToMany.getJoinFetch().getValue()); - } - - public void testJoinFetchDefault() throws Exception { - createTestEmployee(); - createTestDepartment(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Department"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Employee"); - - OrmPersistentType departmentPersistentType = getEntityMappings().getPersistentTypes().iterator().next(); - EclipseLinkOneToManyMapping oneToMany = (EclipseLinkOneToManyMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - - assertNull(oneToMany.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - oneToMany = (EclipseLinkOneToManyMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - assertNull(oneToMany.getJoinFetch().getValue()); - - EclipseLinkRelationshipMapping javaRelationshipMapping = (EclipseLinkRelationshipMapping) departmentPersistentType.getJavaPersistentType().getAttributeNamed("employees").getMapping(); - javaRelationshipMapping.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - assertNull(oneToMany.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - oneToMany = (EclipseLinkOneToManyMapping) departmentPersistentType.getAttributeNamed("employees").getMapping(); - assertEquals(EclipseLinkJoinFetchType.OUTER, oneToMany.getJoinFetch().getValue()); - } - - public void testDefaultJoinTable() throws Exception { - createTestEmployee(); - createTestDepartment(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Department"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Employee"); - - OrmPersistentType departmentPersistentType = getEntityMappings().getPersistentTypes().iterator().next(); - OrmReadOnlyPersistentAttribute attribute = departmentPersistentType.getAttributeNamed("employees"); - OneToManyMapping oneToMany = (OneToManyMapping) attribute.getMapping(); - - assertEquals(true, attribute.isVirtual()); - JoinTable ormJoinTable = oneToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("DEP_EMP", ormJoinTable.getName()); - assertEquals("DEPT_ID", ormJoinTable.specifiedJoinColumns().next().getName()); - assertEquals("id", ormJoinTable.specifiedJoinColumns().next().getReferencedColumnName()); - assertEquals("EMP_ID", ormJoinTable.specifiedInverseJoinColumns().next().getName()); - assertEquals("empId", ormJoinTable.specifiedInverseJoinColumns().next().getReferencedColumnName()); - - //set metadata-complete and verify JoinTable info is not taken from the java - departmentPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - departmentPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - attribute = departmentPersistentType.getAttributeNamed("employees"); - oneToMany = (OneToManyMapping) attribute.getMapping(); - - assertEquals(true, attribute.isVirtual()); - ormJoinTable = oneToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("Department_Employee", ormJoinTable.getName()); - assertEquals("Department_id", ormJoinTable.getDefaultJoinColumn().getName()); - assertEquals("id", ormJoinTable.getDefaultJoinColumn().getReferencedColumnName()); - assertEquals("employees_empId", ormJoinTable.getDefaultInverseJoinColumn().getName()); - assertEquals("empId", ormJoinTable.getDefaultInverseJoinColumn().getReferencedColumnName()); - - //set metadata-complete to false, add mapping to orm.xml verify JoinTable info is not taken from the java - departmentPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); - attribute = departmentPersistentType.getAttributeNamed("employees"); - oneToMany = (OneToManyMapping) attribute.getMapping(); - assertEquals(true, attribute.isVirtual()); - ormJoinTable = oneToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("DEP_EMP", ormJoinTable.getName()); - assertEquals("DEPT_ID", ormJoinTable.specifiedJoinColumns().next().getName()); - assertEquals("id", ormJoinTable.specifiedJoinColumns().next().getReferencedColumnName()); - assertEquals("EMP_ID", ormJoinTable.specifiedInverseJoinColumns().next().getName()); - assertEquals("empId", ormJoinTable.specifiedInverseJoinColumns().next().getReferencedColumnName()); - - - departmentPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "employees"); - attribute = departmentPersistentType.getAttributeNamed("employees"); - oneToMany = (OneToManyMapping) attribute.getMapping(); - assertEquals(false, attribute.isVirtual()); - ormJoinTable = oneToMany.getRelationship().getJoinTableStrategy().getJoinTable(); - assertEquals("Department_Employee", ormJoinTable.getName()); - assertEquals(0, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals("Department_id", ormJoinTable.getDefaultJoinColumn().getName()); - assertEquals("id", ormJoinTable.getDefaultJoinColumn().getReferencedColumnName()); - assertEquals(0, ormJoinTable.specifiedInverseJoinColumnsSize()); - assertEquals("employees_empId", ormJoinTable.getDefaultInverseJoinColumn().getName()); - assertEquals("empId", ormJoinTable.getDefaultInverseJoinColumn().getReferencedColumnName()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping ormOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(ormOneToManyMapping.getMapKey()); - assertFalse(ormOneToManyMapping.isPkMapKey()); - assertFalse(ormOneToManyMapping.isCustomMapKey()); - assertTrue(ormOneToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setPkMapKey(true); - assertEquals("id", ormOneToManyMapping.getMapKey()); - assertTrue(ormOneToManyMapping.isPkMapKey()); - assertFalse(ormOneToManyMapping.isCustomMapKey()); - assertFalse(ormOneToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setCustomMapKey(true); - javaOneToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("city", ormOneToManyMapping.getMapKey()); - assertFalse(ormOneToManyMapping.isPkMapKey()); - assertTrue(ormOneToManyMapping.isCustomMapKey()); - assertFalse(ormOneToManyMapping.isNoMapKey()); - - //set metadata complete and verify that the orm model ignores the java annotations - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - assertEquals(null, ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals(null, ormOneToManyMapping.getMapKey()); - assertFalse(ormOneToManyMapping.isPkMapKey()); - assertFalse(ormOneToManyMapping.isCustomMapKey()); - assertTrue(ormOneToManyMapping.isNoMapKey()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = - oneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping ormOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - ormOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - ormOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormOneToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); - EclipseLinkOneToManyRelationship2_0 rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); - EclipseLinkOneToManyRelationship2_0 rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = (XmlOneToMany) resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - EclipseLinkOneToManyMapping virtualOneToManyMapping = (EclipseLinkOneToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualOneToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = virtualOneToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - - assertTrue(virtualOneToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertEquals(EclipseLinkJoinFetchType.INNER, virtualOneToManyMapping.getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - - EclipseLinkOneToManyMapping virtualOneToManyMapping = (EclipseLinkOneToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToManyMapping.getName()); - assertEquals(FetchType.LAZY, virtualOneToManyMapping.getFetch()); - assertEquals("test.Address", virtualOneToManyMapping.getTargetEntity()); - assertNull(virtualOneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade cascade = virtualOneToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - - assertTrue(virtualOneToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, virtualOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertEquals(null, virtualOneToManyMapping.getJoinFetch().getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java deleted file mode 100644 index ca2aba3256..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java +++ /dev/null @@ -1,455 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToOneMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlOneToOne; - -@SuppressWarnings("nls") -public class EclipseLinkOrmOneToOneMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmOneToOneMappingTests(String name) { - super(name); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import ").append(JPA.ONE_TO_ONE).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Employee employee;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE, EclipseLink.PRIVATE_OWNED); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(CR); - sb.append(" @PrivateOwned)"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - public void testUpdatePrivateOwned() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - EclipseLinkOneToOneMapping contextOneToOne = - (EclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlOneToOne resourceOneToOne = - (XmlOneToOne) resourceEntity.getAttributes().getOneToOnes().get(0); - - // check defaults - - assertFalse(resourceOneToOne.isPrivateOwned()); - assertFalse(contextOneToOne.getPrivateOwned().isPrivateOwned()); - - // set xml private owned to true, check context - - resourceOneToOne.setPrivateOwned(true); - - assertTrue(resourceOneToOne.isPrivateOwned()); - assertTrue(contextOneToOne.getPrivateOwned().isPrivateOwned()); - - // set xml private owned back to false, check context - - resourceOneToOne.setPrivateOwned(false); - - assertFalse(resourceOneToOne.isPrivateOwned()); - assertFalse(contextOneToOne.getPrivateOwned().isPrivateOwned()); - } - - public void testModifyPrivateOwned() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - EclipseLinkOneToOneMapping contextOneToOne = - (EclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlOneToOne resourceOneToOne = - (XmlOneToOne) resourceEntity.getAttributes().getOneToOnes().get(0); - - // check defaults - - assertFalse(resourceOneToOne.isPrivateOwned()); - assertFalse(contextOneToOne.getPrivateOwned().isPrivateOwned()); - - // set context private owned to true, check resource - - contextOneToOne.getPrivateOwned().setPrivateOwned(true); - - assertTrue(resourceOneToOne.isPrivateOwned()); - assertTrue(contextOneToOne.getPrivateOwned().isPrivateOwned()); - - // set context private owned back to false, check resource - - contextOneToOne.getPrivateOwned().setPrivateOwned(false); - } - - public void testUpdateJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - EclipseLinkOneToOneMapping contextOneToOne = - (EclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity) getXmlEntityMappings().getEntities().get(0); - XmlOneToOne resourceOneToOne = - (XmlOneToOne) resourceEntity.getAttributes().getOneToOnes().get(0); - - // check defaults - - assertNull(resourceOneToOne.getJoinFetch()); - assertNull(contextOneToOne.getJoinFetch().getValue()); - - // set xml join fetch to INNER, check context - - resourceOneToOne.setJoinFetch(XmlJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceOneToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextOneToOne.getJoinFetch().getValue()); - - // set xml join fetch to OUTER, check context - - resourceOneToOne.setJoinFetch(XmlJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceOneToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextOneToOne.getJoinFetch().getValue()); - - // set xml join fetch to null, check context - - resourceOneToOne.setJoinFetch(null); - - assertNull(resourceOneToOne.getJoinFetch()); - assertNull(contextOneToOne.getJoinFetch().getValue()); - } - - public void testModifyJoinFetch() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - EclipseLinkOneToOneMapping contextOneToOne = - (EclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlOneToOne resourceOneToOne = - (XmlOneToOne) resourceEntity.getAttributes().getOneToOnes().get(0); - - // check defaults - - assertNull(resourceOneToOne.getJoinFetch()); - assertNull(contextOneToOne.getJoinFetch().getValue()); - - // set context join fetch to INNER, check resource - - contextOneToOne.getJoinFetch().setValue(EclipseLinkJoinFetchType.INNER); - - assertEquals(XmlJoinFetchType.INNER, resourceOneToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextOneToOne.getJoinFetch().getValue()); - - // set context join fetch to OUTER, check resource - - contextOneToOne.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(XmlJoinFetchType.OUTER, resourceOneToOne.getJoinFetch()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextOneToOne.getJoinFetch().getValue()); - - // set context join fetch to null, check resource - - contextOneToOne.getJoinFetch().setValue(null); - - assertNull(resourceOneToOne.getJoinFetch()); - assertNull(contextOneToOne.getJoinFetch().getValue()); - } - - public void testJoinFetchDefaultFromJava() throws Exception { - createTestEmployee(); - createTestDepartment(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Department"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Employee"); - - OrmPersistentType departmentPersistentType = getEntityMappings().getPersistentTypes().iterator().next(); - EclipseLinkOneToOneMapping oneToOne = (EclipseLinkOneToOneMapping) departmentPersistentType.getAttributeNamed("employee").getMapping(); - - assertNull(oneToOne.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - oneToOne = (EclipseLinkOneToOneMapping) departmentPersistentType.getAttributeNamed("employee").getMapping(); - assertNull(oneToOne.getJoinFetch().getValue()); - - EclipseLinkRelationshipMapping javaRelationshipMapping = (EclipseLinkRelationshipMapping) departmentPersistentType.getJavaPersistentType().getAttributeNamed("employee").getMapping(); - javaRelationshipMapping.getJoinFetch().setValue(EclipseLinkJoinFetchType.OUTER); - assertNull(oneToOne.getJoinFetch().getValue()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - oneToOne = (EclipseLinkOneToOneMapping) departmentPersistentType.getAttributeNamed("employee").getMapping(); - assertEquals(EclipseLinkJoinFetchType.OUTER, oneToOne.getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OneToOneMapping virtualOneToOneMapping = (OneToOneMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualOneToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualOneToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToOneMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - JoinColumn virtualJoinColumn = - virtualOneToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", virtualJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", virtualJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, virtualJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", virtualJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", virtualJoinColumn.getSpecifiedTable()); - - Cascade cascade = virtualOneToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - - assertEquals(EclipseLinkJoinFetchType.INNER, ((EclipseLinkJoinFetchMapping) virtualOneToOneMapping).getJoinFetch().getValue()); - assertTrue(((EclipseLinkOneToOneMapping) virtualOneToOneMapping).getPrivateOwned().isPrivateOwned()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - EclipseLinkOneToOneMapping ormOneToOneMapping = (EclipseLinkOneToOneMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - assertEquals("test.Address", ormOneToOneMapping.getTargetEntity()); - assertNull(ormOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - - assertEquals(null, ormOneToOneMapping.getJoinFetch().getValue()); - assertFalse(ormOneToOneMapping.getPrivateOwned().isPrivateOwned()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEclipseLinkOneToOneMapping ormOneToOneMapping = (OrmEclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormOneToOneMapping.getName()); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(ormOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - //TODO default target entity in xml - //assertEquals("test.Address", ormOneToOneMapping.getDefaultTargetEntity()); - - assertTrue(ormOneToOneMapping.getRelationship().getJoinColumnStrategy().joinColumnsSize() > 0); - - //TODO default join columns for specified xmlOneToOne mapping -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.defaultJoinColumns().next(); -// assertNull(ormJoinColumn.getSpecifiedName()); -// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertNull(ormJoinColumn.getSpecifiedUnique()); -// assertNull(ormJoinColumn.getSpecifiedNullable()); -// assertNull(ormJoinColumn.getSpecifiedInsertable()); -// assertNull(ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertNull(ormJoinColumn.getSpecifiedTable()); -// -// assertEquals("address", ormJoinColumn.getDefaultName()); -// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable()); -// assertEquals(null, ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - - assertEquals(null, ormOneToOneMapping.getJoinFetch().getValue()); - assertFalse(ormOneToOneMapping.getPrivateOwned().isPrivateOwned()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java deleted file mode 100644 index a68d644d59..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java +++ /dev/null @@ -1,313 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkIdMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToOneMapping; - -@SuppressWarnings("nls") -public class EclipseLinkOrmPersistentAttributeTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmPersistentAttributeTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestTypeNullAttributeMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(" private Address address;"); - } - }); - } - - public void testMakeSpecified() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeSpecifiedMappingKey() throws Exception { - createTestTypeNullAttributeMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - //take a virtual mapping with a mapping type and make it specified - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertTrue(ormPersistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - ormPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertEquals(specifiedOrmPersistentAttribute.getMappingKey(), MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmEclipseLinkOneToOneMapping); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmEclipseLinkIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(0, ormPersistentType.specifiedAttributesSize()); - - Iterator virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - - ormPersistentType.specifiedAttributes().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - assertEquals("id", ormPersistentType.virtualAttributes().next().getName()); - assertEquals("name", ormPersistentType.specifiedAttributes().next().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("id", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete2() throws Exception { - createTestEntityOneToOneMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } - - public void testGetJavaPersistentAttribute() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - //virtual orm attribute, access type matches java : FIELD, name matches java - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - JavaResourcePersistentAttribute javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isField()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableFields().next(), javaResourcePersistentAttribute); - - - //specified orm attribute, access type matches java : FIELD, name matches java - //javaPersistentAttribute should be == to java context model object - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - - - //virtual orm attribute, java access type FIELD, orm access type PROPERTY, name matches java - //verify the property java resource persistent attribute is used in orm. - ((OrmPersistentAttribute) ormPersistentAttribute).convertToVirtual(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertNotSame(ormPersistentAttribute, ormPersistentType.getAttributeNamed("id")); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isProperty()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableProperties().next(), javaResourcePersistentAttribute); - - - ormPersistentType.setSpecifiedAccess(null);//default access will be field - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - OrmPersistentAttribute ormPersistentAttribute2 = ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute2.getMapping().setName("id2"); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName(null); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName("id"); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmStructConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmStructConverterTests.java deleted file mode 100644 index e110f72b2e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmStructConverterTests.java +++ /dev/null @@ -1,199 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlBasic; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlStructConverter; - -@SuppressWarnings("nls") -public class EclipseLinkOrmStructConverterTests - extends EclipseLinkOrmContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, EclipseLink.CONVERT, EclipseLink.STRUCT_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Convert(name=\"foo\")").append(CR); - sb.append(" @StructConverter"); - } - }); - } - - - public EclipseLinkOrmStructConverterTests(String name) { - super(name); - } - - - public void testUpdateConverter() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkStructConverter.class); - EclipseLinkStructConverter ormConverter = (EclipseLinkStructConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlStructConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getStructConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getConverter()); - - //set converter class name in the resource model, verify context model updated - converterResource.setConverter("myConvert"); - assertEquals("myConvert", ormConverter.getConverterClass()); - assertEquals("myConvert", converterResource.getConverter()); - - //set converter class name to null in the resource model - converterResource.setConverter(null); - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getConverter()); - - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - ormConverter = (EclipseLinkStructConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkStructConverter javaConverter = ((EclipseLinkStructConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setConverterClass("bar"); - assertEquals("bar", ormConverter.getConverterClass()); - assertEquals("bar", javaConverter.getConverterClass()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getConverterClass()); - } - - public void testModifyConverter() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkStructConverter.class); - EclipseLinkStructConverter ormConverter = (EclipseLinkStructConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlStructConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getStructConverter(); - - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getConverter()); - - //set converter class in the context model, verify resource model updated - ormConverter.setConverterClass("foo"); - assertEquals("foo", ormConverter.getConverterClass()); - assertEquals("foo", converterResource.getConverter()); - - ormConverter.setConverterClass(null); - assertEquals(null, ormConverter.getConverterClass()); - assertEquals(null, converterResource.getConverter()); - } - - public void testUpdateName() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkStructConverter.class); - OrmEclipseLinkStructConverter ormConverter = (OrmEclipseLinkStructConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlStructConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getStructConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class name in the resource model, verify context model updated - converterResource.setName("myConvert"); - assertEquals("myConvert", ormConverter.getName()); - assertEquals("myConvert", converterResource.getName()); - - //set converter class name to null in the resource model - converterResource.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - - //remove the specified persistent attribute, test virtual mapping - - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - EclipseLinkStructConverter virtualConverter = (EclipseLinkStructConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkStructConverter javaConverter = ((EclipseLinkStructConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setName("bar"); - assertEquals("bar", virtualConverter.getName()); - assertEquals("bar", javaConverter.getName()); - - - //set metadata-complete, test virtual mapping - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.virtualAttributes().next(); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkStructConverter.class); - OrmEclipseLinkStructConverter ormConverter = (OrmEclipseLinkStructConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlStructConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getStructConverter(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class in the context model, verify resource model updated - ormConverter.setName("foo"); - assertEquals("foo", ormConverter.getName()); - assertEquals("foo", converterResource.getName()); - - ormConverter.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTransientMappingTests.java deleted file mode 100644 index 90e038cb36..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTransientMappingTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; - -@SuppressWarnings("nls") -public class EclipseLinkOrmTransientMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmTransientMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithTransientMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TRANSIENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient").append(CR); - } - }); - } - - public void testCreateTransientMapping() throws Exception { - createTestEntityWithTransientMapping(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertTrue(persistentAttribute.isVirtual()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - OrmPersistentAttribute persistentAttribute2 = persistentAttribute.convertToSpecified(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertFalse(persistentAttribute2.isVirtual()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, persistentAttribute2.getMappingKey()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, persistentAttribute2.getMapping().getKey()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTypeConverterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTypeConverterTests.java deleted file mode 100644 index 578af975d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmTypeConverterTests.java +++ /dev/null @@ -1,266 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlBasic; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTypeConverter; - -@SuppressWarnings("nls") -public class EclipseLinkOrmTypeConverterTests - extends EclipseLinkOrmContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.BASIC, EclipseLink.CONVERT, EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - sb.append(" @Convert(name=\"foo\")").append(CR); - sb.append(" @TypeConverter"); - } - }); - } - - - public EclipseLinkOrmTypeConverterTests(String name) { - super(name); - } - - - public void testUpdateDataType() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkTypeConverter.class); - EclipseLinkTypeConverter ormConverter = (EclipseLinkTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - - //set converter class name in the resource model, verify context model updated - converterResource.setDataType("myConvert"); - assertEquals("myConvert", ormConverter.getDataType()); - assertEquals("myConvert", converterResource.getDataType()); - - //set converter class name to null in the resource model - converterResource.setDataType(null); - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - ormConverter = (EclipseLinkTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkTypeConverter javaConverter = ((EclipseLinkTypeConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setDataType("bar"); - assertEquals("bar", ormConverter.getDataType()); - assertEquals("bar", javaConverter.getDataType()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getDataType()); - } - - public void testModifyDataType() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkTypeConverter.class); - EclipseLinkTypeConverter ormConverter = (EclipseLinkTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getTypeConverter(); - - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - - //set converter class in the context model, verify resource model updated - ormConverter.setDataType("foo"); - assertEquals("foo", ormConverter.getDataType()); - assertEquals("foo", converterResource.getDataType()); - - ormConverter.setDataType(null); - assertEquals(null, ormConverter.getDataType()); - assertEquals(null, converterResource.getDataType()); - } - - public void testUpdateObjectType() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkTypeConverter.class); - EclipseLinkTypeConverter ormConverter = (EclipseLinkTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - - //set converter class name in the resource model, verify context model updated - converterResource.setObjectType("myConvert"); - assertEquals("myConvert", ormConverter.getObjectType()); - assertEquals("myConvert", converterResource.getObjectType()); - - //set converter class name to null in the resource model - converterResource.setObjectType(null); - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - ormConverter = (EclipseLinkTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkTypeConverter javaConverter = ((EclipseLinkTypeConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setObjectType("bar"); - assertEquals("bar", ormConverter.getObjectType()); - assertEquals("bar", javaConverter.getObjectType()); - - //set metadata-complete, test virtual mapping - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getObjectType()); - } - - public void testModifyObjectType() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkTypeConverter.class); - EclipseLinkTypeConverter ormConverter = (EclipseLinkTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getTypeConverter(); - - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - - //set converter class in the context model, verify resource model updated - ormConverter.setObjectType("foo"); - assertEquals("foo", ormConverter.getObjectType()); - assertEquals("foo", converterResource.getObjectType()); - - ormConverter.setObjectType(null); - assertEquals(null, ormConverter.getObjectType()); - assertEquals(null, converterResource.getObjectType()); - } - - public void testUpdateName() throws Exception { - createTestEntityWithBasicMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkTypeConverter.class); - OrmEclipseLinkTypeConverter ormConverter = (OrmEclipseLinkTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getTypeConverter(); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class name in the resource model, verify context model updated - converterResource.setName("myConvert"); - assertEquals("myConvert", ormConverter.getName()); - assertEquals("myConvert", converterResource.getName()); - - //set converter class name to null in the resource model - converterResource.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - - //remove the specified persistent attribute, test virtual mapping - ormPersistentAttribute.convertToVirtual(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - BasicMapping virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - EclipseLinkTypeConverter virtualConverter = (EclipseLinkTypeConverter) ((EclipseLinkConvert) virtualBasicMapping.getConverter()).getConverter(); - - EclipseLinkTypeConverter javaConverter = ((EclipseLinkTypeConverter) ((EclipseLinkConvert) javaBasicMapping.getConverter()).getConverter()); - javaConverter.setName("bar"); - assertEquals("bar", virtualConverter.getName()); - assertEquals("bar", javaConverter.getName()); - - - //set metadata-complete, test virtual mapping - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.virtualAttributes().next(); - virtualBasicMapping = (BasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(virtualBasicMapping.getConverter().getType()); - assertEquals("bar", javaConverter.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = ((OrmBasicMapping) ormPersistentAttribute.getMapping()); - ormBasicMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) ormBasicMapping.getConverter()).setConverter(EclipseLinkTypeConverter.class); - OrmEclipseLinkTypeConverter ormConverter = (OrmEclipseLinkTypeConverter) ((EclipseLinkConvert) ormBasicMapping.getConverter()).getConverter(); - XmlTypeConverter converterResource = ((XmlBasic) getXmlEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0)).getTypeConverter(); - - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - - //set converter class in the context model, verify resource model updated - ormConverter.setName("foo"); - assertEquals("foo", ormConverter.getName()); - assertEquals("foo", converterResource.getName()); - - ormConverter.setName(null); - assertEquals(null, ormConverter.getName()); - assertEquals(null, converterResource.getName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmVersionMappingTests.java deleted file mode 100644 index dd3fafd859..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmVersionMappingTests.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkBasicMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkVersionMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkVersionMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlVersion; - -@SuppressWarnings("nls") -public class EclipseLinkOrmVersionMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmVersionMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithVersionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableVersionDate() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.VERSION, EclipseLink.MUTABLE, "java.util.Date"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - sb.append(" @Mutable").append(CR); - sb.append(" private Date myDate;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - public void testUpdateMutable() throws Exception { - createTestEntityWithVersionMapping(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "id"); - OrmEclipseLinkVersionMapping contextVersion = - (OrmEclipseLinkVersionMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlVersion resourceVersion = - (XmlVersion) resourceEntity.getAttributes().getVersions().get(0); - EclipseLinkVersionMapping javaVersionMapping = (EclipseLinkVersionMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - // check defaults - - assertNull(resourceVersion.getMutable()); - assertTrue(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertTrue(contextVersion.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceVersion.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceVersion.getMutable()); - assertTrue(contextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceVersion.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceVersion.getMutable()); - assertTrue(contextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextVersion.getMutable().getSpecifiedMutable()); - assertTrue(contextVersion.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceVersion.setMutable(null); - - assertNull(resourceVersion.getMutable()); - assertTrue(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertTrue(contextVersion.getMutable().isMutable()); - - // TODO - test defaults for java serializable and date/time types, - // with and without persistence property - - // set mutable on java basic mapping - - javaVersionMapping.getMutable().setSpecifiedMutable(Boolean.FALSE); - assertNull(resourceVersion.getMutable()); - assertTrue(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertTrue(contextVersion.getMutable().isMutable()); - assertFalse(javaVersionMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - EclipseLinkVersionMapping virtualContextVersion = (EclipseLinkVersionMapping) ormPersistentAttribute2.getMapping(); - - assertNull(resourceVersion.getMutable()); - assertTrue(virtualContextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, virtualContextVersion.getMutable().getSpecifiedMutable()); - assertFalse(virtualContextVersion.getMutable().isMutable()); - assertFalse(javaVersionMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - EclipseLinkBasicMapping contextBasic = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(resourceVersion.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - assertFalse(javaVersionMapping.getMutable().isMutable()); - } - - public void testUpdateMutableDate() throws Exception { - createTestEntityWithMutableVersionDate(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "myDate"); - OrmEclipseLinkVersionMapping contextVersion = - (OrmEclipseLinkVersionMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlVersion resourceVersion = - (XmlVersion) resourceEntity.getAttributes().getVersions().get(0); - EclipseLinkVersionMapping javaVersionMapping = (EclipseLinkVersionMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("myDate").getMapping(); - - // check defaults - - assertNull(resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceVersion.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceVersion.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextVersion.getMutable().getSpecifiedMutable()); - assertTrue(contextVersion.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceVersion.setMutable(null); - - assertNull(resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.TRUE); - assertNull(resourceVersion.getMutable()); - assertTrue(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertTrue(contextVersion.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.FALSE); - assertNull(resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(null); - assertNull(resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - // set mutable on java version mapping - - javaVersionMapping.getMutable().setSpecifiedMutable(Boolean.TRUE); - assertNull(resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - assertTrue(javaVersionMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("myDate"); - EclipseLinkVersionMapping virtualContextVersion = (EclipseLinkVersionMapping) ormPersistentAttribute2.getMapping(); - - assertNull(resourceVersion.getMutable()); - assertFalse(virtualContextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, virtualContextVersion.getMutable().getSpecifiedMutable()); - assertTrue(virtualContextVersion.getMutable().isMutable()); - assertTrue(javaVersionMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("myDate"); - EclipseLinkBasicMapping contextBasic = (EclipseLinkBasicMapping) ormPersistentAttribute2.getMapping(); - assertNull(resourceVersion.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertNull(contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - assertTrue(javaVersionMapping.getMutable().isMutable()); - } - - public void testModifyMutable() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "basic"); - OrmEclipseLinkVersionMapping contextVersion = - (OrmEclipseLinkVersionMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlVersion resourceVersion = - (XmlVersion) resourceEntity.getAttributes().getVersions().get(0); - - // check defaults - - assertNull(resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - // set context mutable to true, check resource - - contextVersion.getMutable().setSpecifiedMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextVersion.getMutable().getSpecifiedMutable()); - assertTrue(contextVersion.getMutable().isMutable()); - - // set context mutable to false, check resource - - contextVersion.getMutable().setSpecifiedMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - - // set context read only to null, check resource - - contextVersion.getMutable().setSpecifiedMutable(null); - - assertNull(resourceVersion.getMutable()); - assertFalse(contextVersion.getMutable().isDefaultMutable()); - assertNull(contextVersion.getMutable().getSpecifiedMutable()); - assertFalse(contextVersion.getMutable().isMutable()); - } - - public void testUpdateConvert() throws Exception { - createTestEntityWithVersionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "id"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion basicResource = (XmlVersion) getXmlEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - JavaVersionMapping javaVersionMapping = (JavaVersionMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(ormVersionMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob in the resource model, verify context model updated - basicResource.setConvert("myConvert"); - assertEquals(EclipseLinkConvert.class, ormVersionMapping.getConverter().getType()); - assertEquals("myConvert", basicResource.getConvert()); - - //set lob to null in the resource model - basicResource.setConvert(null); - assertNull(ormVersionMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - - javaVersionMapping.setConverter(EclipseLinkConvert.class); - ((EclipseLinkConvert) javaVersionMapping.getConverter()).setSpecifiedConverterName("foo"); - - assertNull(ormVersionMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaVersionMapping.getConverter()).getSpecifiedConverterName()); - - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("id"); - VersionMapping virtualVersionMapping = (VersionMapping) ormPersistentAttribute2.getMapping(); - - assertEquals(EclipseLinkConvert.class, virtualVersionMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) virtualVersionMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaVersionMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) javaVersionMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals(EclipseLinkConvert.class, virtualVersionMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) virtualVersionMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("bar", ((EclipseLinkConvert) javaVersionMapping.getConverter()).getSpecifiedConverterName()); - - javaVersionMapping.setConverter(null); - assertNull(virtualVersionMapping.getConverter().getType()); - assertNull(basicResource.getConvert()); - assertNull(javaVersionMapping.getConverter().getType()); - } - - public void testModifyConvert() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion basicResource = (XmlVersion) getXmlEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertNull(ormVersionMapping.getConverter().getType()); - assertNull(basicResource.getConvert()); - - //set lob in the context model, verify resource model updated - ormVersionMapping.setConverter(EclipseLinkConvert.class); - assertEquals("", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.class, ormVersionMapping.getConverter().getType()); - - ((EclipseLinkConvert) ormVersionMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals("bar", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.class, ormVersionMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) ormVersionMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) ormVersionMapping.getConverter()).setSpecifiedConverterName(null); - - assertNull(ormVersionMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob to false in the context model - ormVersionMapping.setConverter(null); - assertNull(ormVersionMapping.getConverter().getType()); - assertNull(basicResource.getConvert()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitDefaultsTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitDefaultsTests.java deleted file mode 100644 index a41eba4ec8..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitDefaultsTests.java +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; - -@SuppressWarnings("nls") -public class EclipseLinkPersistenceUnitDefaultsTests extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkPersistenceUnitDefaultsTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - protected OrmPersistenceUnitDefaults persistenceUnitDefaults() { - return getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults(); - } - - public void testIsAllFeaturesUnset() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - XmlPersistenceUnitMetadata persistenceUnitMetadata = EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - getXmlEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isUnset()); - - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaultsResource = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - persistenceUnitMetadata.setPersistenceUnitDefaults(persistenceUnitDefaultsResource); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(true); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(false); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setSchema("asdf"); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setSchema(null); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCatalog("asdf"); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setCatalog(null); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertFalse(persistenceUnitDefaultsResource.isUnset()); - - persistenceUnitDefaultsResource.setAccess(null); - assertTrue(persistenceUnitDefaultsResource.isUnset()); - } - - public void testUpdateSchema() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifySchema2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCatalog() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCatalog2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCascadePersist() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the resource model, persistence-unit-defaults tag not removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCascadePersist2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - - public void testUpdateAccess() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set access in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyAccess2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitMetadataTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitMetadataTests.java deleted file mode 100644 index 7e628e2394..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkPersistenceUnitMetadataTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlPersistenceUnitMetadata; - -public class EclipseLinkPersistenceUnitMetadataTests extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkPersistenceUnitMetadataTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - protected OrmPersistenceUnitMetadata persistenceUnitMetadata() { - return getEntityMappings().getPersistenceUnitMetadata(); - } - - public void testIsAllFeaturesUnset() throws Exception { - XmlPersistenceUnitMetadata persistenceUnitMetadata = EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - getXmlEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertFalse(persistenceUnitMetadata.isUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertTrue(persistenceUnitMetadata.isUnset()); - - persistenceUnitMetadata.setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - assertFalse(persistenceUnitMetadata.isUnset()); - } - - public void testUpdateXmlMappingMetadataComplete() throws Exception { - OrmPersistenceUnitMetadata persistenceUnitMetadata = getEntityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the resource model, verify context model updated - getXmlEntityMappings().setPersistenceUnitMetadata(EclipseLinkOrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the resource model - getXmlEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } - - public void testModifyXmlMappingMetadataComplete() throws Exception { - OrmPersistenceUnitMetadata persistenceUnitMetadata = getEntityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyXmlMappingMetadataComplete2() throws Exception { - OrmPersistenceUnitMetadata persistenceUnitMetadata = getEntityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(getXmlEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - //set another element on the persistence-unit-metadata element so it doesn't get removed - getXmlEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(getXmlEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/JptEclipseLinkCoreOrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/JptEclipseLinkCoreOrmContextModelTests.java deleted file mode 100644 index 13621f86eb..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/JptEclipseLinkCoreOrmContextModelTests.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLinkCoreOrmContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreOrmContextModelTests.class.getName()); - suite.addTestSuite(EclipseLinkEntityMappingsTests.class); - suite.addTestSuite(EclipseLinkPersistenceUnitMetadataTests.class); - suite.addTestSuite(EclipseLinkPersistenceUnitDefaultsTests.class); - suite.addTestSuite(EclipseLinkOrmEmbeddableTests.class); - suite.addTestSuite(EclipseLinkOrmEntityTests.class); - suite.addTestSuite(EclipseLinkOrmMappedSuperclassTests.class); - suite.addTestSuite(EclipseLinkOrmBasicMappingTests.class); - suite.addTestSuite(EclipseLinkOrmIdMappingTests.class); - suite.addTestSuite(EclipseLinkOrmManyToManyMappingTests.class); - suite.addTestSuite(EclipseLinkOrmManyToOneMappingTests.class); - suite.addTestSuite(EclipseLinkOrmOneToManyMappingTests.class); - suite.addTestSuite(EclipseLinkOrmOneToOneMappingTests.class); - suite.addTestSuite(EclipseLinkOrmPersistentAttributeTests.class); - suite.addTestSuite(EclipseLinkOrmVersionMappingTests.class); - suite.addTestSuite(EclipseLinkOrmTransientMappingTests.class); - suite.addTestSuite(EclipseLinkOrmConverterTests.class); - suite.addTestSuite(EclipseLinkOrmObjectTypeConverterTests.class); - suite.addTestSuite(EclipseLinkOrmStructConverterTests.class); - suite.addTestSuite(EclipseLinkOrmTypeConverterTests.class); - return suite; - } - - - private JptEclipseLinkCoreOrmContextModelTests() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTestCase.java deleted file mode 100644 index df1967f92c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTestCase.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence; - -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.tests.internal.context.persistence.PersistenceUnitTestCase; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.platform.EclipseLinkPlatform; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * PersistenceUnitTestCase - */ -public abstract class EclipseLinkPersistenceUnitTestCase extends PersistenceUnitTestCase -{ - protected EclipseLinkPersistenceUnit subject; - - protected PropertyValueModel subjectHolder; - - // ********** constructors ********** - protected EclipseLinkPersistenceUnitTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject = this.getPersistenceUnit(); - this.subjectHolder = new SimplePropertyValueModel(this.subject); - this.populatePu(); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, EclipseLinkPlatform.VERSION_1_0); - return dataModel; - } - - @Override - protected EclipseLinkPersistenceUnit getPersistenceUnit() { - return (EclipseLinkPersistenceUnit) super.getPersistenceUnit(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java deleted file mode 100644 index b1c0848c14..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/EclipseLinkPersistenceUnitTests.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.orm.EclipseLinkOrmContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class EclipseLinkPersistenceUnitTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkPersistenceUnitTests(String name) { - super(name); - } - - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - @Override - protected IDataModel buildEclipseLinkOrmConfig(TestJpaProject testJpaProject) { - IDataModel dataModel = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - dataModel.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - testJpaProject.getProject().getFolder("src/META-INF").getFullPath()); - dataModel.setProperty(OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT, Boolean.FALSE); - return dataModel; - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - }); - } - - public void testUpdateEclipseLinkImpliedMappingFileRef1() throws Exception { - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that there is one initially - JpaXmlResource eclipseLinkOrmResource = getOrmXmlResource(); - assertTrue(eclipseLinkOrmResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - assertNotNull(persistenceUnit.getImpliedEclipseLinkMappingFileRef()); - - // remove eclipselink-orm.xml - deleteResource(eclipseLinkOrmResource); - - assertFalse(eclipseLinkOrmResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - assertNull(persistenceUnit.getImpliedEclipseLinkMappingFileRef()); - } - - public void testUpdateEclipseLinkImpliedMappingFileRef2() { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that there is one initially - JpaXmlResource eclipseLinkOrmResource = getOrmXmlResource(); - assertTrue(eclipseLinkOrmResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - assertNotNull(persistenceUnit.getImpliedEclipseLinkMappingFileRef()); - - // add specified eclipselink-orm.xml - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("META-INF/eclipselink-orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(1, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - - assertTrue(eclipseLinkOrmResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - assertNull(persistenceUnit.getImpliedEclipseLinkMappingFileRef()); - } - - public void testUpdateEclipseLinkImpliedMappingFileRef3() { - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - - // test that there is one initially - JpaXmlResource eclipseLinkOrmResource = getOrmXmlResource(); - assertTrue(eclipseLinkOrmResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - assertNotNull(persistenceUnit.getImpliedEclipseLinkMappingFileRef()); - - // ignore in persistence unit - persistenceUnit.getGeneralProperties().setExcludeEclipselinkOrm(Boolean.TRUE); - - assertTrue(eclipseLinkOrmResource.fileExists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - assertNull(persistenceUnit.getImpliedEclipseLinkMappingFileRef()); - } - - public void testMappingFileRefs() { - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - ListIterator mappingFileRefs = persistenceUnit.mappingFileRefs(); - - assertEquals(persistenceUnit.getImpliedMappingFileRef(), mappingFileRefs.next().getMappingFile().getParent()); - assertEquals(persistenceUnit.getImpliedEclipseLinkMappingFileRef(), mappingFileRefs.next().getMappingFile().getParent()); - } - - public void testMappingFileRefsSize() { - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - assertEquals(2, persistenceUnit.mappingFileRefsSize()); - } - - public void testPersistentType() throws Exception { - getJpaProject().setDiscoversAnnotatedClasses(false); - PersistenceUnit persistenceUnit = getPersistenceUnit(); - createTestEntity(); - - //persistentType not listed in persistence.xml and discoverAnnotatedClasses is false - //still find the persistentType because of changes for bug 190317 - assertFalse(getJpaProject().discoversAnnotatedClasses()); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - //test persistentType not listed in persistence.xml, discover annotated classes set to true - getJpaProject().setDiscoversAnnotatedClasses(true); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - //test persistentType list as class in persistence.xml - getJpaProject().setDiscoversAnnotatedClasses(false); - XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - classRef.setJavaClass(FULLY_QUALIFIED_TYPE_NAME); - getXmlPersistenceUnit().getClasses().add(classRef); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - - //test persistentType from orm.xml file that is specified in the persistence.xml - addXmlMappingFileRef(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH.toString()); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - assertNotNull(persistenceUnit.getPersistentType("model.Foo")); - assertEquals(ormPersistentType, persistenceUnit.getPersistentType("model.Foo")); - - //test persistentType from eclipselink-orm.xml file that is implied(not specified) in the persistence.xml - getXmlPersistenceUnit().getMappingFiles().remove(0); - assertNotNull(persistenceUnit.getPersistentType("model.Foo")); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/JptEclipseLinkCorePersistenceContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/JptEclipseLinkCorePersistenceContextModelTests.java deleted file mode 100644 index 825e5d5a32..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/JptEclipseLinkCorePersistenceContextModelTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.caching.JptEclipseLinkPersistenceCachingTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.connection.JptEclipseLinkPersistenceConnectionTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.customization.JptEclipseLinkPersistenceCustomizationTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.general.JptEclipseLinkPersistenceGeneralTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.logging.JptEclipseLinkPersistenceLoggingTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.options.JptEclipseLinkPersistenceOptionsTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.schema.generation.JptEclipseLinkPersistenceSchemaGenerationTests; - -public class JptEclipseLinkCorePersistenceContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCorePersistenceContextModelTests.class.getName()); - suite.addTestSuite(EclipseLinkPersistenceUnitTests.class); - suite.addTest(JptEclipseLinkPersistenceGeneralTests.suite()); - suite.addTest(JptEclipseLinkPersistenceConnectionTests.suite()); - suite.addTest(JptEclipseLinkPersistenceCustomizationTests.suite()); - suite.addTest(JptEclipseLinkPersistenceCachingTests.suite()); - suite.addTest(JptEclipseLinkPersistenceLoggingTests.suite()); - suite.addTest(JptEclipseLinkPersistenceOptionsTests.suite()); - suite.addTest(JptEclipseLinkPersistenceSchemaGenerationTests.suite()); - return suite; - } - - private JptEclipseLinkCorePersistenceContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java deleted file mode 100644 index cb9107fb68..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java +++ /dev/null @@ -1,449 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.caching; - -import org.eclipse.jpt.common.utility.model.event.ListAddEvent; -import org.eclipse.jpt.common.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.common.utility.model.event.ListClearEvent; -import org.eclipse.jpt.common.utility.model.event.ListEvent; -import org.eclipse.jpt.common.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.common.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.caching.CacheType; -import org.eclipse.jpt.eclipselink.core.context.persistence.caching.Caching; -import org.eclipse.jpt.eclipselink.core.context.persistence.caching.FlushClearCache; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * Tests the update of model objects by the Caching adapter when the - * PersistenceUnit changes. - */ -@SuppressWarnings("nls") -public class CachingAdapterTests extends EclipseLinkPersistenceUnitTestCase -{ - private Caching caching; - private ListEvent 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 static final String FLUSH_CLEAR_CACHE_KEY = Caching.ECLIPSELINK_FLUSH_CLEAR_CACHE; - public static final FlushClearCache FLUSH_CLEAR_CACHE_TEST_VALUE = FlushClearCache.drop; - public static final FlushClearCache FLUSH_CLEAR_CACHE_TEST_VALUE_2 = FlushClearCache.merge; - - public CachingAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.caching = this.getPersistenceUnit().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(Entity.CACHE_TYPE_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Entity.CACHE_SIZE_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Entity.SHARED_CACHE_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.FLUSH_CLEAR_CACHE_PROPERTY, propertyChangeListener); - - ListChangeListener entitiesChangeListener = this.buildEntitiesChangeListener(); - this.caching.addListChangeListener(Caching.ENTITIES_LIST, 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.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(CACHE_TYPE_DEFAULT_KEY, CACHE_TYPE_DEFAULT_TEST_VALUE); - this.persistenceUnitSetProperty("misc.property.2", "value.2"); - this.persistenceUnitSetProperty(CACHE_SIZE_DEFAULT_KEY, CACHE_SIZE_DEFAULT_TEST_VALUE); - this.persistenceUnitSetProperty(SHARED_CACHE_DEFAULT_KEY, SHARED_CACHE_DEFAULT_TEST_VALUE); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - this.persistenceUnitSetProperty("misc.property.4", "value.4"); - this.persistenceUnitSetProperty(CACHE_SIZE_KEY, CACHE_SIZE_TEST_VALUE); - this.persistenceUnitSetProperty(CACHE_TYPE_KEY, CACHE_TYPE_TEST_VALUE); - this.persistenceUnitSetProperty(SHARED_CACHE_KEY, SHARED_CACHE_TEST_VALUE); - this.persistenceUnitSetProperty(FLUSH_CLEAR_CACHE_KEY, FLUSH_CLEAR_CACHE_TEST_VALUE); - return; - } - - // ********** Listeners ********** - private ListChangeListener buildEntitiesChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - CachingAdapterTests.this.entityAdded(e); - } - - public void itemsRemoved(ListRemoveEvent e) { - CachingAdapterTests.this.entityRemoved(e); - } - - public void itemsReplaced(ListReplaceEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListMoveEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListClearEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - CachingAdapterTests.this.throwUnsupportedOperationException(e); - } - }; - } - - @Override - protected void clearEvent() { - super.clearEvent(); - this.entitiesEvent = null; - } - - void entityAdded(ListAddEvent e) { - this.entitiesEvent = e; - } - - void entityRemoved(ListRemoveEvent e) { - this.entitiesEvent = e; - } - - // ********** entities list ********** - public void testEntitiesList() throws Exception { - // add - this.clearEvent(); - int originalNumberOfEntities = this.caching.entitiesSize(); - - this.caching.addEntity(ENTITY_TEST_2); - assertEquals("Entity not added", this.caching.entitiesSize(), originalNumberOfEntities + 1); - - // verify event received - assertNotNull("No Event Fired.", this.entitiesEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.entitiesEvent.getListName(), Caching.ENTITIES_LIST); - - // remove - this.clearEvent(); - this.caching.removeEntity(ENTITY_TEST_2); - assertEquals("Entity not removed", this.caching.entitiesSize(), originalNumberOfEntities); - - // verify event received - assertNotNull("No Event Fired.", this.entitiesEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.entitiesEvent.getListName(), Caching.ENTITIES_LIST); - } - - // ********** CacheTypeDefault ********** - /** - * Tests the update of CacheTypeDefault property by the Caching adapter when - * the PU or the model changes. - */ - public void testSetCacheTypeDefault() throws Exception { - this.verifyModelInitialized( - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE, - CACHE_TYPE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveCacheTypeDefault() throws Exception { - this.verifyAddRemoveProperty( - CACHE_TYPE_DEFAULT_KEY, - CACHE_TYPE_DEFAULT_TEST_VALUE, - CACHE_TYPE_DEFAULT_TEST_VALUE_2); - } - - // ********** CacheSizeDefault ********** - /** - * Tests the update of CacheSizeDefault property by the Caching adapter when - * the PU or the model changes. - */ - public void testSetCacheSizeDefault() throws Exception { - this.verifyModelInitialized( - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE, - CACHE_SIZE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveCacheSizeDefault() throws Exception { - this.verifyAddRemoveProperty( - CACHE_SIZE_DEFAULT_KEY, - CACHE_SIZE_DEFAULT_TEST_VALUE, - CACHE_SIZE_DEFAULT_TEST_VALUE_2); - } - - // ********** SharedCacheDefault ********** - public void testSetSharedCacheDefault() throws Exception { - this.verifyModelInitialized( - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE); - this.verifySetProperty( - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE, - SHARED_CACHE_DEFAULT_TEST_VALUE_2); - } - - public void testAddRemoveSharedCacheDefault() throws Exception { - this.verifyAddRemoveProperty( - SHARED_CACHE_DEFAULT_KEY, - SHARED_CACHE_DEFAULT_TEST_VALUE, - SHARED_CACHE_DEFAULT_TEST_VALUE_2); - } - - // ********** CacheType ********** - /** - * Tests the update of CacheType property by the Caching adapter when the PU - * or the model changes. - */ - public void testSetCacheType() throws Exception { - this.verifyModelInitialized( - CACHE_TYPE_KEY, - CACHE_TYPE_TEST_VALUE); - this.verifySetCachingProperty( - Entity.CACHE_TYPE_PROPERTY, - CACHE_TYPE_KEY, - CACHE_TYPE_TEST_VALUE, - CACHE_TYPE_TEST_VALUE_2); - } - - public void testAddRemoveCacheType() throws Exception { - this.verifyAddRemoveCachingProperty( - Entity.CACHE_TYPE_PROPERTY, - CACHE_TYPE_KEY, - CACHE_TYPE_TEST_VALUE, - CACHE_TYPE_TEST_VALUE_2); - } - - // ********** CacheSize ********** - /** - * Tests the update of CacheSize property by the Caching adapter when the PU - * or the model changes. - */ - public void testSetCacheSize() throws Exception { - this.verifyModelInitialized( - CACHE_SIZE_KEY, - CACHE_SIZE_TEST_VALUE); - this.verifySetCachingProperty( - Entity.CACHE_SIZE_PROPERTY, - CACHE_SIZE_KEY, - CACHE_SIZE_TEST_VALUE, - CACHE_SIZE_TEST_VALUE_2); - } - - public void testAddRemoveCacheSize() throws Exception { - this.verifyAddRemoveCachingProperty( - Entity.CACHE_SIZE_PROPERTY, - CACHE_SIZE_KEY, - CACHE_SIZE_TEST_VALUE, - CACHE_SIZE_TEST_VALUE_2); - } - - // ********** SharedCache ********** - /** - * Tests the update of SharedCache property by the Caching adapter when the - * PU or the model changes. - */ - public void testSetSharedCache() throws Exception { - this.verifyModelInitialized( - SHARED_CACHE_KEY, - SHARED_CACHE_TEST_VALUE); - this.verifySetCachingProperty( - Entity.SHARED_CACHE_PROPERTY, - SHARED_CACHE_KEY, - SHARED_CACHE_TEST_VALUE, - SHARED_CACHE_TEST_VALUE_2); - } - - public void testAddRemoveSharedCache() throws Exception { - this.verifyAddRemoveCachingProperty( - Entity.SHARED_CACHE_PROPERTY, - SHARED_CACHE_KEY, - SHARED_CACHE_TEST_VALUE, - SHARED_CACHE_TEST_VALUE_2); - } - - // ********** FlushClearCache tests ********** - public void testSetFlushClearCache() throws Exception { - this.verifyModelInitialized( - FLUSH_CLEAR_CACHE_KEY, - FLUSH_CLEAR_CACHE_TEST_VALUE); - this.verifySetProperty( - FLUSH_CLEAR_CACHE_KEY, - FLUSH_CLEAR_CACHE_TEST_VALUE, - FLUSH_CLEAR_CACHE_TEST_VALUE_2); - } - - public void testAddRemoveFlushClearCache() throws Exception { - this.verifyAddRemoveProperty( - FLUSH_CLEAR_CACHE_KEY, - FLUSH_CLEAR_CACHE_TEST_VALUE, - FLUSH_CLEAR_CACHE_TEST_VALUE_2); - } - - // ****** convenience methods ******* - @Override - protected PersistenceUnitProperties getModel() { - return this.caching; - } - - protected void verifySetCachingProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Replace - this.persistenceUnitSetProperty(key, testValue2); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue2); - - // Replace by setting model object - this.clearEvent(); - this.setCachingProperty(propertyName, ENTITY_TEST, testValue1); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue1); - } - - protected void verifyAddRemoveCachingProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.getPersistenceUnit().removeProperty(key); - assertNull(this.getPersistenceUnit().getProperty(key)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, null); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(key, testValue1); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue1); - - // Set to null - this.persistenceUnitSetProperty(key, null); - this.verifyPutCachingProperty(propertyName, ENTITY_TEST, null); - - // Replace - this.persistenceUnitSetProperty(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 - Entity entity = (Entity) this.propertyChangedEvent.getNewValue(); - if (propertyName.equals(Entity.CACHE_TYPE_PROPERTY)) { - assertEquals(expectedValue, entity.getParent().getCacheTypeOf(entityName)); - assertEquals(expectedValue, this.caching.getCacheTypeOf(entityName)); - } - else if (propertyName.equals(Entity.CACHE_SIZE_PROPERTY)) { - assertEquals(expectedValue, entity.getParent().getCacheSizeOf(entityName)); - assertEquals(expectedValue, this.caching.getCacheSizeOf(entityName)); - } - else if (propertyName.equals(Entity.SHARED_CACHE_PROPERTY)) { - assertEquals(expectedValue, entity.getParent().getSharedCacheOf(entityName)); - assertEquals(expectedValue, this.caching.getSharedCacheOf(entityName)); - } - else { - this.throwMissingDefinition("verifyCachingEvent", propertyName); - } - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Caching.CACHE_TYPE_DEFAULT_PROPERTY)) - this.caching.setCacheTypeDefault((CacheType) newValue); - else if (propertyName.equals(Caching.CACHE_SIZE_DEFAULT_PROPERTY)) - this.caching.setCacheSizeDefault((Integer) newValue); - else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY)) - this.caching.setSharedCacheDefault((Boolean) newValue); - else if (propertyName.equals(Caching.FLUSH_CLEAR_CACHE_PROPERTY)) - this.caching.setFlushClearCache((FlushClearCache) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - protected void setCachingProperty(String propertyName, String entityName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(Entity.CACHE_TYPE_PROPERTY)) - this.caching.setCacheTypeOf(entityName, (CacheType) newValue); - else if (propertyName.equals(Entity.CACHE_SIZE_PROPERTY)) - this.caching.setCacheSizeOf(entityName, (Integer) newValue); - else if (propertyName.equals(Entity.SHARED_CACHE_PROPERTY)) - this.caching.setSharedCacheOf(entityName, (Boolean) newValue); - else - this.throwMissingDefinition("setCachingProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Caching.CACHE_TYPE_DEFAULT_PROPERTY)) - modelValue = this.caching.getCacheTypeDefault(); - else if (propertyName.equals(Caching.CACHE_SIZE_DEFAULT_PROPERTY)) - modelValue = this.caching.getCacheSizeDefault(); - else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY)) - modelValue = this.caching.getSharedCacheDefault(); - else if (propertyName.equals(Entity.CACHE_SIZE_PROPERTY)) - modelValue = this.caching.getCacheSizeOf(ENTITY_TEST); - else if (propertyName.equals(Entity.CACHE_TYPE_PROPERTY)) - modelValue = this.caching.getCacheTypeOf(ENTITY_TEST); - else if (propertyName.equals(Entity.SHARED_CACHE_PROPERTY)) - modelValue = this.caching.getSharedCacheOf(ENTITY_TEST); - else if (propertyName.equals(Caching.FLUSH_CLEAR_CACHE_PROPERTY)) - modelValue = this.caching.getFlushClearCache(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java deleted file mode 100644 index a0a0059a82..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.caching; - -import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.caching.CacheType; -import org.eclipse.jpt.eclipselink.core.context.persistence.caching.Caching; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * CachingValueModelTests - */ -@SuppressWarnings("nls") -public class CachingValueModelTests extends EclipseLinkPersistenceUnitTestCase -{ - private Caching caching; - private PropertyValueModel cachingHolder; - - private WritablePropertyValueModel cacheTypeHolder; - private PropertyChangeListener cacheTypeListener; - private PropertyChangeEvent cacheTypeEvent; - - private WritablePropertyValueModel sharedCacheHolder; - private PropertyChangeListener sharedCacheListener; - private PropertyChangeEvent sharedCacheEvent; - - private WritablePropertyValueModel cacheTypeDefaultHolder; - private PropertyChangeListener cacheTypeDefaultListener; - private PropertyChangeEvent cacheTypeDefaultEvent; - - private WritablePropertyValueModel 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.subject.getCaching(); // Subject - this.cachingHolder = new SimplePropertyValueModel(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 cacheTypeAA = - (PropertyAspectAdapter) 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 sharedCacheAA = - (PropertyAspectAdapter) 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 cacheTypeDefaultAA = - (PropertyAspectAdapter) 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 sharedCacheDefaultAA = - (PropertyAspectAdapter) 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. - */ - @Override - protected void populatePu() { - this.persistenceUnitSetProperty( - Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE, - CACHE_TYPE_TEST_VALUE); - this.persistenceUnitSetProperty( - Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE, - SHARED_CACHE_TEST_VALUE); - this.persistenceUnitSetProperty( - Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT, - CACHE_TYPE_DEFAULT_TEST_VALUE); - this.persistenceUnitSetProperty( - Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT, - SHARED_CACHE_DEFAULT_TEST_VALUE); - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.caching; - } - - /** ****** CacheType ******* */ - private WritablePropertyValueModel buildCacheTypeAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(subjectHolder, Caching.CACHE_TYPE_PROPERTY) { - @Override - protected CacheType buildValue_() { - return this.subject.getCacheTypeOf(ENTITY_NAME_TEST_VALUE); - } - - @Override - protected void setValue_(CacheType enumValue) { - this.subject.setCacheTypeOf(ENTITY_NAME_TEST_VALUE, enumValue); - } - }; - } - - private PropertyChangeListener buildCacheTypeChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingValueModelTests.this.cacheTypeEvent = e; - } - }; - } - - /** ****** SharedCache ******* */ - private WritablePropertyValueModel buildSharedCacheAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(subjectHolder, Caching.SHARED_CACHE_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getSharedCacheOf(ENTITY_NAME_TEST_VALUE); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setSharedCacheOf(ENTITY_NAME_TEST_VALUE, enumValue); - } - }; - } - - private PropertyChangeListener buildSharedCacheChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingValueModelTests.this.sharedCacheEvent = e; - } - }; - } - - /** ****** CacheTypeDefault ******* */ - private WritablePropertyValueModel buildCacheTypeDefaultAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(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 buildSharedCacheDefaultAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(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; - } - }; - } - - /** ****** Basic Entity's Properties Tests ******* */ - - public void testClone() { - Entity entity = this.buildEntity("TestEntity", CacheType.full, 100, true); - - this.verifyClone(entity, entity.clone()); - } - - public void testEquals() { - Entity entity1 = this.buildEntity("TestEntityA", CacheType.full, 100, true); - Entity entity2 = this.buildEntity("TestEntityB", CacheType.full, 100, true); - assertEquals(entity1, entity2); - Entity entity3 = this.buildEntity("TestEntityC", CacheType.full, 100, true); - assertEquals(entity1, entity3); - assertEquals(entity2, entity3); - } - - public void testIsEmpty() { - Entity entity = this.buildEntity("TestEntity"); - assertTrue(entity.isEmpty()); - this.caching.setCacheSizeOf(entity.getName(), 100); - assertFalse(entity.isEmpty()); - } - - private void verifyClone(Entity original, Entity clone) { - assertNotSame(original, clone); - assertEquals(original, original); - assertEquals(original, clone); - } - - private Entity buildEntity(String name) { - return this.caching.addEntity(name); - } - - private Entity buildEntity(String name, CacheType cacheType, Integer size, Boolean isShared) { - Entity entity = this.caching.addEntity(name); - this.caching.setCacheTypeOf(entity.getName(), cacheType); - this.caching.setCacheSizeOf(entity.getName(), size); - this.caching.setSharedCacheOf(entity.getName(), isShared); - return entity; - } - - /** ****** Caching Tests ******* */ - public void testValue() { - /** ****** CacheType - defaults for entity level caching are equal to the persistence unit settings ******* */ - this.verifyCacheTypeAAValue(CACHE_TYPE_TEST_VALUE); - assertEquals(this.caching.getCacheTypeDefault(), this.caching.getDefaultCacheType()); - /** ****** SharedCache - defaults for entity level caching are equal to the persistence unit settings ******* */ - this.verifySharedCacheAAValue(SHARED_CACHE_TEST_VALUE); - assertEquals(this.caching.getSharedCacheDefault(), this.caching.getDefaultSharedCache()); - /** ****** CacheTypeDefault ******* */ - this.verifyCacheTypeDefaultAAValue(CACHE_TYPE_DEFAULT_TEST_VALUE); - assertEquals(Caching.DEFAULT_CACHE_TYPE_DEFAULT, this.caching.getDefaultCacheTypeDefault()); - /** ****** SharedCacheDefault ******* */ - this.verifySharedCacheDefaultAAValue(SHARED_CACHE_DEFAULT_TEST_VALUE); - assertEquals(Caching.DEFAULT_SHARED_CACHE_DEFAULT, this.caching.getDefaultSharedCacheDefault()); - } - - public void testSetValue() throws Exception { - /** ****** CacheType ******* */ - this.cacheTypeEvent = null; - this.verifyHasListeners(this.cacheTypeHolder, PropertyValueModel.VALUE); - CacheType newCacheType = CacheType.full; - // Modify the property holder - this.cacheTypeHolder.setValue(newCacheType); - this.verifyCacheTypeAAValue(newCacheType); - assertNotNull(this.cacheTypeEvent); - /** ****** SharedCache ******* */ - this.sharedCacheEvent = null; - this.verifyHasListeners(this.sharedCacheHolder, PropertyValueModel.VALUE); - Boolean newSharedCache = !SHARED_CACHE_TEST_VALUE; - // Modify the property holder - this.sharedCacheHolder.setValue(newSharedCache); - this.verifySharedCacheAAValue(newSharedCache); - assertNotNull(this.sharedCacheEvent); - /** ****** CacheTypeDefault ******* */ - this.cacheTypeDefaultEvent = null; - this.verifyHasListeners(this.cacheTypeDefaultHolder, PropertyValueModel.VALUE); - CacheType newCacheTypeDefault = CacheType.none; - // Modify the property holder - this.cacheTypeDefaultHolder.setValue(newCacheTypeDefault); - this.verifyCacheTypeDefaultAAValue(newCacheTypeDefault); - assertNotNull(this.cacheTypeDefaultEvent); - /** ****** SharedCacheDefault ******* */ - this.sharedCacheDefaultEvent = null; - this.verifyHasListeners(this.sharedCacheDefaultHolder, PropertyValueModel.VALUE); - Boolean newSharedCacheDefault = !SHARED_CACHE_DEFAULT_TEST_VALUE; - // Modify the property holder - this.sharedCacheDefaultHolder.setValue(newSharedCacheDefault); - this.verifySharedCacheDefaultAAValue(newSharedCacheDefault); - assertNotNull(this.sharedCacheDefaultEvent); - } - - public void testSetNullValue() { - String notDeleted = "Property not deleted"; - /** ****** CacheType ******* */ - this.cacheTypeEvent = null; - // Setting the property holder - this.cacheTypeHolder.setValue(null); - // testing Holder - this.verifyCacheTypeAAValue(null); - assertNotNull(this.cacheTypeEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE, notDeleted); - /** ****** SharedCache ******* */ - this.sharedCacheEvent = null; - // Setting the property holder - this.sharedCacheHolder.setValue(null); - // testing Holder - this.verifySharedCacheAAValue(null); - assertNotNull(this.sharedCacheEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE, notDeleted); - /** ****** CacheTypeDefault ******* */ - this.cacheTypeDefaultEvent = null; - // Setting the property holder - this.cacheTypeDefaultHolder.setValue(null); - // testing Holder - this.verifyCacheTypeDefaultAAValue(null); - assertNotNull(this.cacheTypeDefaultEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT, notDeleted); - /** ****** SharedCacheDefault ******* */ - this.sharedCacheDefaultEvent = null; - // Setting the property holder - this.sharedCacheDefaultHolder.setValue(null); - // testing Holder - this.verifySharedCacheDefaultAAValue(null); - assertNotNull(this.sharedCacheDefaultEvent); - // testing PU properties - this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT, notDeleted); - } - - /** ****** convenience methods ******* */ - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyCacheTypeAAValue(CacheType testValue) { - this.verifyAAValue( - testValue, - this.caching.getCacheTypeOf(ENTITY_NAME_TEST_VALUE), - this.cacheTypeHolder, - Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE); - } - - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifySharedCacheAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.caching.getSharedCacheOf(ENTITY_NAME_TEST_VALUE), - this.sharedCacheHolder, - Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE); - } - - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyCacheTypeDefaultAAValue(CacheType testValue) { - this.verifyAAValue( - testValue, - this.caching.getCacheTypeDefault(), - this.cacheTypeDefaultHolder, - Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT); - } - - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifySharedCacheDefaultAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.caching.getSharedCacheDefault(), - this.sharedCacheDefaultHolder, - Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT); - } - - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/JptEclipseLinkPersistenceCachingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/JptEclipseLinkPersistenceCachingTests.java deleted file mode 100644 index 42da1ba956..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/JptEclipseLinkPersistenceCachingTests.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.context.persistence.caching; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkPersistenceCachingTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkPersistenceCachingTests.class.getPackage().getName()); - - suite.addTestSuite(CachingValueModelTests.class); - suite.addTestSuite(CachingAdapterTests.class); - - return suite; - } - - private JptEclipseLinkPersistenceCachingTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/EclipseLinkConnectionTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/EclipseLinkConnectionTests.java deleted file mode 100644 index d0f6740690..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/EclipseLinkConnectionTests.java +++ /dev/null @@ -1,542 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2008, 2010 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.connection; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.eclipselink.core.context.persistence.connection.BatchWriting; -import org.eclipse.jpt.eclipselink.core.context.persistence.connection.Connection; -import org.eclipse.jpt.eclipselink.core.context.persistence.connection.ExclusiveConnectionMode; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * ConnectionAdapterTests - */ -@SuppressWarnings("nls") -public class EclipseLinkConnectionTests extends EclipseLinkPersistenceUnitTestCase -{ - private Connection connection; - - public static final PersistenceUnitTransactionType TRANSACTION_TYPE_TEST_VALUE = PersistenceUnitTransactionType.RESOURCE_LOCAL; - public static final PersistenceUnitTransactionType TRANSACTION_TYPE_TEST_VALUE_2 = PersistenceUnitTransactionType.JTA; - - public static final String JTA_DATA_SOURCE_TEST_VALUE = "Test_JTA"; - public static final String JTA_DATA_SOURCE_TEST_VALUE_2 = "Test_JTA_2"; - - public static final String NON_JTA_DATA_SOURCE_TEST_VALUE = "Test_Non_JTA"; - public static final String NON_JTA_DATA_SOURCE_TEST_VALUE_2 = "Test_Non_JTA_2"; - - public static final String NATIVE_SQL_KEY = Connection.ECLIPSELINK_NATIVE_SQL; - public static final Boolean NATIVE_SQL_TEST_VALUE = false; - public static final Boolean NATIVE_SQL_TEST_VALUE_2 = ! NATIVE_SQL_TEST_VALUE; - - public static final String BATCH_WRITING_KEY = Connection.ECLIPSELINK_BATCH_WRITING; - public static final BatchWriting BATCH_WRITING_TEST_VALUE = BatchWriting.oracle_jdbc; - public static final BatchWriting BATCH_WRITING_TEST_VALUE_2 = BatchWriting.buffered; - - public static final String CACHE_STATEMENTS_KEY = Connection.ECLIPSELINK_CACHE_STATEMENTS; - public static final Boolean CACHE_STATEMENTS_TEST_VALUE = false; - public static final Boolean CACHE_STATEMENTS_TEST_VALUE_2 = ! CACHE_STATEMENTS_TEST_VALUE; - - public static final String CACHE_STATEMENTS_SIZE_KEY = Connection.ECLIPSELINK_CACHE_STATEMENTS_SIZE; - public static final Integer CACHE_STATEMENTS_SIZE_TEST_VALUE = 100; - public static final Integer CACHE_STATEMENTS_SIZE_TEST_VALUE_2 = 200; - - public static final String DRIVER_KEY = Connection.ECLIPSELINK_DRIVER; - public static final String DRIVER_TEST_VALUE = "connection.driver"; - public static final String DRIVER_TEST_VALUE_2 = "connection.driver.2"; - - public static final String URL_KEY = Connection.ECLIPSELINK_URL; - public static final String URL_TEST_VALUE = "test"; - public static final String URL_TEST_VALUE_2 = "test_2"; - - public static final String USER_KEY = Connection.ECLIPSELINK_USER; - public static final String USER_TEST_VALUE = "test"; - public static final String USER_TEST_VALUE_2 = "test_2"; - - public static final String PASSWORD_KEY = Connection.ECLIPSELINK_PASSWORD; - public static final String PASSWORD_TEST_VALUE = "test"; - public static final String PASSWORD_TEST_VALUE_2 = "test_2"; - - public static final String BIND_PARAMETERS_KEY = Connection.ECLIPSELINK_BIND_PARAMETERS; - public static final Boolean BIND_PARAMETERS_TEST_VALUE = false; - public static final Boolean BIND_PARAMETERS_TEST_VALUE_2 = ! BIND_PARAMETERS_TEST_VALUE; - - public static final String READ_CONNECTIONS_SHARED_KEY = Connection.ECLIPSELINK_READ_CONNECTIONS_SHARED; - public static final Boolean READ_CONNECTIONS_SHARED_TEST_VALUE = false; - public static final Boolean READ_CONNECTIONS_SHARED_TEST_VALUE_2 = ! READ_CONNECTIONS_SHARED_TEST_VALUE; - - public static final String READ_CONNECTIONS_MIN_KEY = Connection.ECLIPSELINK_READ_CONNECTIONS_MIN; - public static final Integer READ_CONNECTIONS_MIN_TEST_VALUE = 100; - public static final Integer READ_CONNECTIONS_MIN_TEST_VALUE_2 = 200; - - public static final String READ_CONNECTIONS_MAX_KEY = Connection.ECLIPSELINK_READ_CONNECTIONS_MAX; - public static final Integer READ_CONNECTIONS_MAX_TEST_VALUE = 100; - public static final Integer READ_CONNECTIONS_MAX_TEST_VALUE_2 = 200; - - public static final String WRITE_CONNECTIONS_MIN_KEY = Connection.ECLIPSELINK_WRITE_CONNECTIONS_MIN; - public static final Integer WRITE_CONNECTIONS_MIN_TEST_VALUE = 100; - public static final Integer WRITE_CONNECTIONS_MIN_TEST_VALUE_2 = 200; - - public static final String WRITE_CONNECTIONS_MAX_KEY = Connection.ECLIPSELINK_WRITE_CONNECTIONS_MAX; - public static final Integer WRITE_CONNECTIONS_MAX_TEST_VALUE = 100; - public static final Integer WRITE_CONNECTIONS_MAX_TEST_VALUE_2 = 200; - - public static final String EXCLUSIVE_CONNECTION_MODE_KEY = Connection.ECLIPSELINK_EXCLUSIVE_CONNECTION_MODE; - public static final ExclusiveConnectionMode EXCLUSIVE_CONNECTION_MODE_TEST_VALUE = ExclusiveConnectionMode.always; - public static final ExclusiveConnectionMode EXCLUSIVE_CONNECTION_MODE_TEST_VALUE_2 = ExclusiveConnectionMode.isolated; - - public static final String LAZY_CONNECTION_KEY = Connection.ECLIPSELINK_LAZY_CONNECTION; - public static final Boolean LAZY_CONNECTION_TEST_VALUE = false; - public static final Boolean LAZY_CONNECTION_TEST_VALUE_2 = ! LAZY_CONNECTION_TEST_VALUE; - - // ********** constructors ********** - public EclipseLinkConnectionTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.connection = this.subject.getConnection(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.connection.addPropertyChangeListener(Connection.NATIVE_SQL_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.BATCH_WRITING_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.CACHE_STATEMENTS_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.CACHE_STATEMENTS_SIZE_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.DRIVER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.URL_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.USER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.PASSWORD_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.BIND_PARAMETERS_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.READ_CONNECTIONS_SHARED_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.READ_CONNECTIONS_MIN_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.READ_CONNECTIONS_MAX_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.WRITE_CONNECTIONS_MIN_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.WRITE_CONNECTIONS_MAX_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.EXCLUSIVE_CONNECTION_MODE_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.LAZY_CONNECTION_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 16; // EclipseLink properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes EclipseLink properties - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(NATIVE_SQL_KEY, NATIVE_SQL_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(BATCH_WRITING_KEY, BATCH_WRITING_TEST_VALUE); - this.persistenceUnitSetProperty(CACHE_STATEMENTS_KEY, CACHE_STATEMENTS_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(CACHE_STATEMENTS_SIZE_KEY, CACHE_STATEMENTS_SIZE_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(DRIVER_KEY, DRIVER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(URL_KEY, URL_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(USER_KEY, USER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(PASSWORD_KEY, PASSWORD_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(BIND_PARAMETERS_KEY, BIND_PARAMETERS_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.2", "value.2"); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - this.persistenceUnitSetProperty(READ_CONNECTIONS_SHARED_KEY, READ_CONNECTIONS_SHARED_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(READ_CONNECTIONS_MIN_KEY, READ_CONNECTIONS_MIN_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(READ_CONNECTIONS_MAX_KEY, READ_CONNECTIONS_MAX_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WRITE_CONNECTIONS_MIN_KEY, WRITE_CONNECTIONS_MIN_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WRITE_CONNECTIONS_MAX_KEY, WRITE_CONNECTIONS_MAX_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.4", "value.4"); - this.persistenceUnitSetProperty(EXCLUSIVE_CONNECTION_MODE_KEY, EXCLUSIVE_CONNECTION_MODE_TEST_VALUE); - this.persistenceUnitSetProperty(LAZY_CONNECTION_KEY, LAZY_CONNECTION_TEST_VALUE.toString()); - - // Initializes PU elements - this.getPersistenceUnit().setSpecifiedTransactionType(TRANSACTION_TYPE_TEST_VALUE); - this.getPersistenceUnit().setJtaDataSource(JTA_DATA_SOURCE_TEST_VALUE); - this.getPersistenceUnit().setNonJtaDataSource(NON_JTA_DATA_SOURCE_TEST_VALUE); - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.connection; - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Connection.NATIVE_SQL_PROPERTY)) - this.connection.setNativeSql((Boolean) newValue); - else if (propertyName.equals(Connection.BATCH_WRITING_PROPERTY)) - this.connection.setBatchWriting((BatchWriting) newValue); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_PROPERTY)) - this.connection.setCacheStatements((Boolean) newValue); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_SIZE_PROPERTY)) - this.connection.setCacheStatementsSize((Integer) newValue); - else if (propertyName.equals(Connection.DRIVER_PROPERTY)) - this.connection.setDriver((String) newValue); - else if (propertyName.equals(Connection.URL_PROPERTY)) - this.connection.setUrl((String) newValue); - else if (propertyName.equals(Connection.USER_PROPERTY)) - this.connection.setUser((String) newValue); - else if (propertyName.equals(Connection.PASSWORD_PROPERTY)) - this.connection.setPassword((String) newValue); - else if (propertyName.equals(Connection.BIND_PARAMETERS_PROPERTY)) - this.connection.setBindParameters((Boolean) newValue); - else if (propertyName.equals(Connection.READ_CONNECTIONS_SHARED_PROPERTY)) - this.connection.setReadConnectionsShared((Boolean) newValue); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MIN_PROPERTY)) - this.connection.setReadConnectionsMin((Integer) newValue); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MAX_PROPERTY)) - this.connection.setReadConnectionsMax((Integer) newValue); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MIN_PROPERTY)) - this.connection.setWriteConnectionsMin((Integer) newValue); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MAX_PROPERTY)) - this.connection.setWriteConnectionsMax((Integer) newValue); - else if (propertyName.equals(Connection.EXCLUSIVE_CONNECTION_MODE_PROPERTY)) - this.connection.setExclusiveConnectionMode((ExclusiveConnectionMode) newValue); - else if (propertyName.equals(Connection.LAZY_CONNECTION_PROPERTY)) - this.connection.setLazyConnection((Boolean) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Connection.NATIVE_SQL_PROPERTY)) - modelValue = this.connection.getNativeSql(); - else if (propertyName.equals(Connection.BATCH_WRITING_PROPERTY)) - modelValue = this.connection.getBatchWriting(); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_PROPERTY)) - modelValue = this.connection.getCacheStatements(); - else if (propertyName.equals(Connection.CACHE_STATEMENTS_SIZE_PROPERTY)) - modelValue = this.connection.getCacheStatementsSize(); - else if (propertyName.equals(Connection.DRIVER_PROPERTY)) - modelValue = this.connection.getDriver(); - else if (propertyName.equals(Connection.URL_PROPERTY)) - modelValue = this.connection.getUrl(); - else if (propertyName.equals(Connection.USER_PROPERTY)) - modelValue = this.connection.getUser(); - else if (propertyName.equals(Connection.PASSWORD_PROPERTY)) - modelValue = this.connection.getPassword(); - else if (propertyName.equals(Connection.BIND_PARAMETERS_PROPERTY)) - modelValue = this.connection.getBindParameters(); - else if (propertyName.equals(Connection.READ_CONNECTIONS_SHARED_PROPERTY)) - modelValue = this.connection.getReadConnectionsShared(); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MIN_PROPERTY)) - modelValue = this.connection.getReadConnectionsMin(); - else if (propertyName.equals(Connection.READ_CONNECTIONS_MAX_PROPERTY)) - modelValue = this.connection.getReadConnectionsMax(); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MIN_PROPERTY)) - modelValue = this.connection.getWriteConnectionsMin(); - else if (propertyName.equals(Connection.WRITE_CONNECTIONS_MAX_PROPERTY)) - modelValue = this.connection.getWriteConnectionsMax(); - else if (propertyName.equals(Connection.EXCLUSIVE_CONNECTION_MODE_PROPERTY)) - modelValue = this.connection.getExclusiveConnectionMode(); - else if (propertyName.equals(Connection.LAZY_CONNECTION_PROPERTY)) - modelValue = this.connection.getLazyConnection(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - // ********** NativeSql tests ********** - public void testSetNativeSql() throws Exception { - this.verifyModelInitialized( - NATIVE_SQL_KEY, - NATIVE_SQL_TEST_VALUE); - this.verifySetProperty( - NATIVE_SQL_KEY, - NATIVE_SQL_TEST_VALUE, - NATIVE_SQL_TEST_VALUE_2); - } - - public void testAddRemoveNativeSql() throws Exception { - this.verifyAddRemoveProperty( - NATIVE_SQL_KEY, - NATIVE_SQL_TEST_VALUE, - NATIVE_SQL_TEST_VALUE_2); - } - - // ********** BatchWriting tests ********** - public void testSetBatchWriting() throws Exception { - this.verifyModelInitialized( - BATCH_WRITING_KEY, - BATCH_WRITING_TEST_VALUE); - this.verifySetProperty( - BATCH_WRITING_KEY, - BATCH_WRITING_TEST_VALUE, - BATCH_WRITING_TEST_VALUE_2); - } - - public void testAddRemoveBatchWriting() throws Exception { - this.verifyAddRemoveProperty( - BATCH_WRITING_KEY, - BATCH_WRITING_TEST_VALUE, - BATCH_WRITING_TEST_VALUE_2); - } - - // ********** CacheStatements tests ********** - public void testSetCacheStatements() throws Exception { - this.verifyModelInitialized( - CACHE_STATEMENTS_KEY, - CACHE_STATEMENTS_TEST_VALUE); - this.verifySetProperty( - CACHE_STATEMENTS_KEY, - CACHE_STATEMENTS_TEST_VALUE, - CACHE_STATEMENTS_TEST_VALUE_2); - } - - public void testAddRemoveCacheStatements() throws Exception { - this.verifyAddRemoveProperty( - CACHE_STATEMENTS_KEY, - CACHE_STATEMENTS_TEST_VALUE, - CACHE_STATEMENTS_TEST_VALUE_2); - } - - // ********** CacheStatementsSize tests ********** - public void testSetCacheStatementsSize() throws Exception { - this.verifyModelInitialized( - CACHE_STATEMENTS_SIZE_KEY, - CACHE_STATEMENTS_SIZE_TEST_VALUE); - this.verifySetProperty( - CACHE_STATEMENTS_SIZE_KEY, - CACHE_STATEMENTS_SIZE_TEST_VALUE, - CACHE_STATEMENTS_SIZE_TEST_VALUE_2); - } - - public void testAddRemoveCacheStatementsSize() throws Exception { - this.verifyAddRemoveProperty( - CACHE_STATEMENTS_SIZE_KEY, - CACHE_STATEMENTS_SIZE_TEST_VALUE, - CACHE_STATEMENTS_SIZE_TEST_VALUE_2); - } - - // ********** Driver tests ********** - public void testSetDriver() throws Exception { - this.verifyModelInitialized( - DRIVER_KEY, - DRIVER_TEST_VALUE); - this.verifySetProperty( - DRIVER_KEY, - DRIVER_TEST_VALUE, - DRIVER_TEST_VALUE_2); - } - - public void testAddRemoveDriver() throws Exception { - this.verifyAddRemoveProperty( - DRIVER_KEY, - DRIVER_TEST_VALUE, - DRIVER_TEST_VALUE_2); - } - - // ********** Url tests ********** - public void testSetUrl() throws Exception { - this.verifyModelInitialized( - URL_KEY, - URL_TEST_VALUE); - this.verifySetProperty( - URL_KEY, - URL_TEST_VALUE, - URL_TEST_VALUE_2); - } - - public void testAddRemoveUrl() throws Exception { - this.verifyAddRemoveProperty( - URL_KEY, - URL_TEST_VALUE, - URL_TEST_VALUE_2); - } - - // ********** User tests ********** - public void testSetUser() throws Exception { - this.verifyModelInitialized( - USER_KEY, - USER_TEST_VALUE); - this.verifySetProperty( - USER_KEY, - USER_TEST_VALUE, - USER_TEST_VALUE_2); - } - - public void testAddRemoveUser() throws Exception { - this.verifyAddRemoveProperty( - USER_KEY, - USER_TEST_VALUE, - USER_TEST_VALUE_2); - } - - // ********** Password tests ********** - public void testSetPassword() throws Exception { - this.verifyModelInitialized( - PASSWORD_KEY, - PASSWORD_TEST_VALUE); - this.verifySetProperty( - PASSWORD_KEY, - PASSWORD_TEST_VALUE, - PASSWORD_TEST_VALUE_2); - } - - public void testAddRemovePassword() throws Exception { - this.verifyAddRemoveProperty( - PASSWORD_KEY, - PASSWORD_TEST_VALUE, - PASSWORD_TEST_VALUE_2); - } - - // ********** BindParameters tests ********** - public void testSetBindParameters() throws Exception { - this.verifyModelInitialized( - BIND_PARAMETERS_KEY, - BIND_PARAMETERS_TEST_VALUE); - this.verifySetProperty( - BIND_PARAMETERS_KEY, - BIND_PARAMETERS_TEST_VALUE, - BIND_PARAMETERS_TEST_VALUE_2); - } - - public void testAddRemoveBindParameters() throws Exception { - this.verifyAddRemoveProperty( - BIND_PARAMETERS_KEY, - BIND_PARAMETERS_TEST_VALUE, - BIND_PARAMETERS_TEST_VALUE_2); - } - - // ********** ReadConnectionsShared tests ********** - public void testSetReadConnectionsShared() throws Exception { - this.verifyModelInitialized( - READ_CONNECTIONS_SHARED_KEY, - READ_CONNECTIONS_SHARED_TEST_VALUE); - this.verifySetProperty( - READ_CONNECTIONS_SHARED_KEY, - READ_CONNECTIONS_SHARED_TEST_VALUE, - READ_CONNECTIONS_SHARED_TEST_VALUE_2); - } - - public void testAddRemoveReadConnectionsShared() throws Exception { - this.verifyAddRemoveProperty( - READ_CONNECTIONS_SHARED_KEY, - READ_CONNECTIONS_SHARED_TEST_VALUE, - READ_CONNECTIONS_SHARED_TEST_VALUE_2); - } - - // ********** ReadConnectionsMin tests ********** - public void testSetReadConnectionsMin() throws Exception { - this.verifyModelInitialized( - READ_CONNECTIONS_MIN_KEY, - READ_CONNECTIONS_MIN_TEST_VALUE); - this.verifySetProperty( - READ_CONNECTIONS_MIN_KEY, - READ_CONNECTIONS_MIN_TEST_VALUE, - READ_CONNECTIONS_MIN_TEST_VALUE_2); - } - - public void testAddRemoveReadConnectionsMin() throws Exception { - this.verifyAddRemoveProperty( - READ_CONNECTIONS_MIN_KEY, - READ_CONNECTIONS_MIN_TEST_VALUE, - READ_CONNECTIONS_MIN_TEST_VALUE_2); - } - - // ********** ReadConnectionsMax tests ********** - public void testSetReadConnectionsMax() throws Exception { - this.verifyModelInitialized( - READ_CONNECTIONS_MAX_KEY, - READ_CONNECTIONS_MAX_TEST_VALUE); - this.verifySetProperty( - READ_CONNECTIONS_MAX_KEY, - READ_CONNECTIONS_MAX_TEST_VALUE, - READ_CONNECTIONS_MAX_TEST_VALUE_2); - } - - public void testAddRemoveReadConnectionsMax() throws Exception { - this.verifyAddRemoveProperty( - READ_CONNECTIONS_MAX_KEY, - READ_CONNECTIONS_MAX_TEST_VALUE, - READ_CONNECTIONS_MAX_TEST_VALUE_2); - } - - // ********** WriteConnectionsMin tests ********** - public void testSetWriteConnectionsMin() throws Exception { - this.verifyModelInitialized( - WRITE_CONNECTIONS_MIN_KEY, - WRITE_CONNECTIONS_MIN_TEST_VALUE); - this.verifySetProperty( - WRITE_CONNECTIONS_MIN_KEY, - WRITE_CONNECTIONS_MIN_TEST_VALUE, - WRITE_CONNECTIONS_MIN_TEST_VALUE_2); - } - - public void testAddRemoveWriteConnectionsMin() throws Exception { - this.verifyAddRemoveProperty( - WRITE_CONNECTIONS_MIN_KEY, - WRITE_CONNECTIONS_MIN_TEST_VALUE, - WRITE_CONNECTIONS_MIN_TEST_VALUE_2); - } - - // ********** WriteConnectionsMax tests ********** - public void testSetWriteConnectionsMax() throws Exception { - this.verifyModelInitialized( - WRITE_CONNECTIONS_MAX_KEY, - WRITE_CONNECTIONS_MAX_TEST_VALUE); - this.verifySetProperty( - WRITE_CONNECTIONS_MAX_KEY, - WRITE_CONNECTIONS_MAX_TEST_VALUE, - WRITE_CONNECTIONS_MAX_TEST_VALUE_2); - } - - public void testAddRemoveWriteConnectionsMax() throws Exception { - this.verifyAddRemoveProperty( - WRITE_CONNECTIONS_MAX_KEY, - WRITE_CONNECTIONS_MAX_TEST_VALUE, - WRITE_CONNECTIONS_MAX_TEST_VALUE_2); - } - - // ********** ExclusiveConnectionMode tests ********** - public void testSetExclusiveConnectionMode() throws Exception { - this.verifyModelInitialized( - EXCLUSIVE_CONNECTION_MODE_KEY, - EXCLUSIVE_CONNECTION_MODE_TEST_VALUE); - this.verifySetProperty( - EXCLUSIVE_CONNECTION_MODE_KEY, - EXCLUSIVE_CONNECTION_MODE_TEST_VALUE, - EXCLUSIVE_CONNECTION_MODE_TEST_VALUE_2); - } - - public void testAddRemoveExclusiveConnectionMode() throws Exception { - this.verifyAddRemoveProperty( - EXCLUSIVE_CONNECTION_MODE_KEY, - EXCLUSIVE_CONNECTION_MODE_TEST_VALUE, - EXCLUSIVE_CONNECTION_MODE_TEST_VALUE_2); - } - - // ********** LazyConnection tests ********** - public void testSetLazyConnection() throws Exception { - this.verifyModelInitialized( - LAZY_CONNECTION_KEY, - LAZY_CONNECTION_TEST_VALUE); - this.verifySetProperty( - LAZY_CONNECTION_KEY, - LAZY_CONNECTION_TEST_VALUE, - LAZY_CONNECTION_TEST_VALUE_2); - } - - public void testAddRemoveLazyConnection() throws Exception { - this.verifyAddRemoveProperty( - LAZY_CONNECTION_KEY, - LAZY_CONNECTION_TEST_VALUE, - LAZY_CONNECTION_TEST_VALUE_2); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/JptEclipseLinkPersistenceConnectionTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/JptEclipseLinkPersistenceConnectionTests.java deleted file mode 100644 index df33d3274a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/connection/JptEclipseLinkPersistenceConnectionTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.connection; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkPersistenceConnectionTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkPersistenceConnectionTests.class.getPackage().getName()); - -// suite.addTestSuite(ConnectionValueModelTests.class); - suite.addTestSuite(EclipseLinkConnectionTests.class); - - return suite; - } - - private JptEclipseLinkPersistenceConnectionTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java deleted file mode 100644 index d18232b649..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.customization; - -import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.customization.Customization; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Entity; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * CustomizationValueModelTests - */ -public class CustomizationValueModelTests extends EclipseLinkPersistenceUnitTestCase -{ - private Customization customization; - - private WritablePropertyValueModel 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 static final String CUSTOMIZER_TEST_VALUE = "acme.sessions.Customizer"; - - public CustomizationValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.customization = this.subject.getCustomization(); // Subject - PropertyValueModel customizationHolder = new SimplePropertyValueModel(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 throwExceptionsAA = - (PropertyAspectAdapter) 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. - */ - @Override - protected void populatePu() { - this.persistenceUnitSetProperty( - Customization.ECLIPSELINK_THROW_EXCEPTIONS, - THROW_EXCEPTIONS_TEST_VALUE); - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.customization; - } - - // ****** ThrowExceptions ******* - private WritablePropertyValueModel buildThrowExceptionsAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(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; - } - }; - } - - /** ****** Basic Entity's Properties Tests ******* */ - - public void testClone() { - Entity entity = this.buildEntity("TestEntity", CUSTOMIZER_TEST_VALUE); - - this.verifyClone(entity, entity.clone()); - } - - public void testEquals() { - Entity entity1 = this.buildEntity("TestEntityA", CUSTOMIZER_TEST_VALUE); - Entity entity2 = this.buildEntity("TestEntityB", CUSTOMIZER_TEST_VALUE); - assertEquals(entity1, entity2); - Entity entity3 = this.buildEntity("TestEntityC", CUSTOMIZER_TEST_VALUE); - assertEquals(entity1, entity3); - assertEquals(entity2, entity3); - } - - public void testIsEmpty() { - Entity entity = this.buildEntity("TestEntity"); - assertTrue(entity.isEmpty()); - this.customization.setDescriptorCustomizerOf(entity.getName(), CUSTOMIZER_TEST_VALUE); - assertFalse(entity.isEmpty()); - } - - private void verifyClone(Entity original, Entity clone) { - assertNotSame(original, clone); - assertEquals(original, original); - assertEquals(original, clone); - } - - private Entity buildEntity(String name) { - return this.customization.addEntity(name); - } - - private Entity buildEntity(String name, String aClassName) { - Entity entity = this.customization.addEntity(name); - this.customization.setDescriptorCustomizerOf(entity.getName(), aClassName); - return entity; - } - - // ****** 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:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyThrowExceptionsAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.customization.getThrowExceptions(), - this.throwExceptionsHolder, - Customization.ECLIPSELINK_THROW_EXCEPTIONS); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/EclipseLinkCustomizationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/EclipseLinkCustomizationTests.java deleted file mode 100644 index 11367bd891..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/EclipseLinkCustomizationTests.java +++ /dev/null @@ -1,762 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.customization; - -import java.util.ListIterator; - -import org.eclipse.jpt.common.utility.model.event.ListAddEvent; -import org.eclipse.jpt.common.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.common.utility.model.event.ListClearEvent; -import org.eclipse.jpt.common.utility.model.event.ListEvent; -import org.eclipse.jpt.common.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.common.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.customization.Customization; -import org.eclipse.jpt.eclipselink.core.context.persistence.customization.Profiler; -import org.eclipse.jpt.eclipselink.core.context.persistence.customization.Weaving; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.EclipseLinkCustomization; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Entity; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * Tests the update of model objects by the Customization adapter when the - * PersistenceUnit changes. - */ -@SuppressWarnings("nls") -public class EclipseLinkCustomizationTests extends EclipseLinkPersistenceUnitTestCase -{ - private Customization customization; - private ListEvent entitiesEvent; - private ListEvent sessionCustomizersEvent; - - public static final String ENTITY_TEST = "Employee"; - public static final String ENTITY_TEST_2 = "Address"; - - public static final String THROW_EXCEPTIONS_KEY = Customization.ECLIPSELINK_THROW_EXCEPTIONS; - public static final Boolean THROW_EXCEPTIONS_TEST_VALUE = false; - public static final Boolean THROW_EXCEPTIONS_TEST_VALUE_2 = ! THROW_EXCEPTIONS_TEST_VALUE; - - public static final String WEAVING_LAZY_KEY = Customization.ECLIPSELINK_WEAVING_LAZY; - public static final Boolean WEAVING_LAZY_TEST_VALUE = false; - public static final Boolean WEAVING_LAZY_TEST_VALUE_2 = ! WEAVING_LAZY_TEST_VALUE; - - public static final String WEAVING_CHANGE_TRACKING_KEY = Customization.ECLIPSELINK_WEAVING_CHANGE_TRACKING; - public static final Boolean WEAVING_CHANGE_TRACKING_TEST_VALUE = false; - public static final Boolean WEAVING_CHANGE_TRACKING_TEST_VALUE_2 = ! WEAVING_CHANGE_TRACKING_TEST_VALUE; - - public static final String WEAVING_FETCH_GROUPS_KEY = Customization.ECLIPSELINK_WEAVING_FETCH_GROUPS; - public static final Boolean WEAVING_FETCH_GROUPS_TEST_VALUE = false; - public static final Boolean WEAVING_FETCH_GROUPS_TEST_VALUE_2 = ! WEAVING_FETCH_GROUPS_TEST_VALUE; - - public static final String WEAVING_INTERNAL_KEY = Customization.ECLIPSELINK_WEAVING_INTERNAL; - public static final Boolean WEAVING_INTERNAL_TEST_VALUE = false; - public static final Boolean WEAVING_INTERNAL_TEST_VALUE_2 = ! WEAVING_INTERNAL_TEST_VALUE; - - public static final String WEAVING_EAGER_KEY = Customization.ECLIPSELINK_WEAVING_EAGER; - public static final Boolean WEAVING_EAGER_TEST_VALUE = true; - public static final Boolean WEAVING_EAGER_TEST_VALUE_2 = ! WEAVING_EAGER_TEST_VALUE; - - public static final String VALIDATION_ONLY_KEY = Customization.ECLIPSELINK_VALIDATION_ONLY; - public static final Boolean VALIDATION_ONLY_TEST_VALUE = false; - public static final Boolean VALIDATION_ONLY_TEST_VALUE_2 = ! VALIDATION_ONLY_TEST_VALUE; - - public static final String VALIDATE_SCHEMA_KEY = Customization.ECLIPSELINK_VALIDATE_SCHEMA; - public static final Boolean VALIDATE_SCHEMA_TEST_VALUE = true; - public static final Boolean VALIDATE_SCHEMA_TEST_VALUE_2 = ! VALIDATE_SCHEMA_TEST_VALUE; - - private static final String SESSION_CUSTOMIZER_KEY = Customization.ECLIPSELINK_SESSION_CUSTOMIZER; - private static final String SESSION_CUSTOMIZER_TEST_VALUE = "java.lang.String"; - private static final String SESSION_CUSTOMIZER_TEST_VALUE_2 = "java.lang.Boolean"; - - public static final String WEAVING_KEY = Customization.ECLIPSELINK_WEAVING; - public static final Weaving WEAVING_TEST_VALUE = Weaving.false_; - public static final Weaving WEAVING_TEST_VALUE_2 = Weaving.static_; - - public static final String CUSTOMIZER_KEY = Customization.ECLIPSELINK_DESCRIPTOR_CUSTOMIZER + ENTITY_TEST; - public static final String CUSTOMIZER_TEST_VALUE = "acme.sessions.DescriptorCustomizer"; - public static final String CUSTOMIZER_TEST_VALUE_2 = "acme.sessions.Customizer"; - - private static final String PROFILER_KEY = Customization.ECLIPSELINK_PROFILER; - private static final Profiler PROFILER_TEST_VALUE = Profiler.query_monitor; - private static final String PROFILER_TEST_VALUE_2 = "custom.profiler.test"; - - public static final String EXCEPTION_HANDLER_KEY = Customization.ECLIPSELINK_EXCEPTION_HANDLER; - public static final String EXCEPTION_HANDLER_TEST_VALUE = "acme.CustomSessionEventListener"; - public static final String EXCEPTION_HANDLER_TEST_VALUE_2 = "oracle.sessions.CustomSessionEventListener"; - - // ********** constructors ********** - public EclipseLinkCustomizationTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.customization = this.subject.getCustomization(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.customization.addPropertyChangeListener(Customization.THROW_EXCEPTIONS_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_LAZY_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_CHANGE_TRACKING_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_FETCH_GROUPS_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_INTERNAL_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_EAGER_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.WEAVING_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.VALIDATION_ONLY_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.VALIDATE_SCHEMA_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.SESSION_CUSTOMIZER_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.PROFILER_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.EXCEPTION_HANDLER_PROPERTY, propertyChangeListener); - - ListChangeListener sessionCustomizersChangeListener = this.buildSessionCustomizersChangeListener(); - this.customization.addListChangeListener(Customization.SESSION_CUSTOMIZER_LIST, sessionCustomizersChangeListener); - - ListChangeListener entitiesChangeListener = this.buildEntitiesChangeListener(); - this.customization.addListChangeListener(Customization.ENTITIES_LIST, entitiesChangeListener); - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 13; - this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(THROW_EXCEPTIONS_KEY, THROW_EXCEPTIONS_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WEAVING_LAZY_KEY, WEAVING_LAZY_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WEAVING_CHANGE_TRACKING_KEY, WEAVING_CHANGE_TRACKING_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WEAVING_FETCH_GROUPS_KEY, WEAVING_FETCH_GROUPS_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WEAVING_INTERNAL_KEY, WEAVING_INTERNAL_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WEAVING_EAGER_KEY, WEAVING_EAGER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(VALIDATION_ONLY_KEY, VALIDATION_ONLY_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(VALIDATE_SCHEMA_KEY, VALIDATE_SCHEMA_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.2", "value.2"); - this.persistenceUnitSetProperty(SESSION_CUSTOMIZER_KEY, SESSION_CUSTOMIZER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(WEAVING_KEY, WEAVING_TEST_VALUE); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - this.persistenceUnitSetProperty("misc.property.4", "value.4"); - this.persistenceUnitSetProperty(CUSTOMIZER_KEY, CUSTOMIZER_TEST_VALUE); - this.persistenceUnitSetProperty(PROFILER_KEY, PROFILER_TEST_VALUE); - this.persistenceUnitSetProperty(EXCEPTION_HANDLER_KEY, EXCEPTION_HANDLER_TEST_VALUE); - return; - } - - // ********** Listeners ********** - private ListChangeListener buildEntitiesChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - EclipseLinkCustomizationTests.this.entityAdded(e); - } - - public void itemsRemoved(ListRemoveEvent e) { - EclipseLinkCustomizationTests.this.entityRemoved(e); - } - - public void itemsReplaced(ListReplaceEvent e) { - EclipseLinkCustomizationTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListMoveEvent e) { - EclipseLinkCustomizationTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListClearEvent e) { - EclipseLinkCustomizationTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - EclipseLinkCustomizationTests.this.throwUnsupportedOperationException(e); - } - }; - } - - private ListChangeListener buildSessionCustomizersChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - EclipseLinkCustomizationTests.this.sessionCustomizerAdded(e); - } - - public void itemsRemoved(ListRemoveEvent e) { - EclipseLinkCustomizationTests.this.sessionCustomizerRemoved(e); - } - - public void itemsReplaced(ListReplaceEvent e) { - EclipseLinkCustomizationTests.this.sessionCustomizerReplaced(e); - } - - public void itemsMoved(ListMoveEvent e) { - EclipseLinkCustomizationTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListClearEvent e) { - EclipseLinkCustomizationTests.this.sessionCustomizerListCleared(e); - } - - public void listChanged(ListChangeEvent e) { - EclipseLinkCustomizationTests.this.throwUnsupportedOperationException(e); - } - }; - } - - @Override - protected void clearEvent() { - super.clearEvent(); - this.entitiesEvent = null; - this.sessionCustomizersEvent = null; - } - - void entityAdded(ListAddEvent e) { - this.entitiesEvent = e; - } - - void entityRemoved(ListRemoveEvent e) { - this.entitiesEvent = e; - } - - void sessionCustomizerAdded(ListAddEvent e) { - this.sessionCustomizersEvent = e; - } - - void sessionCustomizerRemoved(ListRemoveEvent e) { - this.sessionCustomizersEvent = e; - } - - void sessionCustomizerReplaced(ListReplaceEvent e) { - this.sessionCustomizersEvent = e; - } - - void sessionCustomizerListCleared(ListClearEvent e) { - this.sessionCustomizersEvent = e; - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Customization.THROW_EXCEPTIONS_PROPERTY)) - this.customization.setThrowExceptions((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_LAZY_PROPERTY)) - this.customization.setWeavingLazy((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_CHANGE_TRACKING_PROPERTY)) - this.customization.setWeavingChangeTracking((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_FETCH_GROUPS_PROPERTY)) - this.customization.setWeavingFetchGroups((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_INTERNAL_PROPERTY)) - this.customization.setWeavingInternal((Boolean) newValue); - else if (propertyName.equals(Customization.WEAVING_EAGER_PROPERTY)) - this.customization.setWeavingEager((Boolean) newValue); - else if (propertyName.equals(Customization.VALIDATION_ONLY_PROPERTY)) - this.customization.setValidationOnly((Boolean) newValue); - else if (propertyName.equals(Customization.VALIDATE_SCHEMA_PROPERTY)) - this.customization.setValidateSchema((Boolean) newValue); - else if (propertyName.equals(Customization.EXCEPTION_HANDLER_PROPERTY)) - this.customization.setExceptionHandler((String) newValue); - else if (propertyName.equals(Customization.SESSION_CUSTOMIZER_PROPERTY)) - this.customization.addSessionCustomizer((String) newValue); - else if (propertyName.equals(Customization.WEAVING_PROPERTY)) - this.customization.setWeaving((Weaving) newValue); - else if (propertyName.equals(Customization.PROFILER_PROPERTY)) { - if (newValue.getClass().isEnum()) - this.customization.setProfiler((Profiler) newValue); - else - this.customization.setProfiler((String) newValue); - } - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Customization.THROW_EXCEPTIONS_PROPERTY)) - modelValue = this.customization.getThrowExceptions(); - else if (propertyName.equals(Customization.WEAVING_PROPERTY)) - modelValue = this.customization.getWeaving(); - else if (propertyName.equals(Customization.WEAVING_LAZY_PROPERTY)) - modelValue = this.customization.getWeavingLazy(); - else if (propertyName.equals(Customization.WEAVING_CHANGE_TRACKING_PROPERTY)) - modelValue = this.customization.getWeavingChangeTracking(); - else if (propertyName.equals(Customization.WEAVING_FETCH_GROUPS_PROPERTY)) - modelValue = this.customization.getWeavingFetchGroups(); - else if (propertyName.equals(Customization.WEAVING_INTERNAL_PROPERTY)) - modelValue = this.customization.getWeavingInternal(); - else if (propertyName.equals(Customization.WEAVING_EAGER_PROPERTY)) - modelValue = this.customization.getWeavingEager(); - else if (propertyName.equals(Customization.VALIDATION_ONLY_PROPERTY)) - modelValue = this.customization.getValidationOnly(); - else if (propertyName.equals(Customization.VALIDATE_SCHEMA_PROPERTY)) - modelValue = this.customization.getValidateSchema(); - else if (propertyName.equals(Customization.EXCEPTION_HANDLER_PROPERTY)) - modelValue = this.customization.getExceptionHandler(); - else if (propertyName.equals(Customization.PROFILER_PROPERTY)) - modelValue = this.customization.getProfiler(); - else if (propertyName.equals(Customization.SESSION_CUSTOMIZER_PROPERTY)) { - ListIterator iterator = this.customization.sessionCustomizers(); - if(iterator.hasNext()) { - modelValue = iterator.next(); - } - } - else if (propertyName.equals(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY)) - modelValue = this.customization.getDescriptorCustomizerOf(ENTITY_TEST); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - Object expectedValue_ = expectedValue; - if (propertyName.equals(Customization.PROFILER_PROPERTY)) { - - expectedValue_ = (expectedValue != null && expectedValue.getClass().isEnum()) ? - this.getPropertyStringValueOf(PROFILER_TEST_VALUE) : // model is storing EclipseLinkStringValue - expectedValue; - } - super.verifyPutProperty(propertyName, expectedValue_); - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.customization; - } - - // ********** 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.getListName(), Customization.ENTITIES_LIST); - - // 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.getListName(), Customization.ENTITIES_LIST); - } - - // ********** sessionCustomizers list ********** - public void testSessionCustomizersList() throws Exception { - // add - this.clearEvent(); - String className = this.customization.addSessionCustomizer(SESSION_CUSTOMIZER_TEST_VALUE_2); - - // verify event received - assertNotNull("No Event Fired.", this.sessionCustomizersEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.sessionCustomizersEvent.getListName(), Customization.SESSION_CUSTOMIZER_LIST); - - // remove - this.clearEvent(); - - this.customization.removeSessionCustomizer(className); - // verify event received - assertNotNull("No Event Fired.", this.sessionCustomizersEvent); - // verify event for the expected property - assertEquals("Wrong Event.", this.sessionCustomizersEvent.getListName(), Customization.SESSION_CUSTOMIZER_LIST); - } - - // ********** ThrowExceptions tests ********** - public void testSetThrowExceptions() throws Exception { - this.verifyModelInitialized( - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE); - this.verifySetProperty( - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE, - THROW_EXCEPTIONS_TEST_VALUE_2); - } - - public void testAddRemoveThrowExceptions() throws Exception { - this.verifyAddRemoveProperty( - THROW_EXCEPTIONS_KEY, - THROW_EXCEPTIONS_TEST_VALUE, - THROW_EXCEPTIONS_TEST_VALUE_2); - } - - // ********** WeavingLazy tests ********** - public void testSetWeavingLazy() throws Exception { - this.verifyModelInitialized( - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE); - this.verifySetProperty( - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE, - WEAVING_LAZY_TEST_VALUE_2); - } - - public void testAddRemoveWeavingLazy() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_LAZY_KEY, - WEAVING_LAZY_TEST_VALUE, - WEAVING_LAZY_TEST_VALUE_2); - } - - // ********** WeavingChangeTracking tests ********** - public void testSetWeavingChangeTracking() throws Exception { - this.verifyModelInitialized( - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE); - this.verifySetProperty( - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE, - WEAVING_CHANGE_TRACKING_TEST_VALUE_2); - } - - public void testAddRemoveWeavingChangeTracking() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_CHANGE_TRACKING_KEY, - WEAVING_CHANGE_TRACKING_TEST_VALUE, - WEAVING_CHANGE_TRACKING_TEST_VALUE_2); - } - - // ********** WeavingFetchGroups tests ********** - public void testSetWeavingFetchGroups() throws Exception { - this.verifyModelInitialized( - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE); - this.verifySetProperty( - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE, - WEAVING_FETCH_GROUPS_TEST_VALUE_2); - } - - public void testAddRemoveWeavingFetchGroups() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_FETCH_GROUPS_KEY, - WEAVING_FETCH_GROUPS_TEST_VALUE, - WEAVING_FETCH_GROUPS_TEST_VALUE_2); - } - - // ********** WeavingInternal tests ********** - public void testSetWeavingInternal() throws Exception { - this.verifyModelInitialized( - WEAVING_INTERNAL_KEY, - WEAVING_INTERNAL_TEST_VALUE); - this.verifySetProperty( - WEAVING_INTERNAL_KEY, - WEAVING_INTERNAL_TEST_VALUE, - WEAVING_INTERNAL_TEST_VALUE_2); - } - - public void testAddRemoveWeavingInternal() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_INTERNAL_KEY, - WEAVING_INTERNAL_TEST_VALUE, - WEAVING_INTERNAL_TEST_VALUE_2); - } - - // ********** WeavingEager tests ********** - public void testSetWeavingEager() throws Exception { - this.verifyModelInitialized( - WEAVING_EAGER_KEY, - WEAVING_EAGER_TEST_VALUE); - this.verifySetProperty( - WEAVING_EAGER_KEY, - WEAVING_EAGER_TEST_VALUE, - WEAVING_EAGER_TEST_VALUE_2); - } - - public void testAddRemoveWeavingEager() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_EAGER_KEY, - WEAVING_EAGER_TEST_VALUE, - WEAVING_EAGER_TEST_VALUE_2); - } - - // ********** SessionCustomizer tests ********** - public void testSetSessionCustomizer() throws Exception { - this.verifyModelInitialized( - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE); - this.verifySetSessionCustomizationProperty( - Customization.SESSION_CUSTOMIZER_PROPERTY, - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE, - SESSION_CUSTOMIZER_TEST_VALUE_2); - } - - public void testAddRemoveSessionCustomizer() throws Exception { - this.verifyAddRemoveSessionCustomizationProperty( - Customization.SESSION_CUSTOMIZER_PROPERTY, - SESSION_CUSTOMIZER_KEY, - SESSION_CUSTOMIZER_TEST_VALUE, - SESSION_CUSTOMIZER_TEST_VALUE_2); - } - - // ********** Weaving tests ********** - /** - * Tests the update of Weaving property by the Customization adapter when - * the PU or the model changes. - */ - public void testSetWeaving() throws Exception { - this.verifyModelInitialized( - WEAVING_KEY, - WEAVING_TEST_VALUE); - this.verifySetProperty( - WEAVING_KEY, - WEAVING_TEST_VALUE, - WEAVING_TEST_VALUE_2); - } - - public void testAddRemoveWeaving() throws Exception { - this.verifyAddRemoveProperty( - WEAVING_KEY, - WEAVING_TEST_VALUE, - WEAVING_TEST_VALUE_2); - } - - // ********** ValidationOnly tests ********** - public void testSetValidationOnly() throws Exception { - this.verifyModelInitialized( - VALIDATION_ONLY_KEY, - VALIDATION_ONLY_TEST_VALUE); - this.verifySetProperty( - VALIDATION_ONLY_KEY, - VALIDATION_ONLY_TEST_VALUE, - VALIDATION_ONLY_TEST_VALUE_2); - } - - public void testAddRemoveValidationOnly() throws Exception { - this.verifyAddRemoveProperty( - VALIDATION_ONLY_KEY, - VALIDATION_ONLY_TEST_VALUE, - VALIDATION_ONLY_TEST_VALUE_2); - } - - // ********** ValidateSchema tests ********** - public void testSetValidateSchema() throws Exception { - this.verifyModelInitialized( - VALIDATE_SCHEMA_KEY, - VALIDATE_SCHEMA_TEST_VALUE); - this.verifySetProperty( - VALIDATE_SCHEMA_KEY, - VALIDATE_SCHEMA_TEST_VALUE, - VALIDATE_SCHEMA_TEST_VALUE_2); - } - - public void testAddRemoveValidateSchema() throws Exception { - this.verifyAddRemoveProperty( - VALIDATE_SCHEMA_KEY, - VALIDATE_SCHEMA_TEST_VALUE, - VALIDATE_SCHEMA_TEST_VALUE_2); - } - - // ********** ExceptionHandler tests ********** - public void testSetExceptionHandler() throws Exception { - this.verifyModelInitialized( - EXCEPTION_HANDLER_KEY, - EXCEPTION_HANDLER_TEST_VALUE); - this.verifySetProperty( - EXCEPTION_HANDLER_KEY, - EXCEPTION_HANDLER_TEST_VALUE, - EXCEPTION_HANDLER_TEST_VALUE_2); - } - - public void testAddRemoveExceptionHandler() throws Exception { - this.verifyAddRemoveProperty( - EXCEPTION_HANDLER_KEY, - EXCEPTION_HANDLER_TEST_VALUE, - EXCEPTION_HANDLER_TEST_VALUE_2); - } - - // ********** Customization class ********** - /** - * Tests the update of Customization property by the Customization adapter when the - * PU or the model changes. - */ - public void testSetCustomization() throws Exception { - this.verifyModelInitialized( - CUSTOMIZER_KEY, - CUSTOMIZER_TEST_VALUE); - this.verifySetCustomizationProperty( - Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY, - CUSTOMIZER_KEY, - CUSTOMIZER_TEST_VALUE, - CUSTOMIZER_TEST_VALUE_2); - } - - public void testAddRemoveCustomization() throws Exception { - this.verifyAddRemoveCustomizationProperty( - Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY, - CUSTOMIZER_KEY, - CUSTOMIZER_TEST_VALUE, - CUSTOMIZER_TEST_VALUE_2); - } - - // ********** Profiler tests ********** - public void testSetProfiler() throws Exception { - this.verifyModelInitialized( - PROFILER_KEY, - this.getPropertyStringValueOf(PROFILER_TEST_VALUE)); // model is storing EclipseLinkStringValue - // verify set enum value - this.verifySetProperty( - PROFILER_KEY, - PROFILER_TEST_VALUE, - PROFILER_TEST_VALUE_2); - // verify set custom and literal value - this.verifySetProfiler( - PROFILER_KEY, - PROFILER_TEST_VALUE, - PROFILER_TEST_VALUE_2); - } - - public void testAddRemoveProfiler() throws Exception { - this.verifyAddRemoveProperty( - PROFILER_KEY, - PROFILER_TEST_VALUE, - PROFILER_TEST_VALUE_2); - } - - /** - * Verifies setting custom profiler and literals. - */ - protected void verifySetProfiler(String elKey, Object testValue1, Object testValue2) throws Exception { - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdOf(property); - // test set custom profiler. - this.clearEvent(); - this.setProperty(propertyName, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // test set (Profiler) null - this.clearEvent(); - this.customization.setProfiler((Profiler) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - - // test set enum literal - this.clearEvent(); - this.setProperty(propertyName, testValue1.toString()); - assertNotNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, this.getPropertyStringValueOf(testValue1)); - - // test set (String) null - this.clearEvent(); - this.customization.setProfiler((String) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - } - - - - // ****** convenience methods ******* - - // ********** verify SessionCustomizer property ********** - protected void verifySetSessionCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Replace - this.persistenceUnitSetProperty(key, testValue2, true); - this.propertiesTotal++; - this.verifyPutSessionCustomizerProperty(propertyName, testValue1); - } - - @SuppressWarnings("unused") - protected void verifyAddRemoveSessionCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.getPersistenceUnit().removeProperty(key, (String) testValue1); - assertFalse(this.customization.sessionCustomizerExists(key)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(key, testValue1, true); - this.verifyPutSessionCustomizerProperty(propertyName, testValue1); - } - - protected void verifyPutSessionCustomizerProperty(String propertyName, Object expectedValue) throws Exception { - // verify event received - assertNotNull("No Event Fired.", this.sessionCustomizersEvent); - this.verifySessionCustomizerEvent(propertyName, expectedValue); - } - - @SuppressWarnings("unused") - protected void verifySessionCustomizerEvent(String propertyName, Object expectedValue) throws Exception { - // verify event value - EclipseLinkCustomization customization = (EclipseLinkCustomization) this.sessionCustomizersEvent.getSource(); - assertTrue(customization.sessionCustomizerExists((String) expectedValue)); - return; - } - - // ********** verify entity property ********** - protected void verifySetCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Replace - this.persistenceUnitSetProperty(key, testValue2); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, testValue2); - - // Replace by setting model object - this.clearEvent(); - this.setCustomizationProperty(propertyName, ENTITY_TEST, testValue1); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, testValue1); - } - - protected void verifyAddRemoveCustomizationProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.getPersistenceUnit().removeProperty(key); - assertNull(this.getPersistenceUnit().getProperty(key)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, null); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(key, testValue1); - this.verifyPutCustomizationProperty(propertyName, ENTITY_TEST, testValue1); - - // Replace - this.persistenceUnitSetProperty(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 - Entity entity = (Entity) this.propertyChangedEvent.getNewValue(); - if (propertyName.equals(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY)) { - assertEquals(expectedValue, entity.getParent().getDescriptorCustomizerOf(entityName)); - assertEquals(expectedValue, this.customization.getDescriptorCustomizerOf(entityName)); - } - else { - this.throwMissingDefinition("verifyCustomizationEvent", propertyName); - } - } - - protected void setCustomizationProperty(String propertyName, String entityName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY)) - this.customization.setDescriptorCustomizerOf(entityName, (String) newValue); - else - this.throwMissingDefinition("setCustomizationProperty", propertyName); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/JptEclipseLinkPersistenceCustomizationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/JptEclipseLinkPersistenceCustomizationTests.java deleted file mode 100644 index 9082c62599..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/JptEclipseLinkPersistenceCustomizationTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.customization; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkPersistenceCustomizationTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkPersistenceCustomizationTests.class.getPackage().getName()); - - suite.addTestSuite(CustomizationValueModelTests.class); - suite.addTestSuite(EclipseLinkCustomizationTests.class); - - return suite; - } - - private JptEclipseLinkPersistenceCustomizationTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesAdapterTests.java deleted file mode 100644 index 8a6d5e3bfe..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesAdapterTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2008, 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.general; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.general.GeneralProperties; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * GeneralAdapterTests - */ -@SuppressWarnings("nls") -public class GeneralPropertiesAdapterTests extends EclipseLinkPersistenceUnitTestCase -{ - private GeneralProperties generalProperties; - - public static final String EXCLUDE_ECLIPSELINK_ORM_KEY = GeneralProperties.ECLIPSELINK_EXCLUDE_ECLIPSELINK_ORM; - public static final Boolean EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE = false; - public static final Boolean EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE_2 = ! EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE; - - - public GeneralPropertiesAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.generalProperties = this.subject.getGeneralProperties(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.generalProperties.addPropertyChangeListener(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 1; - this.propertiesTotal = this.modelPropertiesSizeOriginal + 2; // misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(EXCLUDE_ECLIPSELINK_ORM_KEY, EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.2", "value.2"); - - return; - } - - - // ********** ExcludeEclipselinkOrm tests ********** - public void testSetExcludeEclipselinkOrm() throws Exception { - this.verifyModelInitialized( - EXCLUDE_ECLIPSELINK_ORM_KEY, - EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE); - this.verifySetProperty( - EXCLUDE_ECLIPSELINK_ORM_KEY, - EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE, - EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE_2); - } - - public void testAddRemoveExcludeEclipselinkOrm() throws Exception { - this.verifyAddRemoveProperty( - EXCLUDE_ECLIPSELINK_ORM_KEY, - EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE, - EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE_2); - } - - - - // ********** get/set property ********** - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY)) - modelValue = this.generalProperties.getExcludeEclipselinkOrm(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY)) - this.generalProperties.setExcludeEclipselinkOrm((Boolean) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.generalProperties; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesValueModelTests.java deleted file mode 100644 index 7bcf63098e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/GeneralPropertiesValueModelTests.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.general; - -import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.general.GeneralProperties; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * GeneralPropertyValueModelTests - */ -@SuppressWarnings("nls") -public class GeneralPropertiesValueModelTests extends EclipseLinkPersistenceUnitTestCase -{ - private GeneralProperties generalProperty; - - private WritablePropertyValueModel excludeEclipselinkOrmHolder; - private PropertyChangeListener excludeEclipselinkOrmListener; - private PropertyChangeEvent excludeEclipselinkOrmEvent; - - public static final Boolean EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE = Boolean.FALSE; - - public GeneralPropertiesValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.generalProperty = this.subject.getGeneralProperties(); // Subject - PropertyValueModel generalPropertyHolder = new SimplePropertyValueModel(this.generalProperty); - - this.excludeEclipselinkOrmHolder = this.buildExcludeEclipselinkOrmAA(generalPropertyHolder); - this.excludeEclipselinkOrmListener = this.buildExcludeEclipselinkOrmChangeListener(); - this.excludeEclipselinkOrmHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.excludeEclipselinkOrmListener); - this.excludeEclipselinkOrmEvent = null; - } - - public void testHasListeners() { - AbstractModel subjectGeneralProperty = (AbstractModel) this.generalProperty; // Subject - - PropertyAspectAdapter excludeEclipselinkOrmAA = - (PropertyAspectAdapter) this.excludeEclipselinkOrmHolder; - assertTrue(excludeEclipselinkOrmAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectGeneralProperty.hasAnyPropertyChangeListeners(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY)); - - excludeEclipselinkOrmAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.excludeEclipselinkOrmListener); - assertFalse(subjectGeneralProperty.hasAnyPropertyChangeListeners(GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY)); - assertFalse(excludeEclipselinkOrmAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.persistenceUnitSetProperty( - GeneralProperties.ECLIPSELINK_EXCLUDE_ECLIPSELINK_ORM, - EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE); - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.generalProperty; - } - - // ****** ExcludeEclipselinkOrm ******* - private WritablePropertyValueModel buildExcludeEclipselinkOrmAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(subjectHolder, GeneralProperties.EXCLUDE_ECLIPSELINK_ORM_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getExcludeEclipselinkOrm(); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setExcludeEclipselinkOrm(enumValue); - } - }; - } - - private PropertyChangeListener buildExcludeEclipselinkOrmChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - GeneralPropertiesValueModelTests.this.excludeEclipselinkOrmEvent = e; - } - }; - } - - // ****** Tests ******* - public void testValue() { - // ****** ExcludeEclipselinkOrm ******* - this.verifyExcludeEclipselinkOrmAAValue(EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE); - assertEquals(GeneralProperties.DEFAULT_EXCLUDE_ECLIPSELINK_ORM, this.generalProperty.getDefaultExcludeEclipselinkOrm()); - } - - public void testSetValue() throws Exception { - // ****** ExcludeEclipselinkOrm ******* - this.excludeEclipselinkOrmEvent = null; - this.verifyHasListeners(this.excludeEclipselinkOrmHolder, PropertyValueModel.VALUE); - Boolean newExcludeEclipselinkOrm = !EXCLUDE_ECLIPSELINK_ORM_TEST_VALUE; - // Modify the property holder - this.excludeEclipselinkOrmHolder.setValue(newExcludeEclipselinkOrm); - this.verifyExcludeEclipselinkOrmAAValue(newExcludeEclipselinkOrm); - assertNotNull(this.excludeEclipselinkOrmEvent); - } - - public void testSetNullValue() { - String notDeleted = "Property not deleted"; - // ****** ExcludeEclipselinkOrm ******* - this.excludeEclipselinkOrmEvent = null; - // Setting the property holder - this.excludeEclipselinkOrmHolder.setValue(null); - // testing Holder - this.verifyExcludeEclipselinkOrmAAValue(null); - assertNotNull(this.excludeEclipselinkOrmEvent); - // testing PU properties - this.verifyPuHasNotProperty(GeneralProperties.ECLIPSELINK_EXCLUDE_ECLIPSELINK_ORM, notDeleted); - } - - // ****** convenience methods ******* - - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyExcludeEclipselinkOrmAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.generalProperty.getExcludeEclipselinkOrm(), - this.excludeEclipselinkOrmHolder, - GeneralProperties.ECLIPSELINK_EXCLUDE_ECLIPSELINK_ORM); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/JptEclipseLinkPersistenceGeneralTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/JptEclipseLinkPersistenceGeneralTests.java deleted file mode 100644 index 2ba84831d4..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/general/JptEclipseLinkPersistenceGeneralTests.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.context.persistence.general; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkPersistenceGeneralTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkPersistenceGeneralTests.class.getPackage().getName()); - - suite.addTestSuite(GeneralPropertiesValueModelTests.class); - suite.addTestSuite(GeneralPropertiesAdapterTests.class); - - return suite; - } - - private JptEclipseLinkPersistenceGeneralTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/JptEclipseLinkPersistenceLoggingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/JptEclipseLinkPersistenceLoggingTests.java deleted file mode 100644 index 51dc7e4f3a..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/JptEclipseLinkPersistenceLoggingTests.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.context.persistence.logging; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkPersistenceLoggingTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkPersistenceLoggingTests.class.getPackage().getName()); - - suite.addTestSuite(LoggingValueModelTests.class); - suite.addTestSuite(LoggingAdapterTests.class); - - return suite; - } - - private JptEclipseLinkPersistenceLoggingTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java deleted file mode 100644 index 79b17be801..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2008, 2010 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.logging; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.logging.Logger; -import org.eclipse.jpt.eclipselink.core.context.persistence.logging.Logging; -import org.eclipse.jpt.eclipselink.core.context.persistence.logging.LoggingLevel; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * Tests the update of model objects by the Logging adapter when the - * PersistenceUnit changes. - */ -public class LoggingAdapterTests extends EclipseLinkPersistenceUnitTestCase -{ - 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.subject.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.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(TIMESTAMP_KEY, TIMESTAMP_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.2", "value.2"); - this.persistenceUnitSetProperty(LEVEL_KEY, LEVEL_TEST_VALUE); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - this.persistenceUnitSetProperty(THREAD_KEY, THREAD_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(SESSION_KEY, SESSION_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(EXCEPTIONS_KEY, EXCEPTIONS_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.4", "value.4"); - this.persistenceUnitSetProperty(LOG_FILE_LOCATION_KEY, LOG_FILE_LOCATION_TEST_VALUE); - this.persistenceUnitSetProperty(LOGGER_KEY, LOGGER_TEST_VALUE); - return; - } - - // ********** Level tests ********** - public void testSetLevel() throws Exception { - this.verifyModelInitialized( - LEVEL_KEY, - LEVEL_TEST_VALUE); - this.verifySetProperty( - LEVEL_KEY, - LEVEL_TEST_VALUE, - LEVEL_TEST_VALUE_2); - } - - public void testAddRemoveLevel() throws Exception { - this.verifyAddRemoveProperty( - LEVEL_KEY, - LEVEL_TEST_VALUE, - LEVEL_TEST_VALUE_2); - } - - // ********** Timestamp tests ********** - public void testSetTimestamp() throws Exception { - this.verifyModelInitialized( - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE); - this.verifySetProperty( - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE, - TIMESTAMP_TEST_VALUE_2); - } - - public void testAddRemoveTimestamp() throws Exception { - this.verifyAddRemoveProperty( - TIMESTAMP_KEY, - TIMESTAMP_TEST_VALUE, - TIMESTAMP_TEST_VALUE_2); - } - - // ********** Thread tests ********** - public void testSetThread() throws Exception { - this.verifyModelInitialized( - THREAD_KEY, - THREAD_TEST_VALUE); - this.verifySetProperty( - THREAD_KEY, - THREAD_TEST_VALUE, - THREAD_TEST_VALUE_2); - } - - public void testAddRemoveThread() throws Exception { - this.verifyAddRemoveProperty( - THREAD_KEY, - THREAD_TEST_VALUE, - THREAD_TEST_VALUE_2); - } - - // ********** Session tests ********** - public void testSetSession() throws Exception { - this.verifyModelInitialized( - SESSION_KEY, - SESSION_TEST_VALUE); - this.verifySetProperty( - SESSION_KEY, - SESSION_TEST_VALUE, - SESSION_TEST_VALUE_2); - } - - public void testAddRemoveSession() throws Exception { - this.verifyAddRemoveProperty( - SESSION_KEY, - SESSION_TEST_VALUE, - SESSION_TEST_VALUE_2); - } - - // ********** Exceptions tests ********** - public void testSetExceptions() throws Exception { - this.verifyModelInitialized( - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE); - this.verifySetProperty( - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE, - EXCEPTIONS_TEST_VALUE_2); - } - - public void testAddRemoveExceptions() throws Exception { - this.verifyAddRemoveProperty( - EXCEPTIONS_KEY, - EXCEPTIONS_TEST_VALUE, - EXCEPTIONS_TEST_VALUE_2); - } - - // ********** LogFileLocation ********** - public void testSetLogFileLocation() throws Exception { - this.verifyModelInitialized( - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE); - this.verifySetProperty( - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE, - LOG_FILE_LOCATION_TEST_VALUE_2); - } - - public void testAddRemoveLogFileLocation() throws Exception { - this.verifyAddRemoveProperty( - LOG_FILE_LOCATION_KEY, - LOG_FILE_LOCATION_TEST_VALUE, - LOG_FILE_LOCATION_TEST_VALUE_2); - } - - public void testSetEmptyFileLocation() throws Exception { - String puKey = LOG_FILE_LOCATION_KEY; - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(puKey); - String propertyName = this.getModel().propertyIdOf(property); - - // Set FileLocation to "" & verify that the property is deleted - this.verifyPuHasProperty(puKey, "persistenceUnit.properties doesn't contains: "); - this.setProperty(propertyName, ""); - - this.verifyPuHasNotProperty(puKey, "Property was not deleted"); - this.verifyPutProperty(propertyName, null); - assertNull(this.getPersistenceUnit().getProperty(puKey)); - } - - // ********** Logger tests ********** - public void testSetLogger() throws Exception { - this.verifyModelInitialized( - LOGGER_KEY, - this.getPropertyStringValueOf(LOGGER_TEST_VALUE)); // model is storing EclipseLinkStringValue - // verify set enum value - this.verifySetProperty( - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - // verify set custom and literal value - this.verifySetLogger( - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - } - - public void testAddRemoveLogger() throws Exception { - this.verifyAddRemoveProperty( - LOGGER_KEY, - LOGGER_TEST_VALUE, - LOGGER_TEST_VALUE_2); - } - - /** - * Verifies setting custom logger and literals. - */ - protected void verifySetLogger(String elKey, Object testValue1, Object testValue2) throws Exception { - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdOf(property); - // test set custom logger. - this.clearEvent(); - this.setProperty(propertyName, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // test set (Logger) null - this.clearEvent(); - this.logging.setLogger((Logger) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - - // test set enum literal - this.clearEvent(); - this.setProperty(propertyName, testValue1.toString()); - assertNotNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, this.getPropertyStringValueOf(testValue1)); - - // test set (String) null - this.clearEvent(); - this.logging.setLogger((String) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Logging.LEVEL_PROPERTY)) - this.logging.setLevel((LoggingLevel) newValue); - else if (propertyName.equals(Logging.TIMESTAMP_PROPERTY)) - this.logging.setTimestamp((Boolean) newValue); - else if (propertyName.equals(Logging.THREAD_PROPERTY)) - this.logging.setThread((Boolean) newValue); - else if (propertyName.equals(Logging.SESSION_PROPERTY)) - this.logging.setSession((Boolean) newValue); - else if (propertyName.equals(Logging.EXCEPTIONS_PROPERTY)) - this.logging.setExceptions((Boolean) newValue); - else if (propertyName.equals(Logging.LOG_FILE_LOCATION_PROPERTY)) - this.logging.setLogFileLocation((String) newValue); - else if (propertyName.equals(Logging.LOGGER_PROPERTY)) { - if (newValue.getClass().isEnum()) - this.logging.setLogger((Logger) newValue); - else - this.logging.setLogger((String) newValue); - } - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Logging.LEVEL_PROPERTY)) - modelValue = this.logging.getLevel(); - else if (propertyName.equals(Logging.TIMESTAMP_PROPERTY)) - modelValue = this.logging.getTimestamp(); - else if (propertyName.equals(Logging.THREAD_PROPERTY)) - modelValue = this.logging.getThread(); - else if (propertyName.equals(Logging.SESSION_PROPERTY)) - modelValue = this.logging.getSession(); - else if (propertyName.equals(Logging.EXCEPTIONS_PROPERTY)) - modelValue = this.logging.getExceptions(); - else if (propertyName.equals(Logging.LOG_FILE_LOCATION_PROPERTY)) - modelValue = this.logging.getLogFileLocation(); - else if (propertyName.equals(Logging.LOGGER_PROPERTY)) - modelValue = this.logging.getLogger(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - Object expectedValue_ = expectedValue; - if (propertyName.equals(Logging.LOGGER_PROPERTY)) { - - expectedValue_ = (expectedValue != null && expectedValue.getClass().isEnum()) ? - this.getPropertyStringValueOf(LOGGER_TEST_VALUE) : // model is storing EclipseLinkStringValue - expectedValue; - } - super.verifyPutProperty(propertyName, expectedValue_); - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.logging; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingValueModelTests.java deleted file mode 100644 index 2c8d3f1faa..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingValueModelTests.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.logging; - -import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.logging.Logging; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * LoggingValueModelTests - */ -@SuppressWarnings("nls") -public class LoggingValueModelTests extends EclipseLinkPersistenceUnitTestCase -{ - private Logging logging; - - private WritablePropertyValueModel 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.subject.getLogging(); // Subject - PropertyValueModel loggingHolder = new SimplePropertyValueModel(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 timestampAA = - (PropertyAspectAdapter) 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. - */ - @Override - protected void populatePu() { - this.persistenceUnitSetProperty( - Logging.ECLIPSELINK_TIMESTAMP, - TIMESTAMP_TEST_VALUE); - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.logging; - } - - // ****** Timestamp ******* - private WritablePropertyValueModel buildTimestampAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(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:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyTimestampAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.logging.getTimestamp(), - this.timestampHolder, - Logging.ECLIPSELINK_TIMESTAMP); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/JptEclipseLinkPersistenceOptionsTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/JptEclipseLinkPersistenceOptionsTests.java deleted file mode 100644 index 5ce21dea5e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/JptEclipseLinkPersistenceOptionsTests.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.context.persistence.options; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkPersistenceOptionsTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkPersistenceOptionsTests.class.getPackage().getName()); - - suite.addTestSuite(OptionsValueModelTests.class); - suite.addTestSuite(OptionsAdapterTests.class); - - return suite; - } - - private JptEclipseLinkPersistenceOptionsTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java deleted file mode 100644 index 388b2ce347..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java +++ /dev/null @@ -1,379 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2008, 2009 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.options; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.options.Options; -import org.eclipse.jpt.eclipselink.core.context.persistence.options.TargetDatabase; -import org.eclipse.jpt.eclipselink.core.context.persistence.options.TargetServer; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * Tests the update of model objects by the Option adapter when the - * PersistenceUnit changes. - */ -public class OptionsAdapterTests extends EclipseLinkPersistenceUnitTestCase -{ - private Options options; - - private static final String SESSION_NAME_KEY = Options.ECLIPSELINK_SESSION_NAME; - private static final String SESSION_NAME_TEST_VALUE = "session-name.test"; - private static final String SESSION_NAME_TEST_VALUE_2 = "session-name-2.test"; - - private static final String SESSIONS_XML_KEY = Options.ECLIPSELINK_SESSIONS_XML; - private static final String SESSIONS_XML_TEST_VALUE = "sessions-xml.test"; - private static final String SESSIONS_XML_TEST_VALUE_2 = "sessions-xml-2.test"; - - public static final String TARGET_DATABASE_KEY = Options.ECLIPSELINK_TARGET_DATABASE; - public static final TargetDatabase TARGET_DATABASE_TEST_VALUE = TargetDatabase.cloudscape; - public static final String TARGET_DATABASE_TEST_VALUE_2 = "custom.targetDatabase.test"; - - private static final String TARGET_SERVER_KEY = Options.ECLIPSELINK_TARGET_SERVER; - private static final TargetServer TARGET_SERVER_TEST_VALUE = TargetServer.weblogic_9; - private static final String TARGET_SERVER_TEST_VALUE_2 = "custom.targetServer.test"; - - public static final String INCLUDE_DESCRIPTOR_QUERIES_KEY = Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES; - public static final Boolean INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE = false; - public static final Boolean INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE_2 = ! INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE; - - public static final String SESSION_EVENT_LISTENER_KEY = Options.ECLIPSELINK_SESSION_EVENT_LISTENER; - public static final String SESSION_EVENT_LISTENER_TEST_VALUE = "acme.CustomSessionEventListener"; - public static final String SESSION_EVENT_LISTENER_TEST_VALUE_2 = "oracle.sessions.CustomSessionEventListener"; - - public static final String TEMPORAL_MUTABLE_KEY = Options.ECLIPSELINK_TEMPORAL_MUTABLE; - public static final Boolean TEMPORAL_MUTABLE_TEST_VALUE = true; - public static final Boolean TEMPORAL_MUTABLE_TEST_VALUE_2 = ! TEMPORAL_MUTABLE_TEST_VALUE; - - public OptionsAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.options = this.subject.getOptions(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.options.addPropertyChangeListener(Options.SESSION_NAME_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.SESSIONS_XML_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.TARGET_DATABASE_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.TARGET_SERVER_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.SESSION_EVENT_LISTENER_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener( - Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options.TEMPORAL_MUTABLE_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.persistenceUnitSetProperty(SESSION_NAME_KEY, SESSION_NAME_TEST_VALUE); - this.persistenceUnitSetProperty(SESSIONS_XML_KEY, SESSIONS_XML_TEST_VALUE); - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(INCLUDE_DESCRIPTOR_QUERIES_KEY, INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.2", "value.2"); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - this.persistenceUnitSetProperty(TARGET_DATABASE_KEY, TARGET_DATABASE_TEST_VALUE); - this.persistenceUnitSetProperty(TARGET_SERVER_KEY, TARGET_SERVER_TEST_VALUE); - this.persistenceUnitSetProperty(SESSION_EVENT_LISTENER_KEY, SESSION_EVENT_LISTENER_TEST_VALUE); - this.persistenceUnitSetProperty("misc.property.4", "value.4"); - this.persistenceUnitSetProperty(TEMPORAL_MUTABLE_KEY, TEMPORAL_MUTABLE_TEST_VALUE.toString()); - return; - } - - // ********** Listeners ********** - - // ********** SessionName tests ********** - public void testSetSessionName() throws Exception { - this.verifyModelInitialized( - SESSION_NAME_KEY, - SESSION_NAME_TEST_VALUE); - this.verifySetProperty( - SESSION_NAME_KEY, - SESSION_NAME_TEST_VALUE, - SESSION_NAME_TEST_VALUE_2); - } - - public void testAddRemoveSessionName() throws Exception { - this.verifyAddRemoveProperty( - SESSION_NAME_KEY, - SESSION_NAME_TEST_VALUE, - SESSION_NAME_TEST_VALUE_2); - } - - // ********** SessionsXml tests ********** - public void testSetSessionsXml() throws Exception { - this.verifyModelInitialized( - SESSIONS_XML_KEY, - SESSIONS_XML_TEST_VALUE); - this.verifySetProperty( - SESSIONS_XML_KEY, - SESSIONS_XML_TEST_VALUE, - SESSIONS_XML_TEST_VALUE_2); - } - - public void testAddRemoveSessionsXml() throws Exception { - this.verifyAddRemoveProperty( - SESSIONS_XML_KEY, - SESSIONS_XML_TEST_VALUE, - SESSIONS_XML_TEST_VALUE_2); - } - - // ********** IncludeDescriptorQueries tests ********** - public void testSetIncludeDescriptorQueries() throws Exception { - this.verifyModelInitialized( - INCLUDE_DESCRIPTOR_QUERIES_KEY, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE); - this.verifySetProperty( - INCLUDE_DESCRIPTOR_QUERIES_KEY, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE_2); - } - - public void testAddRemoveIncludeDescriptorQueries() throws Exception { - this.verifyAddRemoveProperty( - INCLUDE_DESCRIPTOR_QUERIES_KEY, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE_2); - } - - // ********** TargetDatabase tests ********** - public void testSetTargetDatabase() throws Exception { - this.verifyModelInitialized( - TARGET_DATABASE_KEY, - this.getPropertyStringValueOf(TARGET_DATABASE_TEST_VALUE)); // model is storing EclipseLinkStringValue - this.verifySetProperty( - TARGET_DATABASE_KEY, - TARGET_DATABASE_TEST_VALUE, - TARGET_DATABASE_TEST_VALUE_2); - // verify set custom and literal value - this.verifySetTargetDatabase( - TARGET_DATABASE_KEY, - TARGET_DATABASE_TEST_VALUE, - TARGET_DATABASE_TEST_VALUE_2); - } - - public void testAddRemoveTargetDatabase() throws Exception { - this.verifyAddRemoveProperty( - TARGET_DATABASE_KEY, - TARGET_DATABASE_TEST_VALUE, - TARGET_DATABASE_TEST_VALUE_2); - } - - /** - * Verifies setting custom targetDatabase and literals. - */ - protected void verifySetTargetDatabase(String elKey, Object testValue1, Object testValue2) throws Exception { - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdOf(property); - // test set custom targetDatabase. - this.clearEvent(); - this.setProperty(propertyName, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // test set (TargetDatabase) null - this.clearEvent(); - this.options.setTargetDatabase((TargetDatabase) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - - // test set enum literal - this.clearEvent(); - this.setProperty(propertyName, testValue1.toString()); - assertNotNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, this.getPropertyStringValueOf(testValue1)); - - // test set (String) null - this.clearEvent(); - this.options.setTargetDatabase((String) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - } - - // ********** TargetServer tests ********** - public void testSetTargetServer() throws Exception { - this.verifyModelInitialized( - TARGET_SERVER_KEY, - this.getPropertyStringValueOf(TARGET_SERVER_TEST_VALUE)); // model is storing EclipseLinkStringValue - // verify set enum value - this.verifySetProperty( - TARGET_SERVER_KEY, - TARGET_SERVER_TEST_VALUE, - TARGET_SERVER_TEST_VALUE_2); - // verify set custom and literal value - this.verifySetTargetServer( - TARGET_SERVER_KEY, - TARGET_SERVER_TEST_VALUE, - TARGET_SERVER_TEST_VALUE_2); - } - - public void testAddRemoveTargetServer() throws Exception { - this.verifyAddRemoveProperty( - TARGET_SERVER_KEY, - TARGET_SERVER_TEST_VALUE, - TARGET_SERVER_TEST_VALUE_2); - } - - /** - * Verifies setting custom targetServer and literals. - */ - protected void verifySetTargetServer(String elKey, Object testValue1, Object testValue2) throws Exception { - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdOf(property); - // test set custom targetServer. - this.clearEvent(); - this.setProperty(propertyName, testValue2); - this.verifyPutProperty(propertyName, testValue2); - - // test set (TargetServer) null - this.clearEvent(); - this.options.setTargetServer((TargetServer) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - - // test set enum literal - this.clearEvent(); - this.setProperty(propertyName, testValue1.toString()); - assertNotNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, this.getPropertyStringValueOf(testValue1)); - - // test set (String) null - this.clearEvent(); - this.options.setTargetServer((String) null); - assertNull(this.getPersistenceUnit().getProperty(elKey)); - this.verifyPutProperty(propertyName, null); - } - - // ********** EventListener tests ********** - public void testSetEventListener() throws Exception { - this.verifyModelInitialized( - SESSION_EVENT_LISTENER_KEY, - SESSION_EVENT_LISTENER_TEST_VALUE); - this.verifySetProperty( - SESSION_EVENT_LISTENER_KEY, - SESSION_EVENT_LISTENER_TEST_VALUE, - SESSION_EVENT_LISTENER_TEST_VALUE_2); - } - - public void testAddRemoveEventListener() throws Exception { - this.verifyAddRemoveProperty( - SESSION_EVENT_LISTENER_KEY, - SESSION_EVENT_LISTENER_TEST_VALUE, - SESSION_EVENT_LISTENER_TEST_VALUE_2); - } - - // ********** TemporalMutable tests ********** - public void testSetTemporalMutable() throws Exception { - this.verifyModelInitialized( - TEMPORAL_MUTABLE_KEY, - TEMPORAL_MUTABLE_TEST_VALUE); - this.verifySetProperty( - TEMPORAL_MUTABLE_KEY, - TEMPORAL_MUTABLE_TEST_VALUE, - TEMPORAL_MUTABLE_TEST_VALUE_2); - } - - public void testAddRemoveTemporalMutable() throws Exception { - this.verifyAddRemoveProperty( - TEMPORAL_MUTABLE_KEY, - TEMPORAL_MUTABLE_TEST_VALUE, - TEMPORAL_MUTABLE_TEST_VALUE_2); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Options.SESSION_NAME_PROPERTY)) - this.options.setSessionName((String) newValue); - else if (propertyName.equals(Options.SESSIONS_XML_PROPERTY)) - this.options.setSessionsXml((String) newValue); - else if (propertyName.equals(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)) - this.options.setIncludeDescriptorQueries((Boolean) newValue); - else if (propertyName.equals(Options.TARGET_DATABASE_PROPERTY)) - this.setTargetDatabaseProperty(newValue); - else if (propertyName.equals(Options.TARGET_SERVER_PROPERTY)) - this.setTargetServerProperty(newValue); - else if (propertyName.equals(Options.SESSION_EVENT_LISTENER_PROPERTY)) - this.options.setEventListener((String) newValue); - else if (propertyName.equals(Options.TEMPORAL_MUTABLE_PROPERTY)) - this.options.setTemporalMutable((Boolean) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - private void setTargetDatabaseProperty(Object newValue) { - if (newValue.getClass().isEnum()) - this.options.setTargetDatabase((TargetDatabase) newValue); - else - this.options.setTargetDatabase((String) newValue); - } - - private void setTargetServerProperty(Object newValue) { - if (newValue.getClass().isEnum()) - this.options.setTargetServer((TargetServer) newValue); - else - this.options.setTargetServer((String) newValue); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Options.SESSION_NAME_PROPERTY)) - modelValue = this.options.getSessionName(); - else if (propertyName.equals(Options.SESSIONS_XML_PROPERTY)) - modelValue = this.options.getSessionsXml(); - else if (propertyName.equals(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)) - modelValue = this.options.getIncludeDescriptorQueries(); - else if (propertyName.equals(Options.TARGET_DATABASE_PROPERTY)) - modelValue = this.options.getTargetDatabase(); - else if (propertyName.equals(Options.TARGET_SERVER_PROPERTY)) - modelValue = this.options.getTargetServer(); - else if (propertyName.equals(Options.SESSION_EVENT_LISTENER_PROPERTY)) - modelValue = this.options.getEventListener(); - else if (propertyName.equals(Options.TEMPORAL_MUTABLE_PROPERTY)) - modelValue = this.options.getTemporalMutable(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception { - Object expectedValue_ = expectedValue; - if (propertyName.equals(Options.TARGET_DATABASE_PROPERTY) || - propertyName.equals(Options.TARGET_SERVER_PROPERTY)) { - - expectedValue_ = this.convertToEclipseLinkStringValue(expectedValue); - } - - super.verifyPutProperty(propertyName, expectedValue_); - } - - private String convertToEclipseLinkStringValue(Object expectedValue) { - return (String) ((expectedValue != null && expectedValue.getClass().isEnum()) ? - this.getPropertyStringValueOf(expectedValue) : // model is storing EclipseLinkStringValue - expectedValue); // already a EclipseLinkStringValue - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.options; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsValueModelTests.java deleted file mode 100644 index a596295d91..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsValueModelTests.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.options; - -import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.options.Options; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * OptionsValueModelTests - */ -public class OptionsValueModelTests extends EclipseLinkPersistenceUnitTestCase -{ - private Options options; - - private WritablePropertyValueModel includeDescriptorQueriesHolder; - private PropertyChangeListener includeDescriptorQueriesListener; - private PropertyChangeEvent includeDescriptorQueriesEvent; - - public static final Boolean INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE = Boolean.FALSE; - - public OptionsValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.options = this.subject.getOptions(); // Subject - PropertyValueModel optionsHolder = new SimplePropertyValueModel(this.options); - - this.includeDescriptorQueriesHolder = this.buildIncludeDescriptorQueriesAA(optionsHolder); - this.includeDescriptorQueriesListener = this.buildIncludeDescriptorQueriesChangeListener(); - this.includeDescriptorQueriesHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.includeDescriptorQueriesListener); - this.includeDescriptorQueriesEvent = null; - } - - public void testHasListeners() { - AbstractModel subjectOptions = (AbstractModel) this.options; // Subject - - PropertyAspectAdapter includeDescriptorQueriesAA = - (PropertyAspectAdapter) this.includeDescriptorQueriesHolder; - assertTrue(includeDescriptorQueriesAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(subjectOptions.hasAnyPropertyChangeListeners(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)); - - includeDescriptorQueriesAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.includeDescriptorQueriesListener); - assertFalse(subjectOptions.hasAnyPropertyChangeListeners(Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY)); - assertFalse(includeDescriptorQueriesAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.persistenceUnitSetProperty( - Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES, - INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE); - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.options; - } - - // ****** IncludeDescriptorQueries ******* - private WritablePropertyValueModel buildIncludeDescriptorQueriesAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(subjectHolder, Options.SESSION_INCLUDE_DESCRIPTOR_QUERIES_PROPERTY) { - @Override - protected Boolean buildValue_() { - return this.subject.getIncludeDescriptorQueries(); - } - - @Override - protected void setValue_(Boolean enumValue) { - this.subject.setIncludeDescriptorQueries(enumValue); - } - }; - } - - private PropertyChangeListener buildIncludeDescriptorQueriesChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - OptionsValueModelTests.this.includeDescriptorQueriesEvent = e; - } - }; - } - - // ****** Tests ******* - public void testValue() { - // ****** IncludeDescriptorQueries ******* - this.verifyIncludeDescriptorQueriesAAValue(INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE); - assertEquals(Options.DEFAULT_SESSION_INCLUDE_DESCRIPTOR_QUERIES, this.options.getDefaultIncludeDescriptorQueries()); - } - - public void testSetValue() throws Exception { - // ****** IncludeDescriptorQueries ******* - this.includeDescriptorQueriesEvent = null; - this.verifyHasListeners(this.includeDescriptorQueriesHolder, PropertyValueModel.VALUE); - Boolean newIncludeDescriptorQueries = !INCLUDE_DESCRIPTOR_QUERIES_TEST_VALUE; - // Modify the property holder - this.includeDescriptorQueriesHolder.setValue(newIncludeDescriptorQueries); - this.verifyIncludeDescriptorQueriesAAValue(newIncludeDescriptorQueries); - assertNotNull(this.includeDescriptorQueriesEvent); - } - - public void testSetNullValue() { - String notDeleted = "Property not deleted"; - // ****** IncludeDescriptorQueries ******* - this.includeDescriptorQueriesEvent = null; - // Setting the property holder - this.includeDescriptorQueriesHolder.setValue(null); - // testing Holder - this.verifyIncludeDescriptorQueriesAAValue(null); - assertNotNull(this.includeDescriptorQueriesEvent); - // testing PU properties - this.verifyPuHasNotProperty(Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES, notDeleted); - } - - // ****** convenience methods ******* - - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyIncludeDescriptorQueriesAAValue(Boolean testValue) { - this.verifyAAValue( - testValue, - this.options.getIncludeDescriptorQueries(), - this.includeDescriptorQueriesHolder, - Options.ECLIPSELINK_SESSION_INCLUDE_DESCRIPTOR_QUERIES); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/JptEclipseLinkPersistenceSchemaGenerationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/JptEclipseLinkPersistenceSchemaGenerationTests.java deleted file mode 100644 index 8ae6c55d11..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/JptEclipseLinkPersistenceSchemaGenerationTests.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.context.persistence.schema.generation; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLinkPersistenceSchemaGenerationTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkPersistenceSchemaGenerationTests.class.getPackage().getName()); - - suite.addTestSuite(SchemaGenerationValueModelTests.class); - suite.addTestSuite(SchemaGenerationBasicAdapterTests.class); - suite.addTestSuite(SchemaGenerationAdapterTests.class); - - return suite; - } - - private JptEclipseLinkPersistenceSchemaGenerationTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationAdapterTests.java deleted file mode 100644 index 323df59210..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationAdapterTests.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.schema.generation; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.DdlGenerationType; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.OutputMode; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.SchemaGeneration; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * Tests the update of OutputMode model object by the SchemaGeneration adapter - * when the PersistenceUnit changes. - */ -@SuppressWarnings("nls") -public class SchemaGenerationAdapterTests extends EclipseLinkPersistenceUnitTestCase -{ - 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.subject.getSchemaGeneration(); - - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.OUTPUT_MODE_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.CREATE_FILE_NAME_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DROP_FILE_NAME_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.APPLICATION_LOCATION_PROPERTY, propertyChangeListener); - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. Cannot use - * Property Holder to initialize because it is not created yet - */ - @Override - protected void populatePu() { - this.propertiesTotal = 9; - this.modelPropertiesSizeOriginal = 5; - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitSetProperty("property.0", "value.0"); - this.persistenceUnitSetProperty(OUTPUT_MODE_KEY, this.getPropertyStringValueOf(OUTPUT_MODE_TEST_VALUE)); - this.persistenceUnitSetProperty("property.2", "value.2"); - this.persistenceUnitSetProperty("property.3", "value.3"); - this.persistenceUnitSetProperty("property.4", "value.4"); - this.persistenceUnitSetProperty(DDL_GENERATION_TYPE_KEY, this.getPropertyStringValueOf(DDL_GENERATION_TYPE_TEST_VALUE)); - this.persistenceUnitSetProperty(CREATE_FILE_NAME_KEY, CREATE_FILE_NAME_TEST_VALUE); - this.persistenceUnitSetProperty(DROP_FILE_NAME_KEY, DROP_FILE_NAME_TEST_VALUE); - this.persistenceUnitSetProperty(APPLICATION_LOCATION_KEY, APPLICATION_LOCATION_TEST_VALUE); - return; - } - - // ********** CreateFileName ********** - /** - * Tests the update of CreateFileName property by the SchemaGeneration - * adapter when the PU or the model changes. - */ - public void testSetCreateFileName() throws Exception { - this.verifyModelInitialized( - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE); - this.verifySetProperty( - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE, - CREATE_FILE_NAME_TEST_VALUE_2); - } - - public void testAddRemoveCreateFileName() throws Exception { - this.verifyAddRemoveProperty( - CREATE_FILE_NAME_KEY, - CREATE_FILE_NAME_TEST_VALUE, - CREATE_FILE_NAME_TEST_VALUE_2); - } - - // ********** DropFileName ********** - /** - * Tests the update of DropFileName property by the SchemaGeneration adapter - * when the PU or the model changes. - */ - public void testSetDropFileName() throws Exception { - this.verifyModelInitialized( - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE); - this.verifySetProperty( - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE, - DROP_FILE_NAME_TEST_VALUE_2); - } - - public void testAddRemoveDropFileName() throws Exception { - this.verifyAddRemoveProperty( - DROP_FILE_NAME_KEY, - DROP_FILE_NAME_TEST_VALUE, - DROP_FILE_NAME_TEST_VALUE_2); - } - - // ********** ApplicationLocation ********** - /** - * Tests the update of ApplicationLocation property by the SchemaGeneration - * adapter when the PU or the model changes. - */ - public void testSetApplicationLocation() throws Exception { - this.verifyModelInitialized( - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE); - this.verifySetProperty( - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE, - APPLICATION_LOCATION_TEST_VALUE_2); - } - - public void testAddRemoveApplicationLocation() throws Exception { - this.verifyAddRemoveProperty( - APPLICATION_LOCATION_KEY, - APPLICATION_LOCATION_TEST_VALUE, - APPLICATION_LOCATION_TEST_VALUE_2); - } - - public void testSetEmptyApplicationLocation() throws Exception { - String puKey = APPLICATION_LOCATION_KEY; - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(puKey); - String propertyName = this.getModel().propertyIdOf(property); - - // Set ApplicationLocation to "" & verify that the property is deleted - this.verifyPuHasProperty(puKey, "persistenceUnit.properties doesn't contains: "); - this.setProperty(propertyName, ""); - - this.verifyPuHasNotProperty(puKey, "Property was not deleted"); - this.verifyPutProperty(propertyName, null); - assertNull(this.getPersistenceUnit().getProperty(puKey)); - } - - // ********** OutputMode ********** - /** - * Tests the update of OutputMode property by the SchemaGeneration adapter - * when the PU or the model changes. - */ - public void testSetOutputMode() throws Exception { - this.verifyModelInitialized( - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE); - this.verifySetProperty( - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE, - OUTPUT_MODE_TEST_VALUE_2); - } - - public void testAddRemoveOutputMode() throws Exception { - this.verifyAddRemoveProperty( - OUTPUT_MODE_KEY, - OUTPUT_MODE_TEST_VALUE, - OUTPUT_MODE_TEST_VALUE_2); - } - - // ********** DdlGenerationType ********** - /** - * Tests the update of DdlGenerationType property by the SchemaGeneration - * adapter when the PU or the model changes. - */ - public void testSetDdlGenerationType() throws Exception { - this.verifyModelInitialized( - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE); - this.verifySetProperty( - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE, - DDL_GENERATION_TYPE_TEST_VALUE_2); - } - - public void testAddRemoveDdlGenerationType() throws Exception { - this.verifyAddRemoveProperty( - DDL_GENERATION_TYPE_KEY, - DDL_GENERATION_TYPE_TEST_VALUE, - DDL_GENERATION_TYPE_TEST_VALUE_2); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(SchemaGeneration.OUTPUT_MODE_PROPERTY)) - this.schemaGeneration.setOutputMode((OutputMode) newValue); - // else if( propertyName.equals( Caching.CACHE_SIZE_PROPERTY)) - // TODO - else if (propertyName.equals(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY)) - this.schemaGeneration.setDdlGenerationType((DdlGenerationType) newValue); - else if (propertyName.equals(SchemaGeneration.APPLICATION_LOCATION_PROPERTY)) - this.schemaGeneration.setApplicationLocation((String) newValue); - else if (propertyName.equals(SchemaGeneration.CREATE_FILE_NAME_PROPERTY)) - this.schemaGeneration.setCreateFileName((String) newValue); - else if (propertyName.equals(SchemaGeneration.DROP_FILE_NAME_PROPERTY)) - this.schemaGeneration.setDropFileName((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(SchemaGeneration.OUTPUT_MODE_PROPERTY)) - modelValue = this.schemaGeneration.getOutputMode(); - else if (propertyName.equals(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY)) - modelValue = this.schemaGeneration.getDdlGenerationType(); - else if (propertyName.equals(SchemaGeneration.APPLICATION_LOCATION_PROPERTY)) - modelValue = this.schemaGeneration.getApplicationLocation(); - else if (propertyName.equals(SchemaGeneration.CREATE_FILE_NAME_PROPERTY)) - modelValue = this.schemaGeneration.getCreateFileName(); - else if (propertyName.equals(SchemaGeneration.DROP_FILE_NAME_PROPERTY)) - modelValue = this.schemaGeneration.getDropFileName(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.schemaGeneration; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationBasicAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationBasicAdapterTests.java deleted file mode 100644 index 59e825f38e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationBasicAdapterTests.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.schema.generation; - -import java.util.ListIterator; - -import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.ListValueModel; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.DdlGenerationType; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.OutputMode; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.SchemaGeneration; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * Tests the update of OutputMode model object by the SchemaGeneration adapter - * when the PersistenceUnit changes. - */ -public class SchemaGenerationBasicAdapterTests extends EclipseLinkPersistenceUnitTestCase -{ - 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.subject.getSchemaGeneration(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.OUTPUT_MODE_PROPERTY, propertyChangeListener); - this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, propertyChangeListener); - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. Cannot use - * Property Holder to initialize because it is not created yet - */ - @Override - protected void populatePu() { - this.propertiesTotal = 6; - this.modelPropertiesSizeOriginal = 2; - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - this.persistenceUnitSetProperty("property.0", "value.0"); - this.persistenceUnitSetProperty(outputModeKey, this.getPropertyStringValueOf(OUTPUT_MODE_TEST_VALUE)); - this.persistenceUnitSetProperty("property.2", "value.2"); - this.persistenceUnitSetProperty("property.3", "value.3"); - this.persistenceUnitSetProperty("property.4", "value.4"); - this.persistenceUnitSetProperty(ddlGenTypeKey, this.getPropertyStringValueOf(DDL_GENERATION_TYPE_TEST_VALUE)); - return; - } - - /** ****** test methods ******* */ - - /** - * Tests the update of OutputMode property by the SchemaGeneration adapter - * when the PU changes. - */ - public void testOutputModeUpdate() throws Exception { - ListValueModel propertiesAdapter = this.buildPropertiesAdapter(this.subjectHolder); - ListValueModel propertyListAdapter = new ItemPropertyListValueModelAdapter(propertiesAdapter, PersistenceUnit.Property.VALUE_PROPERTY); - - this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY); - - // Basic - assertTrue(schemaGeneration.itemIsProperty(this.getPersistenceUnit().getProperty(outputModeKey))); - assertEquals(OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode()); - - // Replace - this.persistenceUnitSetProperty(outputModeKey, OUTPUT_MODE_TEST_VALUE_2); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE_2, this.schemaGeneration.getOutputMode()); - - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.getPersistenceUnit().removeProperty(outputModeKey); - assertNull(this.getPersistenceUnit().getProperty(outputModeKey)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - assertNotNull(this.propertyChangedEvent); - assertNull(this.propertyChangedEvent.getNewValue()); - - // Add original OutputMode - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(outputModeKey, OUTPUT_MODE_TEST_VALUE); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode()); - - // Replace again - this.persistenceUnitSetProperty(outputModeKey, OUTPUT_MODE_TEST_VALUE_2); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE_2, this.schemaGeneration.getOutputMode()); - - // Replace by setting model object - this.clearEvent(); - this.schemaGeneration.setOutputMode(OUTPUT_MODE_TEST_VALUE); - this.verifyPutEvent(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode()); - } - - // ****** convenience methods ******* - @Override - protected PersistenceUnitProperties getModel() { - return this.schemaGeneration; - } - - private ListValueModel buildPropertiesAdapter(PropertyValueModel subjectHolder) { - return new ListAspectAdapter(subjectHolder, PersistenceUnit.PROPERTIES_LIST) { - @Override - protected ListIterator listIterator_() { - return this.subject.properties(); - } - - @Override - protected int size_() { - return this.subject.propertiesSize(); - } - }; - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationValueModelTests.java deleted file mode 100644 index 7d9dc05000..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/schema/generation/SchemaGenerationValueModelTests.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.schema.generation; - -import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.DdlGenerationType; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.OutputMode; -import org.eclipse.jpt.eclipselink.core.context.persistence.schema.generation.SchemaGeneration; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.EclipseLinkPersistenceUnitTestCase; - -/** - * SchemaGenerationValueModelTests - * - * Tests the PropertyValueModel of SchemaGeneration model and the update of the - * PersistenceUnit. - */ -public class SchemaGenerationValueModelTests extends EclipseLinkPersistenceUnitTestCase -{ - private SchemaGeneration schemaGen; - private PropertyValueModel schemaGenHolder; - - private WritablePropertyValueModel ddlGenerationTypeHolder; - private PropertyChangeEvent ddlGenerationTypeEvent; - - private WritablePropertyValueModel 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.subject.getSchemaGeneration(); // Subject - this.schemaGenHolder = new SimplePropertyValueModel(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.persistenceUnitSetProperty( - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE, - DDL_GENERATION_TYPE_TEST_VALUE); - this.persistenceUnitSetProperty( - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE, - OUTPUT_MODE_TEST_VALUE); - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.schemaGen; - } - - /** ****** DdlGenerationType ******* */ - private WritablePropertyValueModel buildDdlGenerationTypeAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(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 buildOutputModeAA(PropertyValueModel subjectHolder) { - return new PropertyAspectAdapter(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.setProperty( - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE, - this.getPropertyStringValueOf(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.setProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE, null, false); - this.ddlGenerationTypeHolder.setValue(null); - // testing Holder - this.verifyDdlGenerationTypeAAValue(null); - assertNotNull(this.ddlGenerationTypeEvent); - // testing PU properties - PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE); - assertNull(property); - - /** ****** OutputMode ******* */ - this.outputModeEvent = null; - // Setting the property holder - this.outputModeHolder.setValue(null); - // testing Holder - this.verifyOutputModeAAValue(null); - assertNotNull(this.outputModeEvent); - // testing PU properties - property = this.getPersistenceUnit().getProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE); - assertNull(property); - } - - /** ****** convenience methods ******* */ - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyDdlGenerationTypeAAValue(DdlGenerationType testValue) { - this.verifyAAValue( - testValue, - this.schemaGen.getDdlGenerationType(), - this.ddlGenerationTypeHolder, - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE); - } - - /** - * Performs three value tests:
- * 1. subject value
- * 2. aspect adapter value
- * 3. persistenceUnit property value
- */ - protected void verifyOutputModeAAValue(OutputMode testValue) { - this.verifyAAValue( - testValue, - this.schemaGen.getOutputMode(), - this.outputModeHolder, - SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE); - } - - // ********** get/set property ********** - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/JptEclipselinkCoreResourceModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/JptEclipselinkCoreResourceModelTests.java deleted file mode 100644 index 2e8e2362cc..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/JptEclipselinkCoreResourceModelTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.eclipselink.core.tests.internal.JptEclipseLinkCoreTests; -import org.eclipse.jpt.eclipselink.core.tests.internal.resource.java.JptEclipseLinkCoreJavaResourceModelTests; - -/** - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar= - * -Dorg.eclipse.jpt.eclipselink.jar= - */ -public class JptEclipselinkCoreResourceModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipselinkCoreResourceModelTests.class.getName()); - if(JptEclipseLinkCoreTests.requiredJarsExists()) { - suite.addTest(JptEclipseLinkCoreJavaResourceModelTests.suite()); - } - else { - suite.addTest(TestSuite.warning(JptEclipseLinkCoreTests.buildMissingJarErrorMessage())); - } - return suite; - } - - private JptEclipselinkCoreResourceModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CacheTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CacheTests.java deleted file mode 100644 index d97c5c77f5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CacheTests.java +++ /dev/null @@ -1,448 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCacheAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.CacheCoordinationType; -import org.eclipse.jpt.eclipselink.core.resource.java.CacheType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkTimeOfDayAnnotation; - -@SuppressWarnings("nls") -public class CacheTests extends EclipseLinkJavaResourceModelTestCase { - - public CacheTests(String name) { - super(name); - } - - private ICompilationUnit createTestCache() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.CACHE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache"); - } - }); - } - - private ICompilationUnit createTestCacheWithCacheType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.CACHE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(type = CacheType.SOFT)"); - } - }); - } - - private ICompilationUnit createTestCacheWithSize() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(size = 50)"); - } - }); - } - - private ICompilationUnit createTestCacheWithExpiry() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiry = 50)"); - } - }); - } - - private ICompilationUnit createTestCacheWithExpiryTimeOfDay() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay)"); - } - }); - } - - private ICompilationUnit createTestCacheWithShared() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(shared=true)"); - } - }); - } - - private ICompilationUnit createTestCacheWithAlwaysRefresh() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(alwaysRefresh=true)"); - } - }); - } - - private ICompilationUnit createTestCacheWithRefreshOnlyIfNewer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(refreshOnlyIfNewer=true)"); - } - }); - } - - private ICompilationUnit createTestCacheWithDisableHits() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(disableHits=true)"); - } - }); - } - - private ICompilationUnit createTestExistenceCheckingWithCoordinationType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.CACHE_COORDINATION_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(coordinationType = CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS)"); - } - }); - } - - public void testCache() throws Exception { - ICompilationUnit cu = this.createTestCache(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertNotNull(cache); - } - - public void testGetType() throws Exception { - ICompilationUnit cu = this.createTestCacheWithCacheType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(CacheType.SOFT, cache.getType()); - } - - public void testSetType() throws Exception { - ICompilationUnit cu = this.createTestCacheWithCacheType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(CacheType.SOFT, cache.getType()); - - cache.setType(CacheType.WEAK); - assertEquals(CacheType.WEAK, cache.getType()); - - assertSourceContains("@Cache(type = WEAK)", cu); - - cache.setType(null); - assertNull(cache.getType()); - - assertSourceDoesNotContain("(type = WEAK)", cu); - assertSourceDoesNotContain("@Cache(", cu); - } - - public void testGetSize() throws Exception { - ICompilationUnit cu = this.createTestCacheWithSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Integer.valueOf(50), cache.getSize()); - } - - public void testSetSize() throws Exception { - ICompilationUnit cu = this.createTestCacheWithSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Integer.valueOf(50), cache.getSize()); - - cache.setSize(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), cache.getSize()); - - assertSourceContains("@Cache(size = 80)", cu); - - cache.setSize(null); - assertNull(cache.getSize()); - - assertSourceDoesNotContain("(size = 80)", cu); - assertSourceDoesNotContain("@Cache(", cu); - } - - public void testGetShared() throws Exception { - ICompilationUnit cu = this.createTestCacheWithShared(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getShared()); - } - - public void testSetShared() throws Exception { - ICompilationUnit cu = this.createTestCacheWithShared(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getShared()); - - cache.setShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getShared()); - - assertSourceContains("@Cache(shared=false)", cu); - } - - public void testSetSharedNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithShared(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getShared()); - - cache.setShared(null); - - assertSourceDoesNotContain("@Cache(", cu); - } - - public void testGetExpiry() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiry(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Integer.valueOf(50), cache.getExpiry()); - } - - public void testSetExpiry() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiry(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Integer.valueOf(50), cache.getExpiry()); - - cache.setExpiry(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), cache.getExpiry()); - - assertSourceContains("@Cache(expiry = 80)", cu); - - cache.setExpiry(null); - assertNull(cache.getExpiry()); - - assertSourceDoesNotContain("(expiry = 80)", cu); - assertSourceDoesNotContain("@Cache(", cu); - } - - public void testGetExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiryTimeOfDay(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertNotNull(timeOfDay); - } - - public void testAddExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestCache(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - cache.addExpiryTimeOfDay(); - - assertNotNull(cache.getExpiryTimeOfDay()); - - assertSourceContains("@Cache(expiryTimeOfDay = @TimeOfDay)", cu); - } - - public void testRemoveExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestCacheWithExpiryTimeOfDay(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - assertNotNull(cache.getExpiryTimeOfDay()); - - cache.removeExpiryTimeOfDay(); - assertNull(cache.getExpiryTimeOfDay()); - assertSourceDoesNotContain("@Cache(expiryTimeOfDay = @TimeOfDay)", cu); - } - - public void testGetAlwaysRefresh() throws Exception { - ICompilationUnit cu = this.createTestCacheWithAlwaysRefresh(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getAlwaysRefresh()); - } - - public void testSetAlwaysRefresh() throws Exception { - ICompilationUnit cu = this.createTestCacheWithAlwaysRefresh(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getAlwaysRefresh()); - - cache.setAlwaysRefresh(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getAlwaysRefresh()); - - assertSourceContains("@Cache(alwaysRefresh=false)", cu); - } - - public void testSetAlwaysRefreshNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithAlwaysRefresh(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getAlwaysRefresh()); - - cache.setAlwaysRefresh(null); - cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertNull(cache.getAlwaysRefresh()); - - assertSourceContains("@Cache", cu); - assertSourceDoesNotContain("@Cache(", cu); - } - - public void testGetRefreshOnlyIfNewer() throws Exception { - ICompilationUnit cu = this.createTestCacheWithRefreshOnlyIfNewer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getRefreshOnlyIfNewer()); - } - - public void testSetRefreshOnlyIfNewer() throws Exception { - ICompilationUnit cu = this.createTestCacheWithRefreshOnlyIfNewer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getRefreshOnlyIfNewer()); - - cache.setRefreshOnlyIfNewer(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getRefreshOnlyIfNewer()); - - assertSourceContains("@Cache(refreshOnlyIfNewer=false)", cu); - } - - public void testSetRefreshOnlyIfNewerNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithRefreshOnlyIfNewer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getRefreshOnlyIfNewer()); - - cache.setRefreshOnlyIfNewer(null); - cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertNull(cache.getRefreshOnlyIfNewer()); - assertSourceContains("@Cache", cu); - assertSourceDoesNotContain("@Cache(", cu); - } - - public void testGetDisableHits() throws Exception { - ICompilationUnit cu = this.createTestCacheWithDisableHits(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getDisableHits()); - } - - public void testSetDisableHits() throws Exception { - ICompilationUnit cu = this.createTestCacheWithDisableHits(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getDisableHits()); - - cache.setDisableHits(Boolean.FALSE); - assertEquals(Boolean.FALSE, cache.getDisableHits()); - - assertSourceContains("@Cache(disableHits=false)", cu); - } - - public void testSetDisableHitsNull() throws Exception { - ICompilationUnit cu = this.createTestCacheWithDisableHits(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(Boolean.TRUE, cache.getDisableHits()); - - cache.setDisableHits(null); - cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertNull(cache.getDisableHits()); - assertSourceContains("@Cache", cu); - assertSourceDoesNotContain("@Cache(", cu); - } - - - public void testGetCoordinationType() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithCoordinationType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cache.getCoordinationType()); - } - - public void testSetCoordinationType() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithCoordinationType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - assertEquals(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, cache.getCoordinationType()); - - cache.setCoordinationType(CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - assertEquals(CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, cache.getCoordinationType()); - - assertSourceContains("@Cache(coordinationType = SEND_NEW_OBJECTS_WITH_CHANGES)", cu); - - cache.setCoordinationType(null); - assertNull(cache.getCoordinationType()); - - assertSourceDoesNotContain("(coordinationType = SEND_NEW_OBJECTS_WITH_CHANGES)", cu); - assertSourceDoesNotContain("@Cache(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ChangeTrackingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ChangeTrackingTests.java deleted file mode 100644 index 6fd82d588c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ChangeTrackingTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkChangeTrackingAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; - -@SuppressWarnings("nls") -public class ChangeTrackingTests extends EclipseLinkJavaResourceModelTestCase { - - public ChangeTrackingTests(String name) { - super(name); - } - - private ICompilationUnit createTestChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CHANGE_TRACKING, EclipseLink.CHANGE_TRACKING_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@ChangeTracking"); - } - }); - } - - private ICompilationUnit createTestChangeTrackingWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CHANGE_TRACKING, EclipseLink.CHANGE_TRACKING_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@ChangeTracking(ChangeTrackingType.DEFERRED)"); - } - }); - } - - public void testChangeTracking() throws Exception { - ICompilationUnit cu = this.createTestChangeTracking(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkChangeTrackingAnnotation existenceChecking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLink.CHANGE_TRACKING); - assertNotNull(existenceChecking); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestChangeTrackingWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkChangeTrackingAnnotation existenceChecking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLink.CHANGE_TRACKING); - assertEquals(ChangeTrackingType.DEFERRED, existenceChecking.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestChangeTrackingWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkChangeTrackingAnnotation existenceChecking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLink.CHANGE_TRACKING); - assertEquals(ChangeTrackingType.DEFERRED, existenceChecking.getValue()); - - existenceChecking.setValue(ChangeTrackingType.ATTRIBUTE); - assertEquals(ChangeTrackingType.ATTRIBUTE, existenceChecking.getValue()); - - assertSourceContains("@ChangeTracking(ATTRIBUTE)", cu); - - existenceChecking.setValue(null); - assertNull(existenceChecking.getValue()); - - assertSourceDoesNotContain("(ATTRIBUTE)", cu); - assertSourceContains("@ChangeTracking", cu); - assertSourceDoesNotContain("@ChangeTracking(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConversionValueAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConversionValueAnnotationTests.java deleted file mode 100644 index 19b33e5af8..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConversionValueAnnotationTests.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkObjectTypeConverterAnnotation; - -@SuppressWarnings("nls") -public class ConversionValueAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ConversionValueAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestObjectTypeConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithConversionValues() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER, EclipseLink.CONVERSION_VALUE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue = \"F\", objectValue = \"Female\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})"); - } - }); - } - - - public void testGetDataValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("F", converter.conversionValueAt(0).getDataValue()); - } - - public void testSetDataValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("F", converter.conversionValueAt(0).getDataValue()); - - converter.conversionValueAt(0).setDataValue("FOO"); - assertEquals("FOO", converter.conversionValueAt(0).getDataValue()); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue = \"FOO\", objectValue = \"Female\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})", cu); - } - - public void testSetDataValueNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals(0, converter.conversionValuesSize()); - - converter.addConversionValue(0).setDataValue("FOO"); - assertSourceContains("@ObjectTypeConverter(conversionValues = @ConversionValue(dataValue = \"FOO\"))", cu); - - converter.conversionValueAt(0).setDataValue(null); - assertSourceContains("@ObjectTypeConverter(conversionValues = @ConversionValue)", cu); - assertEquals(1, converter.conversionValuesSize()); - } - - public void testGetObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Female", converter.conversionValueAt(0).getObjectValue()); - } - - public void testSetObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Female", converter.conversionValueAt(0).getObjectValue()); - - converter.conversionValueAt(0).setObjectValue("FOO"); - assertEquals("FOO", converter.conversionValueAt(0).getObjectValue()); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue = \"F\", objectValue = \"FOO\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})", cu); - } - - public void testSetObjectValueNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals(0, converter.conversionValuesSize()); - - converter.addConversionValue(0).setObjectValue("FOO"); - assertSourceContains("@ObjectTypeConverter(conversionValues = @ConversionValue(objectValue = \"FOO\"))", cu); - - converter.conversionValueAt(0).setObjectValue(null); - assertSourceContains("@ObjectTypeConverter(conversionValues = @ConversionValue)", cu); - assertEquals(1, converter.conversionValuesSize()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java deleted file mode 100644 index a89ad109d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConvertAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; - -@SuppressWarnings("nls") -public class ConvertAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ConvertAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestConvert() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CONVERT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert"); - } - }); - } - - private ICompilationUnit createTestConverterWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CONVERT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Convert(value=\"myConverter\")"); - } - }); - } - - public void testConvertAnnotation() throws Exception { - ICompilationUnit cu = this.createTestConvert(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.CONVERT)); - - attributeResource.removeAnnotation(EclipseLink.CONVERT); - assertNull(attributeResource.getAnnotation(EclipseLink.CONVERT)); - - attributeResource.addAnnotation(EclipseLink.CONVERT); - assertNotNull(attributeResource.getAnnotation(EclipseLink.CONVERT)); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestConverterWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConvertAnnotation convert = (EclipseLinkConvertAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERT); - assertEquals("myConverter", convert.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestConverterWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConvertAnnotation convert = (EclipseLinkConvertAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERT); - assertEquals("myConverter", convert.getValue()); - - convert.setValue("Bar"); - assertEquals("Bar", convert.getValue()); - - assertSourceContains("@Convert(value=\"Bar\")", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestConverterWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConvertAnnotation convert = (EclipseLinkConvertAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERT); - assertEquals("myConverter", convert.getValue()); - - convert.setValue(null); - assertNull(convert.getValue()); - - assertSourceContains("@Convert", cu); - assertSourceDoesNotContain("value", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java deleted file mode 100644 index 4cefbf691e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConverterAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; - -@SuppressWarnings("nls") -public class ConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ConverterAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Converter"); - } - }); - } - - private ICompilationUnit createTestConverterWithConverterClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Converter(converterClass=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestConverterWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Converter(name=\"bar\")"); - } - }); - } - - public void testConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.CONVERTER)); - - attributeResource.removeAnnotation(EclipseLink.CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLink.CONVERTER)); - - attributeResource.addAnnotation(EclipseLink.CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLink.CONVERTER)); - } - - public void testGetConverterClass() throws Exception { - ICompilationUnit cu = this.createTestConverterWithConverterClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConverterAnnotation converter = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERTER); - assertEquals("Foo", converter.getConverterClass()); - } - - public void testSetConverterClass() throws Exception { - ICompilationUnit cu = this.createTestConverterWithConverterClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConverterAnnotation converter = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERTER); - assertEquals("Foo", converter.getConverterClass()); - - converter.setConverterClass("Bar"); - assertEquals("Bar", converter.getConverterClass()); - - assertSourceContains("@Converter(converterClass=Bar.class)", cu); - } - - public void testSetConverterClassNull() throws Exception { - ICompilationUnit cu = this.createTestConverterWithConverterClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConverterAnnotation converter = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERTER); - assertEquals("Foo", converter.getConverterClass()); - - converter.setConverterClass(null); - assertNull(converter.getConverterClass()); - - assertSourceContains("@Converter", cu); - assertSourceDoesNotContain("converterClass", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConverterAnnotation converter = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConverterAnnotation converter = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@Converter(name=\"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkConverterAnnotation converter = (EclipseLinkConverterAnnotation) attributeResource.getAnnotation(EclipseLink.CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@Converter", cu); - assertSourceDoesNotContain("name=", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CustomizerAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CustomizerAnnotationTests.java deleted file mode 100644 index 524ec6e69d..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/CustomizerAnnotationTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCustomizerAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; - -@SuppressWarnings("nls") -public class CustomizerAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public CustomizerAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestCustomizer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Customizer"); - } - }); - } - - private ICompilationUnit createTestCustomizerWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Customizer(Foo.class)"); - } - }); - } - - public void testCustomizerAnnotation() throws Exception { - ICompilationUnit cu = this.createTestCustomizer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertNotNull(typeResource.getAnnotation(EclipseLink.CUSTOMIZER)); - - typeResource.removeAnnotation(EclipseLink.CUSTOMIZER); - assertNull(typeResource.getAnnotation(EclipseLink.CUSTOMIZER)); - - typeResource.addAnnotation(EclipseLink.CUSTOMIZER); - assertNotNull(typeResource.getAnnotation(EclipseLink.CUSTOMIZER)); - } - - public void testGetConverterClass() throws Exception { - ICompilationUnit cu = this.createTestCustomizerWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCustomizerAnnotation converter = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLink.CUSTOMIZER); - assertEquals("Foo", converter.getValue()); - } - - public void testSetConverterClass() throws Exception { - ICompilationUnit cu = this.createTestCustomizerWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCustomizerAnnotation converter = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLink.CUSTOMIZER); - assertEquals("Foo", converter.getValue()); - - converter.setValue("Bar"); - assertEquals("Bar", converter.getValue()); - - assertSourceContains("@Customizer(Bar.class)", cu); - } - - public void testSetConverterClassNull() throws Exception { - ICompilationUnit cu = this.createTestCustomizerWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCustomizerAnnotation converter = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLink.CUSTOMIZER); - assertEquals("Foo", converter.getValue()); - - converter.setValue(null); - assertNull(converter.getValue()); - - assertSourceContains("@Customizer", cu); - assertSourceDoesNotContain("Foo.class", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java deleted file mode 100644 index 57a7b1b14c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationDefinitionProvider; -import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider; -import org.eclipse.jpt.core.tests.internal.resource.java.JpaJavaResourceModelTestCase; -import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaAnnotationDefinitionProvider; - -public class EclipseLinkJavaResourceModelTestCase extends JpaJavaResourceModelTestCase -{ - - public static final String ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME = "org.eclipse.persistence.annotations"; //$NON-NLS-1$ - - public EclipseLinkJavaResourceModelTestCase(String name) { - super(name); - } - - @Override - protected JpaAnnotationProvider buildAnnotationProvider() { - return new GenericJpaAnnotationProvider( - GenericJpaAnnotationDefinitionProvider.instance(), - EclipseLinkJpaAnnotationDefinitionProvider.instance()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkPrimaryKeyAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkPrimaryKeyAnnotationTests.java deleted file mode 100644 index efd5c4b0cd..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkPrimaryKeyAnnotationTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; - -public class EclipseLinkPrimaryKeyAnnotationTests - extends EclipseLinkJavaResourceModelTestCase -{ - public EclipseLinkPrimaryKeyAnnotationTests(String name) { - super(name); - } - - - private ICompilationUnit createTestTypeWithPrimaryKeyAnnotation() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.PRIMARY_KEY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKey"); - } - }); - } - - - public void testAddRemoveAnnotation() throws Exception { - ICompilationUnit cu = this.createTestTypeWithPrimaryKeyAnnotation(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertNotNull(typeResource.getAnnotation(EclipseLink.PRIMARY_KEY)); - - typeResource.removeAnnotation(EclipseLink.PRIMARY_KEY); - assertNull(typeResource.getAnnotation(EclipseLink.PRIMARY_KEY)); - - typeResource.addAnnotation(EclipseLink.PRIMARY_KEY); - assertNotNull(typeResource.getAnnotation(EclipseLink.PRIMARY_KEY)); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ExistenceCheckingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ExistenceCheckingTests.java deleted file mode 100644 index 76b1829e7e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ExistenceCheckingTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkExistenceCheckingAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.ExistenceType; - -@SuppressWarnings("nls") -public class ExistenceCheckingTests extends EclipseLinkJavaResourceModelTestCase { - - public ExistenceCheckingTests(String name) { - super(name); - } - - private ICompilationUnit createTestExistenceChecking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.EXISTENCE_CHECKING, EclipseLink.EXISTENCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@ExistenceChecking"); - } - }); - } - - private ICompilationUnit createTestExistenceCheckingWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.EXISTENCE_CHECKING, EclipseLink.EXISTENCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@ExistenceChecking(ExistenceType.ASSUME_EXISTENCE)"); - } - }); - } - - public void testExistenceChecking() throws Exception { - ICompilationUnit cu = this.createTestExistenceChecking(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkExistenceCheckingAnnotation existenceChecking = (EclipseLinkExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLink.EXISTENCE_CHECKING); - assertNotNull(existenceChecking); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkExistenceCheckingAnnotation existenceChecking = (EclipseLinkExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLink.EXISTENCE_CHECKING); - assertEquals(ExistenceType.ASSUME_EXISTENCE, existenceChecking.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestExistenceCheckingWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkExistenceCheckingAnnotation existenceChecking = (EclipseLinkExistenceCheckingAnnotation) typeResource.getAnnotation(EclipseLink.EXISTENCE_CHECKING); - assertEquals(ExistenceType.ASSUME_EXISTENCE, existenceChecking.getValue()); - - existenceChecking.setValue(ExistenceType.ASSUME_NON_EXISTENCE); - assertEquals(ExistenceType.ASSUME_NON_EXISTENCE, existenceChecking.getValue()); - - assertSourceContains("@ExistenceChecking(ASSUME_NON_EXISTENCE)", cu); - - existenceChecking.setValue(null); - assertNull(existenceChecking.getValue()); - - assertSourceDoesNotContain("(ASSUME_NON_EXISTENCE)", cu); - assertSourceContains("@ExistenceChecking", cu); - assertSourceDoesNotContain("@ExistenceChecking(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JoinFetchTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JoinFetchTests.java deleted file mode 100644 index 39f3c1c8d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JoinFetchTests.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJoinFetchAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType; - -@SuppressWarnings("nls") -public class JoinFetchTests extends EclipseLinkJavaResourceModelTestCase { - - public JoinFetchTests(String name) { - super(name); - } - - private ICompilationUnit createTestJoinFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinFetch"); - } - }); - } - - private ICompilationUnit createTestJoinFetchWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinFetch(JoinFetchType.OUTER)"); - } - }); - } - - public void testJoinFetch() throws Exception { - ICompilationUnit cu = this.createTestJoinFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkJoinFetchAnnotation joinFetch = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLink.JOIN_FETCH); - assertNotNull(joinFetch); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestJoinFetchWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkJoinFetchAnnotation joinFetch = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLink.JOIN_FETCH); - assertEquals(JoinFetchType.OUTER, joinFetch.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestJoinFetchWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkJoinFetchAnnotation joinFetch = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLink.JOIN_FETCH); - assertEquals(JoinFetchType.OUTER, joinFetch.getValue()); - - joinFetch.setValue(JoinFetchType.INNER); - assertEquals(JoinFetchType.INNER, joinFetch.getValue()); - - assertSourceContains("@JoinFetch(INNER)", cu); - - joinFetch.setValue(null); - assertNull(joinFetch.getValue()); - - assertSourceDoesNotContain("(INNER)", cu); - assertSourceContains("@JoinFetch", cu); - assertSourceDoesNotContain("@JoinFetch(", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java deleted file mode 100644 index 439f1cadec..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptEclipseLinkCoreJavaResourceModelTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLinkCoreJavaResourceModelTests.class.getName()); - suite.addTestSuite(CacheTests.class); - suite.addTestSuite(ChangeTrackingTests.class); - suite.addTestSuite(ConversionValueAnnotationTests.class); - suite.addTestSuite(ConvertAnnotationTests.class); - suite.addTestSuite(ConverterAnnotationTests.class); - suite.addTestSuite(CustomizerAnnotationTests.class); - suite.addTestSuite(ExistenceCheckingTests.class); - suite.addTestSuite(JoinFetchTests.class); - suite.addTestSuite(MutableAnnotationTests.class); - suite.addTestSuite(ObjectTypeConverterAnnotationTests.class); - suite.addTestSuite(EclipseLinkPrimaryKeyAnnotationTests.class); - suite.addTestSuite(PrivateOwnedTests.class); - suite.addTestSuite(ReadOnlyTests.class); - suite.addTestSuite(ReadTransformerAnnotationTests.class); - suite.addTestSuite(StructConverterAnnotationTests.class); - suite.addTestSuite(TimeOfDayTests.class); - suite.addTestSuite(TransformationAnnotationTests.class); - suite.addTestSuite(TypeConverterAnnotationTests.class); - suite.addTestSuite(WriteTransformerAnnotationTests.class); - - return suite; - } - - private JptEclipseLinkCoreJavaResourceModelTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java deleted file mode 100644 index 575306967b..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/MutableAnnotationTests.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkMutableAnnotation; - -@SuppressWarnings("nls") -public class MutableAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public MutableAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestMutable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.MUTABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Mutable"); - } - }); - } - - private ICompilationUnit createTestMutableWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.MUTABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Mutable(value=true)"); - } - }); - } - - - - public void testMutableAnnotation() throws Exception { - ICompilationUnit cu = this.createTestMutable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.MUTABLE)); - - attributeResource.removeAnnotation(EclipseLink.MUTABLE); - assertNull(attributeResource.getAnnotation(EclipseLink.MUTABLE)); - - attributeResource.addAnnotation(EclipseLink.MUTABLE); - assertNotNull(attributeResource.getAnnotation(EclipseLink.MUTABLE)); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestMutableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLink.MUTABLE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestMutableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLink.MUTABLE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - - mutableAnnotation.setValue(Boolean.FALSE); - assertEquals(Boolean.FALSE, mutableAnnotation.getValue()); - - assertSourceContains("@Mutable(value=false)", cu); - - mutableAnnotation.setValue(null); - mutableAnnotation.setValue(Boolean.FALSE); - assertSourceContains("@Mutable(false)", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestMutableWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkMutableAnnotation mutableAnnotation = (EclipseLinkMutableAnnotation) attributeResource.getAnnotation(EclipseLink.MUTABLE); - assertEquals(Boolean.TRUE, mutableAnnotation.getValue()); - - mutableAnnotation.setValue(null); - assertNull(mutableAnnotation.getValue()); - - assertSourceContains("@Mutable", cu); - assertSourceDoesNotContain("value", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ObjectTypeConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ObjectTypeConverterAnnotationTests.java deleted file mode 100644 index aaa852bb7f..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ObjectTypeConverterAnnotationTests.java +++ /dev/null @@ -1,426 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkConversionValueAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkObjectTypeConverterAnnotation; - -@SuppressWarnings("nls") -public class ObjectTypeConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ObjectTypeConverterAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestObjectTypeConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithDataType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(dataType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithObjectType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(objectType=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(name = \"bar\")"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithDefaultObjectValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(defaultObjectValue = \"f\")"); - } - }); - } - - private ICompilationUnit createTestObjectTypeConverterWithConversionValues() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.OBJECT_TYPE_CONVERTER, EclipseLink.CONVERSION_VALUE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue = \"F\", objectValue = \"Female\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})"); - } - }); - } - - public void testObjectTypeConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER)); - - attributeResource.removeAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER)); - - attributeResource.addAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER)); - } - - public void testGetDataType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - } - - public void testSetDataType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - - assertSourceContains("@ObjectTypeConverter(dataType=Bar.class)", cu); - - converter.setDataType("int"); - assertEquals("int", converter.getDataType()); - assertSourceContains("@ObjectTypeConverter(dataType=int.class)", cu); - } - - public void testSetDataTypeNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType(null); - assertNull(converter.getDataType()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("dataType", cu); - } - - public void testGetObjectType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - } - - public void testSetObjectType() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - - assertSourceContains("@ObjectTypeConverter(objectType=Bar.class)", cu); - - converter.setObjectType("int"); - assertEquals("int", converter.getObjectType()); - assertSourceContains("@ObjectTypeConverter(objectType=int.class)", cu); - } - - public void testSetObjectTypeNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType(null); - assertNull(converter.getObjectType()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("objectType", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@ObjectTypeConverter(name = \"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("name=", cu); - } - - - public void testGetDefaultObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDefaultObjectValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("f", converter.getDefaultObjectValue()); - } - - public void testSetDefaultObjectValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDefaultObjectValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("f", converter.getDefaultObjectValue()); - - converter.setDefaultObjectValue("foo"); - assertEquals("foo", converter.getDefaultObjectValue()); - - assertSourceContains("@ObjectTypeConverter(defaultObjectValue = \"foo\")", cu); - } - - public void testSetDefaultObjectValueNull() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithDefaultObjectValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - assertEquals("f", converter.getDefaultObjectValue()); - - converter.setDefaultObjectValue(null); - assertNull(converter.getDefaultObjectValue()); - - assertSourceContains("@ObjectTypeConverter", cu); - assertSourceDoesNotContain("defaultObjectValue", cu); - } - - public void testConversionValues() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - - assertEquals(0, converter.conversionValuesSize()); - assertFalse(converter.conversionValues().hasNext()); - } - - public void testConversionValues2() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - - - converter.addConversionValue(0); - converter.addConversionValue(1); - - assertEquals(2, converter.conversionValuesSize()); - ListIterator conversionValues = converter.conversionValues(); - assertTrue(conversionValues.hasNext()); - assertNotNull(conversionValues.next()); - assertNotNull(conversionValues.next()); - assertFalse(conversionValues.hasNext()); - } - - public void testConversionValues3() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - - assertEquals(2, converter.conversionValuesSize()); - ListIterator conversionValues = converter.conversionValues(); - EclipseLinkConversionValueAnnotation conversionValue = conversionValues.next(); - assertEquals("F", conversionValue.getDataValue()); - assertEquals("Female", conversionValue.getObjectValue()); - conversionValue = conversionValues.next(); - assertEquals("M", conversionValue.getDataValue()); - assertEquals("Male", conversionValue.getObjectValue()); - assertFalse(conversionValues.hasNext()); - } - - public void testAddConversionValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - - converter.addConversionValue(0).setObjectValue("FOO"); - converter.addConversionValue(1); - converter.addConversionValue(0).setDataValue("BAR"); - - assertEquals("BAR", converter.conversionValueAt(0).getDataValue()); - assertNull(converter.conversionValueAt(0).getObjectValue()); - assertEquals("FOO", converter.conversionValueAt(1).getObjectValue()); - assertNull(converter.conversionValueAt(1).getDataValue()); - assertNull(converter.conversionValueAt(2).getDataValue()); - assertNull(converter.conversionValueAt(2).getObjectValue()); - - assertSourceContains("@ObjectTypeConverter(name = \"bar\", conversionValues = {@ConversionValue(dataValue = \"BAR\"),@ConversionValue(objectValue = \"FOO\"), @ConversionValue})", cu); - } - - public void testRemoveConversionValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - converter.addConversionValue(0).setObjectValue("FOO"); - - Iterator conversionValues = converter.conversionValues(); - assertEquals("FOO", conversionValues.next().getObjectValue()); - assertEquals("Female", conversionValues.next().getObjectValue()); - assertEquals("Male", conversionValues.next().getObjectValue()); - assertFalse(conversionValues.hasNext()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue = \"FOO\"), @ConversionValue(dataValue = \"F\", objectValue = \"Female\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})", cu); - - converter.removeConversionValue(1); - conversionValues = converter.conversionValues(); - assertEquals("FOO", conversionValues.next().getObjectValue()); - assertEquals("Male", conversionValues.next().getObjectValue()); - assertFalse(conversionValues.hasNext()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue = \"FOO\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})", cu); - - converter.removeConversionValue(0); - conversionValues = converter.conversionValues(); - assertEquals("Male", conversionValues.next().getObjectValue()); - assertFalse(conversionValues.hasNext()); - assertSourceContains("@ObjectTypeConverter(conversionValues = @ConversionValue(dataValue = \"M\", objectValue = \"Male\"))", cu); - - - converter.removeConversionValue(0); - assertSourceDoesNotContain("@conversionValues", cu); - assertSourceContains("@ObjectTypeConverter", cu); - } - - public void testMoveConversionValue() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - converter.addConversionValue(0).setObjectValue("FOO"); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue = \"FOO\"), @ConversionValue(dataValue = \"F\", objectValue = \"Female\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})", cu); - - converter.moveConversionValue(2, 0); - assertEquals("Female", converter.conversionValueAt(0).getObjectValue()); - assertEquals("F", converter.conversionValueAt(0).getDataValue()); - assertEquals("Male", converter.conversionValueAt(1).getObjectValue()); - assertEquals("M", converter.conversionValueAt(1).getDataValue()); - assertEquals("FOO", converter.conversionValueAt(2).getObjectValue()); - assertEquals(null, converter.conversionValueAt(2).getDataValue()); - assertEquals(3, converter.conversionValuesSize()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue = \"F\", objectValue = \"Female\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\"), @ConversionValue(objectValue = \"FOO\")})", cu); - } - - public void testMoveConversionValue2() throws Exception { - ICompilationUnit cu = this.createTestObjectTypeConverterWithConversionValues(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkObjectTypeConverterAnnotation converter = (EclipseLinkObjectTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.OBJECT_TYPE_CONVERTER); - converter.addConversionValue(0).setObjectValue("FOO"); - - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(objectValue = \"FOO\"), @ConversionValue(dataValue = \"F\", objectValue = \"Female\"), @ConversionValue(dataValue = \"M\", objectValue = \"Male\")})", cu); - - converter.moveConversionValue(0, 2); - assertEquals("Male", converter.conversionValueAt(0).getObjectValue()); - assertEquals("M", converter.conversionValueAt(0).getDataValue()); - assertEquals("FOO", converter.conversionValueAt(1).getObjectValue()); - assertEquals(null, converter.conversionValueAt(1).getDataValue()); - assertEquals("Female", converter.conversionValueAt(2).getObjectValue()); - assertEquals("F", converter.conversionValueAt(2).getDataValue()); - assertEquals(3, converter.conversionValuesSize()); - assertSourceContains("@ObjectTypeConverter(conversionValues = {@ConversionValue(dataValue = \"M\", objectValue = \"Male\"), @ConversionValue(objectValue = \"FOO\"), @ConversionValue(dataValue = \"F\", objectValue = \"Female\")})", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/PrivateOwnedTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/PrivateOwnedTests.java deleted file mode 100644 index cc0ad645c4..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/PrivateOwnedTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkPrivateOwnedAnnotation; - -@SuppressWarnings("nls") -public class PrivateOwnedTests extends EclipseLinkJavaResourceModelTestCase { - - public PrivateOwnedTests(String name) { - super(name); - } - - private ICompilationUnit createTestPrivateOwned() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.PRIVATE_OWNED); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrivateOwned"); - } - }); - } - - public void testPrivateOwned() throws Exception { - ICompilationUnit cu = this.createTestPrivateOwned(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkPrivateOwnedAnnotation privateOwned = (EclipseLinkPrivateOwnedAnnotation) attributeResource.getAnnotation(EclipseLink.PRIVATE_OWNED); - assertNotNull(privateOwned); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadOnlyTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadOnlyTests.java deleted file mode 100644 index 52819c122d..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadOnlyTests.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkReadOnlyAnnotation; - -@SuppressWarnings("nls") -public class ReadOnlyTests extends EclipseLinkJavaResourceModelTestCase { - - public ReadOnlyTests(String name) { - super(name); - } - - private ICompilationUnit createTestReadOnly() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.READ_ONLY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@ReadOnly"); - } - }); - } - - public void testReadOnly() throws Exception { - ICompilationUnit cu = this.createTestReadOnly(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkReadOnlyAnnotation readOnly = (EclipseLinkReadOnlyAnnotation) typeResource.getAnnotation(EclipseLink.READ_ONLY); - assertNotNull(readOnly); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java deleted file mode 100644 index 3310c68c4c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ReadTransformerAnnotationTests.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkReadTransformerAnnotation; - -@SuppressWarnings("nls") -public class ReadTransformerAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public ReadTransformerAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestReadTransformer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.READ_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ReadTransformer"); - } - }); - } - - private ICompilationUnit createTestReadTransformerWithTransformerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.READ_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ReadTransformer(transformerClass=Foo.class)"); - } - }); - } - - private ICompilationUnit createTestReadTransformerWithMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.READ_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ReadTransformer(method=\"transformerMethod\")"); - } - }); - } - - public void testReadTransformerAnnotation() throws Exception { - ICompilationUnit cu = this.createTestReadTransformer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER)); - - attributeResource.removeAnnotation(EclipseLink.READ_TRANSFORMER) ; - assertNull(attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER)); - - attributeResource.addAnnotation(EclipseLink.READ_TRANSFORMER); - assertNotNull(attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER)); - } - - public void testGetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkReadTransformerAnnotation readTransformer = (EclipseLinkReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER); - assertEquals("Foo", readTransformer.getTransformerClass()); - } - - public void testSetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkReadTransformerAnnotation readTransformer = (EclipseLinkReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER); - assertEquals("Foo", readTransformer.getTransformerClass()); - - readTransformer.setTransformerClass("Bar"); - assertEquals("Bar", readTransformer.getTransformerClass()); - - assertSourceContains("@ReadTransformer(transformerClass=Bar.class)", cu); - } - - public void testSetTransformerClassNull() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkReadTransformerAnnotation readTransformer = (EclipseLinkReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER); - assertEquals("Foo", readTransformer.getTransformerClass()); - - readTransformer.setTransformerClass(null); - assertNull(readTransformer.getTransformerClass()); - - assertSourceContains("@ReadTransformer", cu); - assertSourceDoesNotContain("transformerClass", cu); - } - - public void testGetMethod() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkReadTransformerAnnotation readTransformer = (EclipseLinkReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER); - assertEquals("transformerMethod", readTransformer.getMethod()); - } - - public void testSetMethod() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkReadTransformerAnnotation readTransformer = (EclipseLinkReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER); - assertEquals("transformerMethod", readTransformer.getMethod()); - - readTransformer.setMethod("foo"); - assertEquals("foo", readTransformer.getMethod()); - - assertSourceContains("@ReadTransformer(method=\"foo\")", cu); - } - - public void testSetMethodNull() throws Exception { - ICompilationUnit cu = this.createTestReadTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkReadTransformerAnnotation readTransformer = (EclipseLinkReadTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.READ_TRANSFORMER); - assertEquals("transformerMethod", readTransformer.getMethod()); - - readTransformer.setMethod(null); - assertNull(readTransformer.getMethod()); - - assertSourceContains("@ReadTransformer", cu); - assertSourceDoesNotContain("method", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java deleted file mode 100644 index a1cea4ef42..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkStructConverterAnnotation; - -@SuppressWarnings("nls") -public class StructConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public StructConverterAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestStructConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.STRUCT_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@StructConverter"); - } - }); - } - - private ICompilationUnit createTestStructConverterWithConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.STRUCT_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@StructConverter(converter=\"Foo\")"); - } - }); - } - - private ICompilationUnit createTestStructConverterWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.STRUCT_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@StructConverter(name=\"bar\")"); - } - }); - } - - public void testStructConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestStructConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER)); - - attributeResource.removeAnnotation(EclipseLink.STRUCT_CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER)); - - attributeResource.addAnnotation(EclipseLink.STRUCT_CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER)); - } - - public void testGetConverter() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkStructConverterAnnotation converter = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER); - assertEquals("Foo", converter.getConverter()); - } - - public void testSetConverter() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkStructConverterAnnotation converter = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER); - assertEquals("Foo", converter.getConverter()); - - converter.setConverter("Bar"); - assertEquals("Bar", converter.getConverter()); - - assertSourceContains("@StructConverter(converter=\"Bar\")", cu); - } - - public void testSetConverterNull() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkStructConverterAnnotation converter = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER); - assertEquals("Foo", converter.getConverter()); - - converter.setConverter(null); - assertNull(converter.getConverter()); - - assertSourceContains("@StructConverter", cu); - assertSourceDoesNotContain("converter", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkStructConverterAnnotation converter = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkStructConverterAnnotation converter = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@StructConverter(name=\"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestStructConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkStructConverterAnnotation converter = (EclipseLinkStructConverterAnnotation) attributeResource.getAnnotation(EclipseLink.STRUCT_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@StructConverter", cu); - assertSourceDoesNotContain("name=", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TimeOfDayTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TimeOfDayTests.java deleted file mode 100644 index 83088d36c1..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TimeOfDayTests.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCacheAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkTimeOfDayAnnotation; - -@SuppressWarnings("nls") -public class TimeOfDayTests extends EclipseLinkJavaResourceModelTestCase { - - public TimeOfDayTests(String name) { - super(name); - } - - private ICompilationUnit createTestTimeOfDay() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay)"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithHour() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(hour=5))"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithMinute() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(minute=5))"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithSecond() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(second=5))"); - } - }); - } - - private ICompilationUnit createTestTimeOfDayWithMillisecond() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.CACHE, EclipseLink.TIME_OF_DAY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Cache(expiryTimeOfDay = @TimeOfDay(millisecond=5))"); - } - }); - } - - public void testExpiryTimeOfDay() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDay(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - - assertNotNull(timeOfDay); - } - - public void testGetHour() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithHour(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getHour()); - } - - public void testSetHour() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithHour(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getHour()); - - timeOfDay.setHour(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getHour()); - - assertSourceContains("@TimeOfDay(hour=80)", cu); - - timeOfDay.setHour(null); - assertNull(timeOfDay.getHour()); - - assertSourceDoesNotContain("(hour=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - public void testGetMinute() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMinute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMinute()); - } - - public void testSetMinute() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMinute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMinute()); - - timeOfDay.setMinute(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getMinute()); - - assertSourceContains("@TimeOfDay(minute=80)", cu); - - timeOfDay.setMinute(null); - assertNull(timeOfDay.getMinute()); - - assertSourceDoesNotContain("(minute=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - public void testGetSecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithSecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getSecond()); - } - - public void testSetSecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithSecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getSecond()); - - timeOfDay.setSecond(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getSecond()); - - assertSourceContains("@TimeOfDay(second=80)", cu); - - timeOfDay.setSecond(null); - assertNull(timeOfDay.getSecond()); - - assertSourceDoesNotContain("(second=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - public void testGetMillisecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMillisecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMillisecond()); - } - - public void testSetMillisecond() throws Exception { - ICompilationUnit cu = this.createTestTimeOfDayWithMillisecond(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EclipseLinkCacheAnnotation cache = (EclipseLinkCacheAnnotation) typeResource.getAnnotation(EclipseLink.CACHE); - EclipseLinkTimeOfDayAnnotation timeOfDay = cache.getExpiryTimeOfDay(); - assertEquals(Integer.valueOf(5), timeOfDay.getMillisecond()); - - timeOfDay.setMillisecond(Integer.valueOf(80)); - assertEquals(Integer.valueOf(80), timeOfDay.getMillisecond()); - - assertSourceContains("@TimeOfDay(millisecond=80)", cu); - - timeOfDay.setMillisecond(null); - assertNull(timeOfDay.getMillisecond()); - - assertSourceDoesNotContain("(millisecond=80)", cu); - assertSourceContains("@TimeOfDay", cu); - } - - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java deleted file mode 100644 index e086f3ff31..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TransformationAnnotationTests.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.FetchType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkTransformationAnnotation; - -@SuppressWarnings("nls") -public class TransformationAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public TransformationAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestTransformation() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.TRANSFORMATION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transformation"); - } - }); - } - - private ICompilationUnit createTestTransformationWithOptional() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.TRANSFORMATION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transformation(optional = true)"); - } - }); - } - - private ICompilationUnit createTestTransformationWithFetch() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.TRANSFORMATION, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transformation(fetch = FetchType.EAGER)"); - } - }); - } - - public void testTransformationAnnotation() throws Exception { - ICompilationUnit cu = this.createTestTransformation(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.TRANSFORMATION)); - - attributeResource.setPrimaryAnnotation(null, EmptyIterable.instance()); - assertNull(attributeResource.getAnnotation(EclipseLink.TRANSFORMATION)); - - attributeResource.setPrimaryAnnotation(EclipseLink.TRANSFORMATION, EmptyIterable.instance()); - assertNotNull(attributeResource.getAnnotation(EclipseLink.TRANSFORMATION)); - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTransformationAnnotation transformation = (EclipseLinkTransformationAnnotation) attributeResource.getAnnotation(EclipseLink.TRANSFORMATION); - assertEquals(Boolean.TRUE, transformation.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTransformationAnnotation transformation = (EclipseLinkTransformationAnnotation) attributeResource.getAnnotation(EclipseLink.TRANSFORMATION); - assertEquals(Boolean.TRUE, transformation.getOptional()); - - transformation.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, transformation.getOptional()); - - assertSourceContains("@Transformation(optional = false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTransformationAnnotation transformation = (EclipseLinkTransformationAnnotation) attributeResource.getAnnotation(EclipseLink.TRANSFORMATION); - assertEquals(Boolean.TRUE, transformation.getOptional()); - - transformation.setOptional(null); - assertNull(transformation.getOptional()); - - assertSourceContains("@Transformation", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTransformationAnnotation transformation = (EclipseLinkTransformationAnnotation) attributeResource.getAnnotation(EclipseLink.TRANSFORMATION); - assertEquals(FetchType.EAGER, transformation.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTransformationAnnotation transformation = (EclipseLinkTransformationAnnotation) attributeResource.getAnnotation(EclipseLink.TRANSFORMATION); - assertEquals(FetchType.EAGER, transformation.getFetch()); - - transformation.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, transformation.getFetch()); - - assertSourceContains("@Transformation(fetch = LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestTransformationWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTransformationAnnotation transformation = (EclipseLinkTransformationAnnotation) attributeResource.getAnnotation(EclipseLink.TRANSFORMATION); - assertEquals(FetchType.EAGER, transformation.getFetch()); - - transformation.setFetch(null); - assertNull(transformation.getFetch()); - - assertSourceContains("@Transformation", cu); - assertSourceDoesNotContain("fetch", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java deleted file mode 100644 index 73009b29b1..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkTypeConverterAnnotation; - -@SuppressWarnings("nls") -public class TypeConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public TypeConverterAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestTypeConverter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter"); - } - }); - } - - private ICompilationUnit createTestTypeConverterWithDataType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter(dataType = Foo.class)"); - } - }); - } - - private ICompilationUnit createTestTypeConverterWithObjectType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter(objectType = Foo.class)"); - } - }); - } - - private ICompilationUnit createTestTypeConverterWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.TYPE_CONVERTER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TypeConverter(name = \"bar\")"); - } - }); - } - - public void testTypeConverterAnnotation() throws Exception { - ICompilationUnit cu = this.createTestTypeConverter(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER)); - - attributeResource.removeAnnotation(EclipseLink.TYPE_CONVERTER); - assertNull(attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER)); - - attributeResource.addAnnotation(EclipseLink.TYPE_CONVERTER); - assertNotNull(attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER)); - } - - public void testGetTypeDataType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - } - - public void testSetDataType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType("Bar"); - assertEquals("Bar", converter.getDataType()); - - assertSourceContains("@TypeConverter(dataType = Bar.class)", cu); - - converter.setDataType("int"); - assertEquals("int", converter.getDataType()); - assertSourceContains("@TypeConverter(dataType = int.class)", cu); - } - - public void testSetDataTypeNull() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithDataType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("Foo", converter.getDataType()); - - converter.setDataType(null); - assertNull(converter.getDataType()); - - assertSourceContains("@TypeConverter", cu); - assertSourceDoesNotContain("dataType", cu); - } - - public void testGetTypeObjectType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - } - - public void testSetObjectType() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType("Bar"); - assertEquals("Bar", converter.getObjectType()); - - assertSourceContains("@TypeConverter(objectType = Bar.class)", cu); - - converter.setObjectType("int"); - assertEquals("int", converter.getObjectType()); - assertSourceContains("@TypeConverter(objectType = int.class)", cu); - } - - public void testSetObjectTypeNull() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithObjectType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("Foo", converter.getObjectType()); - - converter.setObjectType(null); - assertNull(converter.getObjectType()); - - assertSourceContains("@TypeConverter", cu); - assertSourceDoesNotContain("objectType", cu); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName("foo"); - assertEquals("foo", converter.getName()); - - assertSourceContains("@TypeConverter(name = \"foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestTypeConverterWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkTypeConverterAnnotation converter = (EclipseLinkTypeConverterAnnotation) attributeResource.getAnnotation(EclipseLink.TYPE_CONVERTER); - assertEquals("bar", converter.getName()); - - converter.setName(null); - assertNull(converter.getName()); - - assertSourceContains("@TypeConverter", cu); - assertSourceDoesNotContain("name=", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java deleted file mode 100644 index c0fe34dfb5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/WriteTransformerAnnotationTests.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkWriteTransformerAnnotation; - -@SuppressWarnings("nls") -public class WriteTransformerAnnotationTests extends EclipseLinkJavaResourceModelTestCase { - - public WriteTransformerAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestWriteTransformer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.WRITE_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer"); - } - }); - } - - private ICompilationUnit createTestWriteTransformerWithTransformerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.WRITE_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer(transformerClass = Foo.class)"); - } - }); - } - - private ICompilationUnit createTestWriteTransformerWithMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.WRITE_TRANSFORMER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer(method = \"transformerMethod\")"); - } - }); - } - - private ICompilationUnit createTestWriteTransformerWithColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(EclipseLink.WRITE_TRANSFORMER, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@WriteTransformer(column = @Column(name = \"FOO\"))"); - } - }); - } - - - public void testWriteTransformerAnnotation() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformer(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER)); - - attributeResource.removeAnnotation(EclipseLink.WRITE_TRANSFORMER) ; - assertNull(attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER)); - - attributeResource.addAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertNotNull(attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER)); - } - - public void testGetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertEquals("Foo", writeTransformer.getTransformerClass()); - } - - public void testSetTransformerClass() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertEquals("Foo", writeTransformer.getTransformerClass()); - - writeTransformer.setTransformerClass("Bar"); - assertEquals("Bar", writeTransformer.getTransformerClass()); - - assertSourceContains("@WriteTransformer(transformerClass = Bar.class)", cu); - } - - public void testSetTransformerClassNull() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithTransformerClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertEquals("Foo", writeTransformer.getTransformerClass()); - - writeTransformer.setTransformerClass(null); - assertNull(writeTransformer.getTransformerClass()); - - assertSourceContains("@WriteTransformer", cu); - assertSourceDoesNotContain("transformerClass", cu); - } - - public void testGetMethod() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertEquals("transformerMethod", writeTransformer.getMethod()); - } - - public void testSetMethod() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertEquals("transformerMethod", writeTransformer.getMethod()); - - writeTransformer.setMethod("foo"); - assertEquals("foo", writeTransformer.getMethod()); - - assertSourceContains("@WriteTransformer(method = \"foo\")", cu); - } - - public void testSetMethodNull() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertEquals("transformerMethod", writeTransformer.getMethod()); - - writeTransformer.setMethod(null); - assertNull(writeTransformer.getMethod()); - - assertSourceContains("@WriteTransformer", cu); - assertSourceDoesNotContain("method", cu); - } - - - public void testGetColumn() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertNotNull(writeTransformer.getColumn()); - assertEquals("FOO", writeTransformer.getColumn().getName()); - } - - public void testAddColumn() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertNull(writeTransformer.getColumn()); - - writeTransformer.addColumn(); - - assertNotNull(writeTransformer.getColumn()); - assertSourceContains("@WriteTransformer(method = \"transformerMethod\", column = @Column)", cu); - - writeTransformer.getColumn().setName("BAR"); - assertSourceContains("@WriteTransformer(method = \"transformerMethod\", column = @Column(name = \"BAR\"))", cu); - - } - - public void testRemoveColumn() throws Exception { - ICompilationUnit cu = this.createTestWriteTransformerWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EclipseLinkWriteTransformerAnnotation writeTransformer = (EclipseLinkWriteTransformerAnnotation) attributeResource.getAnnotation(EclipseLink.WRITE_TRANSFORMER); - assertNotNull(writeTransformer.getColumn()); - assertEquals("FOO", writeTransformer.getColumn().getName()); - - writeTransformer.removeColumn(); - assertNull(writeTransformer.getColumn()); - - assertSourceContains("@WriteTransformer", cu); - assertSourceDoesNotContain("column", cu); - } - - public void getNonNullColumn() throws Exception { - - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1ContextModelTestCase.java deleted file mode 100644 index a50fbb3334..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1ContextModelTestCase.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink1_1.core.tests.internal.context; - -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.eclipselink.core.platform.EclipseLinkPlatform; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public abstract class EclipseLink1_1ContextModelTestCase extends EclipseLinkContextModelTestCase -{ - public static final String JPA_ANNOTATIONS_PACKAGE_NAME = "javax.persistence"; //$NON-NLS-1$ - - protected EclipseLink1_1ContextModelTestCase(String name) { - super(name); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(JpaFacetInstallDataModelProperties.PLATFORM, EclipseLinkPlatform.VERSION_1_1); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1JpaProjectTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1JpaProjectTests.java deleted file mode 100644 index f140464cbe..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/EclipseLink1_1JpaProjectTests.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink1_1.core.tests.internal.context; - -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; -import org.eclipse.jpt.eclipselink.core.resource.orm.v1_1.EclipseLink1_1; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class EclipseLink1_1JpaProjectTests extends EclipseLink1_1ContextModelTestCase -{ - - public EclipseLink1_1JpaProjectTests(String name) { - super(name); - } - - public void testGetDefaultOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - //add the orm.xml file with eclipselink 1.1 orm content type - createDefaultOrmXmlFileWithEclipseLink1_1ContentType(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_1_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - - //add the orm.xml file with eclipselink orm content type - createDefaultOrmXmlFileWithEclipseLinkContentType(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - - //add the orm.xml file this time with orm content type - createDefaultOrmXmlFile(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - } - - public void testGetDefaultEclipseLinkOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNull(resource); - - //add the eclipselink-orm.xml 1.1 file - createDefaultEclipseLink1_1OrmXmlFile(); - resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_1_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the eclipselink-orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNull(resource); - } - - private void createDefaultOrmXmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.getDefaultOperation().execute(null, null); - } - - private void createDefaultOrmXmlFileWithEclipseLinkContentType() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, - JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.lastSegment()); - config.getDefaultOperation().execute(null, null); - } - - private void createDefaultOrmXmlFileWithEclipseLink1_1ContentType() throws Exception { - createEclipseLink1_1OrmXmlFile(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.lastSegment()); - } - - private void createDefaultEclipseLink1_1OrmXmlFile() throws Exception { - createEclipseLink1_1OrmXmlFile(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH.lastSegment()); - } - - private void createEclipseLink1_1OrmXmlFile(String fileName) throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, fileName); - config.setProperty(JpaFileCreationDataModelProperties.VERSION, EclipseLink1_1.SCHEMA_VERSION); - config.getDefaultOperation().execute(null, null); - } - - public void testGetMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNull(resource); - - //add the eclipselink-orm.xml 1.1 file - createDefaultEclipseLink1_1OrmXmlFile(); - resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_1_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the eclipselink-orm.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNull(resource); - } - - public void testGetDifferentlyNamedMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //create the orm2.xml file - createEclipseLink1_1OrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_1_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm2.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //add the orm2.xml file back - createEclipseLink1_1OrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_1_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/JptEclipseLink1_1CoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/JptEclipseLink1_1CoreContextModelTests.java deleted file mode 100644 index f156a4abcc..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/JptEclipseLink1_1CoreContextModelTests.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.eclipselink1_1.core.tests.internal.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.eclipselink1_1.core.tests.internal.context.orm.JptEclipseLink1_1CoreOrmContextModelTests; - -public class JptEclipseLink1_1CoreContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink1_1CoreContextModelTests.class.getName()); - suite.addTestSuite(EclipseLink1_1JpaProjectTests.class); - suite.addTest(JptEclipseLink1_1CoreOrmContextModelTests.suite()); - return suite; - } - - private JptEclipseLink1_1CoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmContextModelTestCase.java deleted file mode 100644 index 33c7a42f93..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmContextModelTestCase.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink1_1.core.tests.internal.context.orm; - -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.eclipselink.core.context.orm.EclipseLinkEntityMappings; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationOperation; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.eclipselink.core.resource.orm.v1_1.EclipseLink1_1; -import org.eclipse.jpt.eclipselink1_1.core.tests.internal.context.EclipseLink1_1ContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public abstract class EclipseLink1_1OrmContextModelTestCase - extends EclipseLink1_1ContextModelTestCase -{ - protected JpaXmlResource eclipseLink1_1OrmXmlResource; - - - protected EclipseLink1_1OrmContextModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.eclipseLink1_1OrmXmlResource = getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - } - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - // don't create default orm.xml - instead build eclipselink-orm.xml - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.FALSE); - return dataModel; - } - - @Override - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) throws Exception { - TestJpaProject testJpaProject = super.buildJpaProject(projectName, autoBuild, jpaConfig); - - EclipseLinkOrmFileCreationOperation operation = - new EclipseLinkOrmFileCreationOperation(buildEclipseLinkOrmConfig(testJpaProject)); - operation.execute(null, null); - - return testJpaProject; - } - - protected IDataModel buildEclipseLinkOrmConfig(TestJpaProject testJpaProject) { - IDataModel dataModel = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - dataModel.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - testJpaProject.getProject().getFolder("src/META-INF").getFullPath()); - dataModel.setProperty(JpaFileCreationDataModelProperties.VERSION, EclipseLink1_1.SCHEMA_VERSION); - dataModel.setProperty(OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT, Boolean.TRUE); - return dataModel; - } - - @Override - protected void tearDown() throws Exception { - this.eclipseLink1_1OrmXmlResource = null; - super.tearDown(); - } - - @Override - protected JpaXmlResource getOrmXmlResource() { - return this.eclipseLink1_1OrmXmlResource; - } - - @Override - protected XmlEntityMappings getXmlEntityMappings() { - return (XmlEntityMappings) super.getXmlEntityMappings(); - } - - @Override - protected EclipseLinkEntityMappings getEntityMappings() { - return (EclipseLinkEntityMappings) super.getEntityMappings(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentAttributeTests.java deleted file mode 100644 index 144647e4f5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentAttributeTests.java +++ /dev/null @@ -1,429 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink1_1.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkIdMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToOneMapping; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class EclipseLink1_1OrmPersistentAttributeTests - extends EclipseLink1_1OrmContextModelTestCase -{ - public EclipseLink1_1OrmPersistentAttributeTests(String name) { - super(name); - } - - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - // create both orm.xml and eclipselink-orm.xml - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - private ICompilationUnit createTestTypeNullAttributeMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityIdMappingPropertyAccess() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(" private Address address;"); - } - }); - } - - public void testMakeSpecified() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeSpecifiedMappingKey() throws Exception { - createTestTypeNullAttributeMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - //take a virtual mapping with a mapping type and make it specified - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertNull(ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute.convertToSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmEclipseLinkOneToOneMapping); - - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator specifiedAttributes = ormPersistentType.specifiedAttributes(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmEclipseLinkIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(0, ormPersistentType.specifiedAttributesSize()); - - Iterator virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - - ormPersistentType.specifiedAttributes().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - assertEquals("id", ormPersistentType.virtualAttributes().next().getName()); - assertEquals("name", ormPersistentType.specifiedAttributes().next().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("id", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete2() throws Exception { - createTestEntityOneToOneMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } - - public void testGetJavaPersistentAttribute() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - //virtual orm attribute, access type matches java : FIELD, name matches java - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - JavaResourcePersistentAttribute javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isField()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableFields().next(), javaResourcePersistentAttribute); - - - //specified orm attribute, access type matches java : FIELD, name matches java - //javaPersistentAttribute should be == to java context model object - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - - - //virtual orm attribute, java access type FIELD, orm access type PROPERTY, name matches java - //verify the property java resource persistent attribute is used in orm. - ((OrmPersistentAttribute) ormPersistentAttribute).convertToVirtual(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertNotSame(ormPersistentAttribute, ormPersistentType.getAttributeNamed("id")); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isProperty()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableProperties().next(), javaResourcePersistentAttribute); - - - ormPersistentType.setSpecifiedAccess(null);//default access will be field - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - OrmPersistentAttribute ormPersistentAttribute2 = ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute2.getMapping().setName("id2"); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName(null); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName("id"); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - } - - public void testGetJavaPersistentAttributeMixedAccess() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getOwningPersistentType().getAccess()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, javaPersistentAttribute.getMappingKey()); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - - ((OrmPersistentAttribute) ormPersistentAttribute).setSpecifiedAccess(AccessType.FIELD); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - } - - public void testGetAccess() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isField()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.FIELD, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isField()); - } - - public void testGetAccessPropertyInJava() throws Exception { - createTestEntityIdMappingPropertyAccess(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); - assertTrue(ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute().isProperty()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - assertEquals(AccessType.FIELD, ormPersistentAttribute.getJavaPersistentAttribute().getAccess()); - assertEquals(AccessType.PROPERTY, javaPersistentAttribute.getAccess()); - assertTrue(javaPersistentAttribute.getResourcePersistentAttribute().isProperty()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentTypeTests.java deleted file mode 100644 index 8119a7502d..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmPersistentTypeTests.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.eclipselink1_1.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class EclipseLink1_1OrmPersistentTypeTests extends EclipseLink1_1OrmContextModelTestCase -{ - public EclipseLink1_1OrmPersistentTypeTests(String name) { - super(name); - } - - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - // create both orm.xml and eclipselink-orm.xml - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } -// -// private void createAccessTypeEnum() throws Exception { -// this.createEnumAndMembers(JPA_ANNOTATIONS_PACKAGE_NAME, "AccessType", "FIELD, PROPERTY;"); -// } -// -// private void createAccessAnnotation() throws Exception { -// this.createAnnotationAndMembers(JPA_ANNOTATIONS_PACKAGE_NAME, "Access", "AccessType value();"); -// createAccessTypeEnum(); -// } -// -// private ICompilationUnit createTestEntityAnnotatedFieldPropertySpecified() throws Exception { -// createAccessAnnotation(); -// return this.createTestType(new DefaultAnnotationWriter() { -// @Override -// public Iterator imports() { -// return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA.ACCESS, JPA.ACCESS_TYPE); -// } -// @Override -// public void appendTypeAnnotationTo(StringBuilder sb) { -// sb.append("@Entity"); -// sb.append("@Access(AccessType.PROPERTY)"); -// } -// -// @Override -// public void appendNameFieldAnnotationTo(StringBuilder sb) { -// sb.append("@Basic"); -// sb.append("@Access(AccessType.FIELD)"); -// } -// -// @Override -// public void appendGetIdMethodAnnotationTo(StringBuilder sb) { -// sb.append("@Id"); -// } -// }); -// } -// -// private ICompilationUnit createTestEntityFieldSpecifiedPropertyAnnotated() throws Exception { -// createAccessAnnotation(); -// return this.createTestType(new DefaultAnnotationWriter() { -// @Override -// public Iterator imports() { -// return new ArrayIterator(JPA.ENTITY, JPA.BASIC, JPA.ID, JPA.ACCESS, JPA.ACCESS_TYPE); -// } -// @Override -// public void appendTypeAnnotationTo(StringBuilder sb) { -// sb.append("@Entity"); -// sb.append("@Access(AccessType.FIELD)"); -// } -// -// @Override -// public void appendGetIdMethodAnnotationTo(StringBuilder sb) { -// sb.append("@Id"); -// sb.append("@Access(AccessType.PROPERTY)"); -// } -// }); -// } -// -// private ICompilationUnit createTestEntityPropertySpecified() throws Exception { -// createAccessAnnotation(); -// return this.createTestType(new DefaultAnnotationWriter() { -// @Override -// public Iterator imports() { -// return new ArrayIterator(JPA.ENTITY, JPA.ACCESS, JPA.ACCESS_TYPE); -// } -// @Override -// public void appendTypeAnnotationTo(StringBuilder sb) { -// sb.append("@Entity"); -// sb.append("@Access(AccessType.PROPERTY)"); -// } -// }); -// } - - public void testGetAccessWithJavaAnnotations() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - assertEquals(null, javaPersistentType.getSpecifiedAccess()); - - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentAttribute.convertToSpecified(); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - assertEquals(null, javaPersistentType.getSpecifiedAccess()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - -//TODO Access annotation test -// public void testGetAccessWithJavaAnnotationsProperty() throws Exception { -// createTestEntityAnnotatedFieldPropertySpecified(); -// OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); -// -// assertEquals(AccessType.PROPERTY, ormPersistentType.getAccess()); -// assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); -// assertEquals(AccessType.PROPERTY, javaPersistentType.getSpecifiedAccess()); -// -// -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); -// ormPersistentAttribute.makeSpecified(); -// assertEquals(AccessType.PROPERTY, ormPersistentType.getAccess()); -// assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); -// assertEquals(AccessType.PROPERTY, javaPersistentType.getSpecifiedAccess()); -// -// ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(AccessType.FIELD, ormPersistentType.getAccess()); -// assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); -// } -// -// public void testVirtualAttributes() throws Exception { -// createTestEntityAnnotatedFieldPropertySpecified(); -// OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// ListIterator virtualAttributes = ormPersistentType.virtualAttributes(); -// OrmPersistentAttribute ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); -// -// -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("name", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// -// ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); -// virtualAttributes = ormPersistentType.virtualAttributes(); -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("name", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// } -// -// public void testVirtualAttributes2() throws Exception { -// createTestEntityPropertySpecified(); -// OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// ListIterator virtualAttributes = ormPersistentType.virtualAttributes(); -// OrmPersistentAttribute ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// -// ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); -// virtualAttributes = ormPersistentType.virtualAttributes(); -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("name", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// -// ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); -// virtualAttributes = ormPersistentType.virtualAttributes(); -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// } -// -// public void testVirtualAttributes3() throws Exception { -// createTestEntityFieldSpecifiedPropertyAnnotated(); -// OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// ListIterator virtualAttributes = ormPersistentType.virtualAttributes(); -// OrmPersistentAttribute ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("name", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.PROPERTY, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// -// -// ormPersistentAttribute.makeSpecified(); -// -// virtualAttributes = ormPersistentType.virtualAttributes(); -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("id", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("name", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// -// -// OrmPersistentAttribute specifiedPersistentAttribute = ormPersistentType.specifiedAttributes().next(); -// assertEquals("id", specifiedPersistentAttribute.getName()); -// assertEquals(AccessType.PROPERTY, specifiedPersistentAttribute.getSpecifiedAccess()); -// -// -// ormPersistentType.virtualAttributes().next().makeSpecified(); -// virtualAttributes = ormPersistentType.virtualAttributes(); -// ormPersistentAttribute = virtualAttributes.next(); -// assertEquals("name", ormPersistentAttribute.getName()); -// assertEquals(AccessType.FIELD, ormPersistentAttribute.getAccess()); -// -// assertFalse(virtualAttributes.hasNext()); -// } -// -// public void testGetDefaultAccess() throws Exception { -// createTestEntityPropertySpecified(); -// OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); -// -// assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); -// -// javaPersistentType.setSpecifiedAccess(AccessType.FIELD); -// assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); -// -// javaPersistentType.setSpecifiedAccess(AccessType.PROPERTY); -// assertEquals(AccessType.PROPERTY, ormPersistentType.getDefaultAccess()); -// -// -// ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(AccessType.FIELD, ormPersistentType.getDefaultAccess()); -// } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmTransientMappingTests.java deleted file mode 100644 index 938630d9c5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/EclipseLink1_1OrmTransientMappingTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.eclipselink1_1.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; - -@SuppressWarnings("nls") -public class EclipseLink1_1OrmTransientMappingTests - extends EclipseLink1_1OrmContextModelTestCase -{ - public EclipseLink1_1OrmTransientMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithTransientMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.TRANSIENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient").append(CR); - } - }); - } - - public void testCreateTransientMapping() throws Exception { - createTestEntityWithTransientMapping(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertTrue(persistentAttribute.isVirtual()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - ormPersistentType.addSpecifiedAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "id"); - - persistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(persistentAttribute.isVirtual()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMapping().getKey()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/JptEclipseLink1_1CoreOrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/JptEclipseLink1_1CoreOrmContextModelTests.java deleted file mode 100644 index d1388517d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_1/core/tests/internal/context/orm/JptEclipseLink1_1CoreOrmContextModelTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.eclipselink1_1.core.tests.internal.context.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLink1_1CoreOrmContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink1_1CoreOrmContextModelTests.class.getName()); - - suite.addTestSuite(EclipseLink1_1OrmPersistentAttributeTests.class); - suite.addTestSuite(EclipseLink1_1OrmPersistentTypeTests.class); - suite.addTestSuite(EclipseLink1_1OrmTransientMappingTests.class); - - return suite; - } - - - private JptEclipseLink1_1CoreOrmContextModelTests() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2ContextModelTestCase.java deleted file mode 100644 index 303eee18dd..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2ContextModelTestCase.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink1_2.core.tests.internal.context; - -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.eclipselink.core.platform.EclipseLinkPlatform; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public abstract class EclipseLink1_2ContextModelTestCase extends EclipseLinkContextModelTestCase -{ - public static final String JPA_ANNOTATIONS_PACKAGE_NAME = "javax.persistence"; //$NON-NLS-1$ - - protected EclipseLink1_2ContextModelTestCase(String name) { - super(name); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, EclipseLinkPlatform.VERSION_1_2); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2JpaProjectTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2JpaProjectTests.java deleted file mode 100644 index d2e845cba2..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/EclipseLink1_2JpaProjectTests.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink1_2.core.tests.internal.context; - -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; -import org.eclipse.jpt.eclipselink.core.resource.orm.v1_2.EclipseLink1_2; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public class EclipseLink1_2JpaProjectTests extends EclipseLink1_2ContextModelTestCase -{ - - public EclipseLink1_2JpaProjectTests(String name) { - super(name); - } - - public void testGetDefaultOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - //add the orm.xml file with eclipselink 1.2 orm content type - createDefaultOrmXmlFileWithEclipseLink1_2ContentType(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_2_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - - //add the orm.xml file with eclipselink orm content type - createDefaultOrmXmlFileWithEclipseLinkContentType(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - - //add the orm.xml file this time with orm content type - createDefaultOrmXmlFile(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - } - - public void testGetDefaultEclipseLinkOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNull(resource); - - //add the eclipselink-orm.xml 1.2 file - createDefaultEclipseLink1_2OrmXmlFile(); - resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_2_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); - - - //delete the eclipselink-orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - assertNull(resource); - } - - private void createDefaultOrmXmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.getDefaultOperation().execute(null, null); - } - - private void createDefaultOrmXmlFileWithEclipseLinkContentType() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, - JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.lastSegment()); - config.getDefaultOperation().execute(null, null); - } - - private void createDefaultOrmXmlFileWithEclipseLink1_2ContentType() throws Exception { - createEclipseLink1_2OrmXmlFile(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.lastSegment()); - } - - private void createDefaultEclipseLink1_2OrmXmlFile() throws Exception { - createEclipseLink1_2OrmXmlFile(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH.lastSegment()); - } - - private void createEclipseLink1_2OrmXmlFile(String fileName) throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - config.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - getJpaProject().getProject().getFolder("src/META-INF").getFullPath()); - config.setProperty(JptFileCreationDataModelProperties.FILE_NAME, fileName); - config.setProperty(JpaFileCreationDataModelProperties.VERSION, EclipseLink1_2.SCHEMA_VERSION); - config.getDefaultOperation().execute(null, null); - } - - public void testGetMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNull(resource); - - //add the eclipselink-orm.xml 1.2 file - createDefaultEclipseLink1_2OrmXmlFile(); - resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_2_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the eclipselink-orm.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH); - assertNull(resource); - } - - public void testGetDifferentlyNamedMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //create the orm2.xml file - createEclipseLink1_2OrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_2_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm2.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNull(resource); - - //add the orm2.xml file back - createEclipseLink1_2OrmXmlFile("orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource(new Path("META-INF/orm2.xml")); - assertNotNull(resource); - assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_2_RESOURCE_TYPE, resource.getResourceType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/JptEclipseLink1_2CoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/JptEclipseLink1_2CoreContextModelTests.java deleted file mode 100644 index b5e46ef8fa..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink1_2/core/tests/internal/context/JptEclipseLink1_2CoreContextModelTests.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.eclipselink1_2.core.tests.internal.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLink1_2CoreContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink1_2CoreContextModelTests.class.getName()); - suite.addTestSuite(EclipseLink1_2JpaProjectTests.class); - // suite.addTest(JptEclipseLink1_2CoreOrmContextModelTests.suite()); - return suite; - } - - private JptEclipseLink1_2CoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/EclipseLink2_0ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/EclipseLink2_0ContextModelTestCase.java deleted file mode 100644 index c2e7b60bda..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/EclipseLink2_0ContextModelTestCase.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context; - -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.eclipselink.core.platform.EclipseLinkPlatform; -import org.eclipse.jpt.eclipselink.core.tests.internal.context.EclipseLinkContextModelTestCase; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public abstract class EclipseLink2_0ContextModelTestCase extends EclipseLinkContextModelTestCase -{ - protected EclipseLink2_0ContextModelTestCase(String name) { - super(name); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_2_0.getVersionString()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, EclipseLinkPlatform.VERSION_2_0); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/JptEclipseLink2_0CoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/JptEclipseLink2_0CoreContextModelTests.java deleted file mode 100644 index df6e40ecf5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/JptEclipseLink2_0CoreContextModelTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 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.eclipselink2_0.core.tests.internal.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.java.JptEclipseLink2_0JavaContextModelTests; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm.JptEclipseLink2_0OrmContextModelTests; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.persistence.JptEclipseLink2_0CorePersistenceContextModelTests; - -/** - * JptEclipseLink2_0CoreContextModelTests - */ -public class JptEclipseLink2_0CoreContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink2_0CoreContextModelTests.class.getName()); - - suite.addTest(JptEclipseLink2_0CorePersistenceContextModelTests.suite()); - suite.addTest(JptEclipseLink2_0JavaContextModelTests.suite()); - suite.addTest(JptEclipseLink2_0OrmContextModelTests.suite()); - - return suite; - } - - private JptEclipseLink2_0CoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaCollectionTableTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaCollectionTableTests.java deleted file mode 100644 index 0d5c079fa5..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaCollectionTableTests.java +++ /dev/null @@ -1,723 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.jpa2.context.CollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaCollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.CollectionTable2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLink2_0JavaCollectionTableTests extends EclipseLink2_0ContextModelTestCase -{ - public EclipseLink2_0JavaCollectionTableTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - sb.append(" private Collection projects;").append(CR); - } - }); - } - - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable); - - - //set name in the resource model, verify context model updated - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedName()); - assertEquals("FOO", resourceCollectionTable.getName()); - - //set name to null in the resource model - resourceCollectionTable.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable.getName()); - - resourceCollectionTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedName()); - assertEquals("FOO", resourceCollectionTable.getName()); - - attributeResource.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable3 = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedName()); - assertNull(resourceCollectionTable3); - - //set name in the context model, verify resource model modified - collectionTable.setSpecifiedName("foo"); - resourceCollectionTable3 = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedName()); - assertEquals("foo", resourceCollectionTable3.getName()); - - //set name to null in the context model - collectionTable.setSpecifiedName(null); - assertNull(collectionTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultName() throws Exception { - createTestEntityWithValidElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - - //add the collection table annotation, verify default collection table name is the same - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); - assertNotNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - - //set the entity name, verify default collection table name updates - getJavaEntity().setSpecifiedName("Foo"); - assertEquals("Foo_projects", collectionTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable); - - - //set schema in the resource model, verify context model updated - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceCollectionTable.getSchema()); - - //set schema to null in the resource model - resourceCollectionTable.setSchema(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable.getSchema()); - - resourceCollectionTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceCollectionTable.getSchema()); - - attributeResource.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedSchema() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(resourceCollectionTable); - - //set schema in the context model, verify resource model modified - collectionTable.setSpecifiedSchema("foo"); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedSchema()); - assertEquals("foo", resourceCollectionTable.getSchema()); - - //set schema to null in the context model - collectionTable.setSpecifiedSchema(null); - assertNull(collectionTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable); - - - //set catalog in the resource model, verify context model updated - attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - resourceCollectionTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceCollectionTable.getCatalog()); - - //set catalog to null in the resource model - resourceCollectionTable.setCatalog(null); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable.getCatalog()); - - resourceCollectionTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", collectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceCollectionTable.getCatalog()); - - attributeResource.removeAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedCatalog() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(resourceCollectionTable); - - //set catalog in the context model, verify resource model modified - collectionTable.setSpecifiedCatalog("foo"); - resourceCollectionTable = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals("foo", collectionTable.getSpecifiedCatalog()); - assertEquals("foo", resourceCollectionTable.getCatalog()); - - //set catalog to null in the context model - collectionTable.setSpecifiedCatalog(null); - assertNull(collectionTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME)); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JoinColumn joinColumn = collectionTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = collectionTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = collectionTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - ListIterator joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.joinColumnsSize()); - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.joinColumnsSize()); - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - - collectionTable.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - - collectionTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - CollectionTable2_0Annotation joinTableResource = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - joinTableResource.addJoinColumn(0); - joinTableResource.addJoinColumn(1); - joinTableResource.addJoinColumn(2); - - joinTableResource.joinColumnAt(0).setName("FOO"); - joinTableResource.joinColumnAt(1).setName("BAR"); - joinTableResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = collectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(collectionTable.specifiedJoinColumns().hasNext()); - } - - public void testGetDefaultJoinColumn() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(0, collectionTable.specifiedJoinColumnsSize()); - - collectionTable.addSpecifiedJoinColumn(0); - assertEquals(1, collectionTable.specifiedJoinColumnsSize()); - - collectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, collectionTable.specifiedJoinColumnsSize()); - } - - public void testUniqueConstraints() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - ListIterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = collectionTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - - assertEquals(0, collectionTable.uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - - assertEquals(2, collectionTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - ListIterator uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - ListIterator uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - collectionTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - collectionTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - collectionTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - collectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.getAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - - collectionTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - collectionTable.moveUniqueConstraint(0, 1); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithElementCollection(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - CollectionTable2_0Annotation joinTableAnnotation = (CollectionTable2_0Annotation) attributeResource.addAnnotation(CollectionTable2_0Annotation.ANNOTATION_NAME); - - joinTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - joinTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - - ListIterator uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = collectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaElementCollectionMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaElementCollectionMappingTests.java deleted file mode 100644 index 463d41d29f..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaElementCollectionMappingTests.java +++ /dev/null @@ -1,2076 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.ElementCollection2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLink2_0JavaElementCollectionMappingTests - extends EclipseLink2_0ContextModelTestCase -{ - public static final String EMBEDDABLE_TYPE_NAME = "Address"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericEmbeddableElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericBasicElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithNonGenericElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddablePropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - private void createSelfReferentialElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.List elementCollection;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public EclipseLink2_0JavaElementCollectionMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - - persistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollectionAnnotation = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollectionAnnotation.getTargetClass()); - - //set target class in the resource model, verify context model updated - elementCollectionAnnotation.setTargetClass("newTargetClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("newTargetClass", elementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollectionAnnotation.getTargetClass()); - - //set target class to null in the resource model - elementCollectionAnnotation.setTargetClass(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollectionAnnotation.getTargetClass()); - } - - public void testModifySpecifiedTargetClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedTargetClass("newTargetClass"); - assertEquals("newTargetClass", elementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the context model - elementCollectionMapping.setSpecifiedTargetClass(null); - assertNull(elementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - public void testDefaultTargetClass() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Embeddable, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassNonGenericCollection() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassGenericCollection() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassNonGenericMap() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultTargetClass()); - } - - public void testDefaultTargetClassGenericMap() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getDefaultTargetClass()); - } - - public void testTargetClass() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getTargetClass()); - - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertEquals("foo", elementCollectionMapping.getTargetClass()); - - elementCollectionMapping.setSpecifiedTargetClass(null); - assertEquals(PACKAGE_NAME + ".Address", elementCollectionMapping.getTargetClass()); - } - - protected Embeddable getResolvedTargetEmbeddable(ElementCollectionMapping2_0 mapping) { - return (Embeddable) ReflectionTools.executeMethod(mapping, "getResolvedTargetEmbeddable"); - } - - public void testResolvedTargetEmbeddable() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //target embeddable not in the persistence unit - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - //add target embeddable to the persistence unit, now target embeddable should resolve - createTestTargetEmbeddableAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedTargetClass("foo"); - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - - elementCollectionMapping.setSpecifiedTargetClass(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - - - elementCollectionMapping.setSpecifiedTargetClass(null); - assertEquals(addressTypeMapping, this.getResolvedTargetEmbeddable(elementCollectionMapping)); - } - - public void testResolvedTargetEmbeddableWithBasicType() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - //target is a basic type, so resolved target embeddable is null - assertNull(this.getResolvedTargetEmbeddable(elementCollectionMapping)); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the resource model, verify context model updated - elementCollection.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - - assertEquals(FetchType.EAGER, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - - assertEquals(FetchType.LAZY, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the resource model - elementCollection.setFetch(null); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) attributeResource.getAnnotation(ElementCollection2_0Annotation.ANNOTATION_NAME); - - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, elementCollection.getFetch()); - - elementCollectionMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, elementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the context model - elementCollectionMapping.setSpecifiedFetch(null); - assertNull(elementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testGetValueTypeEmbeddable() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeNone() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.NO_TYPE, elementCollectionMapping.getValueType()); - - elementCollectionMapping.setSpecifiedTargetClass("Address"); - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeBasic() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKey", elementCollectionMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", elementCollectionMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKeyAnnotation.getName()); - - //set mapKey to null in the context model - elementCollectionMapping.setSpecifiedMapKey(null); - assertNull(elementCollectionMapping.getSpecifiedMapKey()); - mapKeyAnnotation = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKeyAnnotation.getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping2_0 = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Iterator mapKeyNames = - elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping2_0 = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Iterator mapKeyNames = elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - elementCollectionMapping2_0.setSpecifiedTargetClass("Address"); - mapKeyNames = elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - elementCollectionMapping2_0.setSpecifiedTargetClass("String"); - mapKeyNames = elementCollectionMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClassAnnotation = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClassAnnotation); - - //set mapKey name in the resource model, verify context model updated - mapKeyClassAnnotation.setValue("myMapKeyClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("myMapKeyClass", elementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClassAnnotation.getValue()); - - //set mapKey name to null in the resource model - mapKeyClassAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClassAnnotation.getValue()); - - mapKeyClassAnnotation.setValue("myMapKeyClass"); - attributeResource.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - elementCollectionMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", elementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - elementCollectionMapping.setSpecifiedMapKeyClass(null); - assertNull(elementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", elementCollectionMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - elementCollectionMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", elementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", elementCollectionMapping.getMapKeyClass()); - - elementCollectionMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", elementCollectionMapping.getMapKeyClass()); - - elementCollectionMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", elementCollectionMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) elementCollectionMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - } - - public void testGetValueColumn() throws Exception { - createTestEntityWithElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getValueColumn().getSpecifiedName()); - assertEquals("id", elementCollectionMapping.getValueColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", elementCollectionMapping.getValueColumn().getSpecifiedName()); - assertEquals("foo", elementCollectionMapping.getValueColumn().getName()); - assertEquals("id", elementCollectionMapping.getValueColumn().getDefaultName()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("addresses", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_addresses", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("addresses", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_addresses", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(6, attributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(6, attributeOverrideContainer.overridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state.name"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualOverrides().next().getName()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - - attributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = (Iterator) attributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.name", virtualAttributeOverrides.next().getName()); - assertEquals("state.abbr", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityWithGenericEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType persistentType = specifiedClassRefs.next().getJavaPersistentType(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentType.getAttributeNamed("addresses").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - ReadOnlyAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - assertEquals(false, virtualAttributeOverrides.hasNext()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("state").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualOverridesSize()); - virtualAttributeOverrides = (ListIterator) nestedAttributeOverrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("abbr", virtualAttributeOverride.getName()); - - PersistentType statePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping abbrMapping = (BasicMapping) statePersistentType.getAttributeNamed("abbr").getMapping(); - abbrMapping.getColumn().setSpecifiedName("BLAH"); - abbrMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - abbrMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - abbrMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - abbrMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - abbrMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - abbrMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - abbrMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.state) attribute override to verify it is getting settings from the specified column on State.abbr - virtualAttributeOverride = ((EmbeddedMapping) addressPersistentType.getAttributeNamed("state").getMapping()).getAttributeOverrideContainer().getOverrideNamed("abbr"); - assertEquals("abbr", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - } - - public void testGetMapKeyColumn() throws Exception { - createTestEntityWithValidGenericMapElementCollectionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) persistentAttribute.getMapping(); - - assertNull(elementCollectionMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", elementCollectionMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_addresses", elementCollectionMapping.getMapKeyColumn().getTable());//collection table name - - elementCollectionMapping.getCollectionTable().setSpecifiedName("MY_COLLECTION_TABLE"); - assertEquals("MY_COLLECTION_TABLE", elementCollectionMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", elementCollectionMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", elementCollectionMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", elementCollectionMapping.getMapKeyColumn().getDefaultName()); - } - - public void testMapKeyValueSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - ListIterator specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - - - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("parcelNumber", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - classRefs.next(); - Embeddable propertyInfoEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping parcelNumberMapping = (BasicMapping) propertyInfoEmbeddable.getPersistentType().getAttributeNamed("parcelNumber").getMapping(); - parcelNumberMapping.getColumn().setSpecifiedName("FOO1"); - parcelNumberMapping.getColumn().setSpecifiedTable("BAR1"); - parcelNumberMapping.getColumn().setColumnDefinition("COLUMN_DEF1"); - parcelNumberMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - parcelNumberMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - parcelNumberMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - parcelNumberMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - parcelNumberMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("FOO1", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR1", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF1", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - parcelNumberMapping.getColumn().setSpecifiedName(null); - parcelNumberMapping.getColumn().setSpecifiedTable(null); - parcelNumberMapping.getColumn().setColumnDefinition(null); - parcelNumberMapping.getColumn().setSpecifiedInsertable(null); - parcelNumberMapping.getColumn().setSpecifiedUpdatable(null); - parcelNumberMapping.getColumn().setSpecifiedUnique(null); - parcelNumberMapping.getColumn().setSpecifiedNullable(null); - parcelNumberMapping.getColumn().setSpecifiedLength(null); - parcelNumberMapping.getColumn().setSpecifiedPrecision(null); - parcelNumberMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualOverrides().next(); - assertEquals("parcelNumber", defaultAttributeOverride.getName()); - assertEquals("parcelNumber", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_parcels", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("value.parcelNumber"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, attributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, valueAttributeOverrideContainer.specifiedOverridesSize()); - assertEquals(0, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, valueAttributeOverrideContainer.specifiedOverridesSize()); - assertEquals(1, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.overridesSize()); - assertEquals(3, valueAttributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(5, mapKeyAttributeOverrideContainer.overridesSize()); - assertEquals(5, valueAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, mapKeyAttributeOverrideContainer.overridesSize()); - assertEquals(6, valueAttributeOverrideContainer.overridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(3, valueAttributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(3, valueAttributeOverrideContainer.virtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.city"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.parcelNumber"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(2, valueAttributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.name"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, valueAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - valueAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - valueAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("value.size", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - valueAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("value.size", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("parcelNumber", valueAttributeOverrideContainer.virtualOverrides().next().getName()); - assertEquals(2, valueAttributeOverrideContainer.virtualOverridesSize()); - assertEquals("city", mapKeyAttributeOverrideContainer.virtualOverrides().next().getName()); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - valueAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = (ListIterator) valueAttributeOverrideContainer.virtualOverrides(); - assertEquals("parcelNumber", virtualAttributeOverrides.next().getName()); - assertEquals("size", virtualAttributeOverrides.next().getName()); - assertEquals("tax", virtualAttributeOverrides.next().getName()); - assertEquals(3, valueAttributeOverrideContainer.virtualOverridesSize()); - - virtualAttributeOverrides = (ListIterator) mapKeyAttributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.name", virtualAttributeOverrides.next().getName()); - assertEquals("state.abbr", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyAndValueElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - createTestEmbeddablePropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - AttributeOverrideContainer valueAttributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - AttributeOverrideContainer mapKeyAttributeOverrideContainer = elementCollectionMapping.getMapKeyAttributeOverrideContainer(); - valueAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - valueAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - ListIterator specifiedOverrides = (ListIterator) valueAttributeOverrideContainer.specifiedOverrides(); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertEquals("size", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = (ListIterator) mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("value.size", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = (ListIterator) valueAttributeOverrideContainer.specifiedOverrides(); - assertEquals("size", specifiedOverrides.next().getName()); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = (ListIterator) mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - - attributeResource.moveAnnotation(3, 2, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("value.size", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("value.parcelNumber", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = (ListIterator) valueAttributeOverrideContainer.specifiedOverrides(); - assertEquals("size", specifiedOverrides.next().getName()); - assertEquals("parcelNumber", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - specifiedOverrides = (ListIterator) mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("state.name", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } - - public void testSelfReferentialElementCollection() throws Exception { - createSelfReferentialElementCollection(); - addXmlClassRef(PACKAGE_NAME + ".Foo"); - - //If there is a StackOverflowError you will not be able to get the mapping - JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributeNamed("elementCollection").getMapping(); - assertFalse(elementCollectionMapping.allOverridableAttributeMappingNames().hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaEntityTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaEntityTests.java deleted file mode 100644 index d06374fcb2..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaEntityTests.java +++ /dev/null @@ -1,1812 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.VirtualAssociationOverride; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaVirtualAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.core.jpa2.resource.java.Cacheable2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.eclipselink.core.EclipseLinkMappingKeys; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLink2_0JavaEntityTests extends EclipseLink2_0ContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public EclipseLink2_0JavaEntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestMappedSuperclassCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - private void createTestMappedSuperclassCustomerWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEntityLongTimeCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("LongTimeCustomer extends Customer "); - sb.append("{}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "LongTimeCustomer.java", sourceWriter); - } - - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) getJavaPersistentType().getMapping(); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.BASIC_COLLECTION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.BASIC_MAP_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.TRANSFORMATION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(EclipseLinkMappingKeys.VARIABLE_ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAssociations = abstractEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributeNames = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertEquals("foo", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - ListIterator specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testDefaultAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testDefaultAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - JavaEntity superclass = (JavaEntity) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testDefaultAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, overrideContainer.overridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(3, CollectionTools.size(typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - Iterator attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - Iterator attributeOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - attributeOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrideResources.hasNext()); - attributeOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaAttributeOverrides)); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("name", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("name", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - } -// - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AttributeOverrideAnnotation) typeResource.addAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(2, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = (ListIterator) overrideContainer.virtualOverrides(); - JavaVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - - public void testOverridableAssociations() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().overridableAssociationNames(); - assertFalse(overridableAssociations.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociationNames = getJavaEntity().overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -// //TODO add all mapping types to the mapped superclass to test which ones are overridable - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociationNames = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociationNames.next()); - assertEquals("address2", overridableAssociationNames.next()); - assertEquals("address3", overridableAssociationNames.next()); - assertEquals("address4", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = (ListIterator) overrideContainer.specifiedOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AssociationOverrideContainer overrideContainer = javaEntity.getAssociationOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - VirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - - //MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - //BasicMapping idMapping = (BasicMapping) mappedSuperclass.persistentType().attributeNamed("id").getMapping(); - //idMapping.getColumn().setSpecifiedName("FOO"); - //idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - //idMapping.getColumn().setSpecifiedName(null); - //idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, overrideContainer.overridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(2, CollectionTools.size(typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - Iterator associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedOverride(1, 0); - Iterator associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address2", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("address2", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("address2", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AssociationOverrideAnnotation) typeResource.addAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(2, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - Iterator associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = (Iterator) overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = (ListIterator) overrideContainer.virtualOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AttributeOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAttributeOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AttributeOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - VirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (VirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AssociationOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testNestedVirtualAssociationOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".LongTimeCustomer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - specifiedClassRefs.next(); - PersistentType longTimeCustomerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - - AssociationOverrideContainer attributeOverrideContainer = ((Entity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - VirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testSetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheable.setSpecifiedCacheable(null); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testGetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - getJavaPersistentType().getResourcePersistentType().addAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheableAnnotation.setValue(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheableAnnotation.setValue(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(true)", cu); - - cacheableAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - getJavaPersistentType().getResourcePersistentType().removeAnnotation(JPA2_0.CACHEABLE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testIsDefaultCacheable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - PersistenceUnit2_0 persistenceUnit = getPersistenceUnit(); - assertEquals(SharedCacheMode.DISABLE_SELECTIVE, persistenceUnit.getSharedCacheMode()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.UNSPECIFIED); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testInheritedIsDefaultCacheable() throws Exception { - createTestEntity(); - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) getJavaEntity()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaEntity().getParentEntity()).getCacheable(); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - - persistenceUnit2_0.setSpecifiedSharedCacheMode(null); - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToManyMappingTests.java deleted file mode 100644 index 18fe108866..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToManyMappingTests.java +++ /dev/null @@ -1,1303 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinTableRelationshipStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.context.ManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetch; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJoinFetchAnnotation; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLink2_0JavaManyToManyMappingTests - extends EclipseLink2_0ContextModelTestCase -{ - public EclipseLink2_0JavaManyToManyMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithJoinFetchManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, EclipseLink.JOIN_FETCH); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - sb.append("@JoinFetch").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Collection employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private String address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityPropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - - public void testGetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to INNER specifically, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change resource to OUTER, test context - - joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // remove value from resource, test context - - joinFetchAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // remove annotation, text context - - attributeResource.removeAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(joinFetchAnnotation.getValue()); - assertNull(contextJoinFetch.getValue()); - } - - public void testSetJoinFetchValue() throws Exception { - createTestEntityWithJoinFetchManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getMapping(); - EclipseLinkJoinFetch contextJoinFetch = manyToManyMapping.getJoinFetch(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EclipseLinkJoinFetchAnnotation joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to INNER specifically, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - - assertNull(joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - - // change context to OUTER, test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.OUTER); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.OUTER, contextJoinFetch.getValue()); - - // set context to null, test resource - - contextJoinFetch.setValue(null); - - assertNull(attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME)); - assertNull(contextJoinFetch.getValue()); - - // change context to INNER specifically (this time from no annotation), test resource - - contextJoinFetch.setValue(EclipseLinkJoinFetchType.INNER); - joinFetchAnnotation = (EclipseLinkJoinFetchAnnotation) attributeResource.getAnnotation(EclipseLinkJoinFetchAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); - assertEquals(EclipseLinkJoinFetchType.INNER, contextJoinFetch.getValue()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employees", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertEquals("employees", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKey(null); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKey.getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping2_0 = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator mapKeyNames = - manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employees", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping2_0 = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator mapKeyNames = manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - manyToManyMapping2_0.setSpecifiedTargetEntity("Address"); - mapKeyNames = manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employees", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - manyToManyMapping2_0.setSpecifiedTargetEntity("String"); - mapKeyNames = manyToManyMapping2_0.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClassAnnotation = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClassAnnotation); - - //set mapKey name in the resource model, verify context model updated - mapKeyClassAnnotation.setValue("myMapKeyClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("myMapKeyClass", manyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClassAnnotation.getValue()); - - //set mapKey name to null in the resource model - mapKeyClassAnnotation.setValue(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClassAnnotation.getValue()); - - mapKeyClassAnnotation.setValue("myMapKeyClass"); - attributeResource.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", manyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(manyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", manyToManyMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.Integer", manyToManyMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.Integer", manyToManyMapping.getMapKeyClass()); - - manyToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", manyToManyMapping.getMapKeyClass()); - - manyToManyMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.Integer", manyToManyMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - addXmlClassRef(PACKAGE_NAME + ".PrintQueue"); - addXmlClassRef(PACKAGE_NAME + ".PrintJob"); - JavaPersistentType printQueuePersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintQueue"); - ManyToManyMapping jobsMapping = (ManyToManyMapping) printQueuePersistentType.getAttributeNamed("jobs").getMapping(); - JavaPersistentType printJobPersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ManyToManyMapping queuesMapping = (ManyToManyMapping) printJobPersistentType.getAttributeNamed("queues").getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - OrderColumn2_0 jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(null, jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); //the join table name - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - OrderColumn2_0 queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(null, queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - jobsOrderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderColumn.setSpecifiedName("BAR"); - assertEquals("BAR", queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - assertEquals("MY_TABLE_PrintQueue", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printQueuePersistentType.getMapping()).getTable().setSpecifiedName("OTHER_TABLE"); - assertEquals("MY_TABLE_OTHER_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_OTHER_TABLE", queuesOrderColumn.getTable()); - - queuesMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_JOIN_TABLE", queuesOrderColumn.getTable()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany(mappedBy=\"queues\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List queues;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testGetMapKeyColumnMappedByStrategy() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - manyToManyMapping.getRelationship().setStrategyToMappedBy(); - manyToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("employees"); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address_" + TYPE_NAME, manyToManyMapping.getMapKeyColumn().getTable());//join table name of owning many-to-many - - PersistentType persistentType = getPersistenceUnit().getPersistentType("test.Address"); - ManyToManyMapping owningManyToManyMapping = (ManyToManyMapping) persistentType.getAttributeNamed("employees").getMapping(); - ((JoinTableRelationshipStrategy) owningManyToManyMapping.getRelationship().getStrategy()).getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnJoinTableStrategy() throws Exception { - createTestEntityWithValidGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping2_0 manyToManyMapping = (ManyToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", manyToManyMapping.getMapKeyColumn().getTable());//join table name - - manyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", manyToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", manyToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", manyToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testMapKeySpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = mapKeyAttributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.foo", virtualAttributeOverrides.next().getName()); - assertEquals("state.address", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyManyToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping2_0 manyToManyMapping = (JavaManyToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = manyToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - ListIterator specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToOneMappingTests.java deleted file mode 100644 index eed9e497ab..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaManyToOneMappingTests.java +++ /dev/null @@ -1,329 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.ManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapsId2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLink2_0JavaManyToOneMappingTests - extends EclipseLink2_0ContextModelTestCase -{ - public EclipseLink2_0JavaManyToOneMappingTests(String name) { - super(name); - } - - - private void createTestEntity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private Address address;"); - sb.append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithIdDerivedIdentity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - public void testUpdateDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - annotation.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - annotation.setValue("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceAttribute.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("address"); - JavaManyToOneMapping2_0 contextMapping = (JavaManyToOneMapping2_0) contextAttribute.getMapping(); - - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - assertNotNull(annotation); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - - ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertFalse(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertFalse(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); - assertEquals("foo", ((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping2_0 mapping = (ManyToOneMapping2_0) contextAttribute.getMapping(); - ManyToOneRelationship2_0 rel = (ManyToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping2_0 mapping = (ManyToOneMapping2_0) contextAttribute.getMapping(); - ManyToOneRelationship2_0 rel = (ManyToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaMappedSuperclassTests.java deleted file mode 100644 index e757f5d428..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaMappedSuperclassTests.java +++ /dev/null @@ -1,528 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.core.jpa2.resource.java.Cacheable2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTracking; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomizer; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkReadOnly; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkChangeTrackingAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkCustomizerAnnotation; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkReadOnlyAnnotation; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLink2_0JavaMappedSuperclassTests extends EclipseLink2_0ContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private ICompilationUnit createTestMappedSuperclassWithReadOnly() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.READ_ONLY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - sb.append("@ReadOnly").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassWithConvertAndCustomizerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - sb.append(" @Customizer(Foo.class"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassWithChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CHANGE_TRACKING); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - sb.append(" @ChangeTracking").append(CR); - } - }); - } - - public EclipseLink2_0JavaMappedSuperclassTests(String name) { - super(name); - } - - - public void testGetReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(true, readOnly.isReadOnly()); - } - - public void testGetSpecifiedReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - } - - //TODO test inheriting a default readonly from you superclass - public void testGetDefaultReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(false, readOnly.isDefaultReadOnly()); - } - - public void testSetSpecifiedReadOnly() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(true, readOnly.isReadOnly()); - - readOnly.setSpecifiedReadOnly(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertEquals(null, readOnly.getSpecifiedReadOnly());//Boolean.FALSE and null really mean the same thing since there are only 2 states in the java resource model - - readOnly.setSpecifiedReadOnly(Boolean.TRUE); - assertNotNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - - readOnly.setSpecifiedReadOnly(null); - assertNull(typeResource.getAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME)); - assertEquals(null, readOnly.getSpecifiedReadOnly());//Boolean.FALSE and null really mean the same thing since there are only 2 states in the java resource model - } - - public void testSpecifiedReadOnlyUpdatesFromResourceModelChange() throws Exception { - createTestMappedSuperclassWithReadOnly(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkReadOnly readOnly = mappedSuperclass.getReadOnly(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.removeAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(null, readOnly.getSpecifiedReadOnly()); - assertEquals(false, readOnly.isDefaultReadOnly()); - - typeResource.addAnnotation(EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, readOnly.getSpecifiedReadOnly()); - } - - public void testGetCustomizerClass() throws Exception { - createTestMappedSuperclassWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping()).getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - } - - public void testSetCustomizerClass() throws Exception { - createTestMappedSuperclassWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkCustomizer customizer = ((EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping()).getCustomizer(); - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - - - customizer.setSpecifiedCustomizerClass(null); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals(null, customizerAnnotation); - - - customizer.setSpecifiedCustomizerClass("Bar"); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - assertEquals("Bar", customizerAnnotation.getValue()); - } - - public void testGetCustomizerClassUpdatesFromResourceModelChange() throws Exception { - createTestMappedSuperclassWithConvertAndCustomizerClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkCustomizer customizer = mappedSuperclass.getCustomizer(); - - assertEquals("Foo", customizer.getSpecifiedCustomizerClass()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkCustomizerAnnotation customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.getAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - customizerAnnotation.setValue("Bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("Bar", customizer.getSpecifiedCustomizerClass()); - - typeResource.removeAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation = (EclipseLinkCustomizerAnnotation) typeResource.addAnnotation(EclipseLinkCustomizerAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(null, customizer.getSpecifiedCustomizerClass()); - - customizerAnnotation.setValue("FooBar"); - getJpaProject().synchronizeContextModel(); - assertEquals("FooBar", customizer.getSpecifiedCustomizerClass()); - } - - public void testGetChangeTracking() throws Exception { - createTestMappedSuperclassWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = mappedSuperclass.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test context value - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change resource to ATTRIBUTE specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change resource to OBJECT specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change resource to DEFERRED specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change resource to AUTO specifically, test context - - resourceChangeTracking.setValue(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO); - getJpaProject().synchronizeContextModel(); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove value from resource, test context - - resourceChangeTracking.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // remove annotation, text context - - typeResource.removeAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getDefaultType()); - assertNull(contextChangeTracking.getSpecifiedType()); - } - - public void testSetChangeTracking() throws Exception { - createTestMappedSuperclassWithChangeTracking(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) getJavaPersistentType().getMapping(); - EclipseLinkChangeTracking contextChangeTracking = mappedSuperclass.getChangeTracking(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EclipseLinkChangeTrackingAnnotation resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - // base annotated, test resource value - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertNull(resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - - // change context to ATTRIBUTE specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.ATTRIBUTE, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, contextChangeTracking.getSpecifiedType()); - - // change context to OBJECT specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.OBJECT, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, contextChangeTracking.getSpecifiedType()); - - // change context to DEFERRED specifically, test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.DEFERRED, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, contextChangeTracking.getSpecifiedType()); - - // change context to null, test resource - - contextChangeTracking.setSpecifiedType(null); - - assertNull(typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME)); - assertNull(contextChangeTracking.getSpecifiedType()); - - // change context to AUTO specifically (this time from no annotation), test resource - - contextChangeTracking.setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - resourceChangeTracking = (EclipseLinkChangeTrackingAnnotation) typeResource.getAnnotation(EclipseLinkChangeTrackingAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.ChangeTrackingType.AUTO, resourceChangeTracking.getValue()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, contextChangeTracking.getSpecifiedType()); - } - - - public void testSetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaPersistentType().getMapping()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheable.setSpecifiedCacheable(null); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testGetSpecifiedCacheable() throws Exception { - ICompilationUnit cu = createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaPersistentType().getMapping()).getCacheable(); - Cacheable2_0Annotation cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - - getJavaPersistentType().getResourcePersistentType().addAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - cacheableAnnotation.setValue(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(false)", cu); - - cacheableAnnotation.setValue(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable(true)", cu); - - cacheableAnnotation.setValue(null); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation.getValue()); - assertSourceContains("@Cacheable", cu); - - getJavaPersistentType().getResourcePersistentType().removeAnnotation(JPA2_0.CACHEABLE); - getJpaProject().synchronizeContextModel(); - cacheableAnnotation = (Cacheable2_0Annotation) getJavaPersistentType().getResourcePersistentType().getAnnotation(JPA2_0.CACHEABLE); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, cacheableAnnotation); - assertSourceDoesNotContain("@Cacheable", cu); - } - - public void testIsDefaultCacheable() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaPersistentType().getMapping()).getCacheable(); - PersistenceUnit2_0 persistenceUnit = getPersistenceUnit(); - assertEquals(SharedCacheMode.DISABLE_SELECTIVE, persistenceUnit.getSharedCacheMode()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit.setSpecifiedSharedCacheMode(SharedCacheMode.UNSPECIFIED); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testInheritedIsDefaultCacheable() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) getJavaPersistentType().getMapping()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) getJavaPersistentType().getSuperPersistentType().getMapping()).getCacheable(); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - - persistenceUnit2_0.setSpecifiedSharedCacheMode(null); - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java deleted file mode 100644 index 66e4dc9412..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToManyMappingTests.java +++ /dev/null @@ -1,1421 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnRelationship; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaVirtualAttributeOverride; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToManyRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyClass2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.OneToMany2_0Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -/** - * EclipseLink2_0JavaOneToManyMappingTests - */ -@SuppressWarnings("nls") -public class EclipseLink2_0JavaOneToManyMappingTests - extends EclipseLink2_0ContextModelTestCase -{ - public EclipseLink2_0JavaOneToManyMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private AnnotationTestType employee;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private String address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableKeyOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map parcels;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityPropertyInfo() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PropertyInfo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private Integer parcelNumber;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private Integer size;").append(CR); - sb.append(CR); - sb.append(" private java.math.BigDecimal tax;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PropertyInfo.java", sourceWriter); - } - private ICompilationUnit createTestEntityWithValidOneToManyMappingOrphanRemovalSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(orphanRemoval=false)").append(CR); - sb.append(" private Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private JavaOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) { - return ((JavaOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval(); - } - - public void testDefaultOneToManyGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToManyMapping).isDefaultOrphanRemoval()); - } - - public void testSpecifiedOneToManyGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToManyMapping).isDefaultOrphanRemoval()); - } - - public void testGetOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - - assertEquals(false, mappingsOrphanRemoval.isOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(true, mappingsOrphanRemoval.isOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - oneToMany.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToManyMappingOrphanRemovalSpecified(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testSetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - - assertEquals(Boolean.TRUE, oneToMany.getOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_MANY)); // .getElement); - } - - public void testSetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - - assertEquals(Boolean.TRUE, oneToMany.getOrphanRemoval()); - - oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_MANY)); - - oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - } - - public void testGetSpecifiedOrphanRemovalUpdatesFromResourceModelChange() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToMany2_0Annotation oneToMany = (OneToMany2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_MANY); - oneToMany.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - oneToMany.setOrphanRemoval(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertSame(oneToManyMapping, persistentAttribute.getMapping()); - - oneToMany.setOrphanRemoval(Boolean.FALSE); - attributeResource.setPrimaryAnnotation(null, EmptyIterable.instance()); - getJpaProject().synchronizeContextModel(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testUpdateMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKey(null); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(mapKey.getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = - javaOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employee", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = javaOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = javaOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertEquals("employee", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - MapKeyClass2_0Annotation mapKeyClassAnnotation = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertNotNull(mapKeyClassAnnotation); - - //set mapKey name in the resource model, verify context model updated - mapKeyClassAnnotation.setValue("myMapKeyClass"); - this.getJpaProject().synchronizeContextModel(); - assertEquals("myMapKeyClass", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("myMapKeyClass", mapKeyClassAnnotation.getValue()); - - //set mapKey name to null in the resource model - mapKeyClassAnnotation.setValue(null); - this.getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(mapKeyClassAnnotation.getValue()); - - mapKeyClassAnnotation.setValue("myMapKeyClass"); - attributeResource.removeAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testModifyMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKeyClass("String"); - MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME); - assertEquals("String", oneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", mapKeyClass.getValue()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(oneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(attributeResource.getAnnotation(MapKeyClass2_0Annotation.ANNOTATION_NAME)); - } - - public void testDefaultMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.String", oneToManyMapping.getDefaultMapKeyClass()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("java.lang.String", oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testDefaultMapKeyClassCollectionType() throws Exception { - createTestEntityWithValidOneToManyMappingOrphanRemovalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultMapKeyClass()); - } - - public void testMapKeyClass() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertEquals("java.lang.String", oneToManyMapping.getMapKeyClass()); - - oneToManyMapping.setSpecifiedMapKeyClass("foo"); - assertEquals("foo", oneToManyMapping.getMapKeyClass()); - - oneToManyMapping.setSpecifiedMapKeyClass(null); - assertEquals("java.lang.String", oneToManyMapping.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - addXmlClassRef(PACKAGE_NAME + ".PrintQueue"); - addXmlClassRef(PACKAGE_NAME + ".PrintJob"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) getJavaPersistentType().getAttributeNamed("jobs").getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - JavaPersistentType printJobPersistentType = (JavaPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - - assertEquals("MY_TABLE", orderColumn.getTable()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @OneToMany(mappedBy=\"queue\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private PrintQueue queue;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testGetMapKeyColumnMappedByStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - oneToManyMapping.getRelationship().setStrategyToMappedBy(); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("employee"); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//owing entity table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testGetMapKeyColumnJoinTableStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals(TYPE_NAME + "_Address", oneToManyMapping.getMapKeyColumn().getTable());//join table name - - oneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_PRIMARY_TABLE"); - assertEquals("MY_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - } - - public void testTargetForeignKeyJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - JoinColumn joinColumn = ((JoinColumnRelationship) oneToManyMapping.getRelationship()).getJoinColumnStrategy().specifiedJoinColumns().next(); - - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("Address", joinColumn.getDefaultTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - joinColumn.setSpecifiedName("FOO"); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - } - - //target foreign key case - public void testGetMapKeyColumnJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - assertNull(oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address", oneToManyMapping.getMapKeyColumn().getTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", oneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", oneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", oneToManyMapping.getMapKeyColumn().getDefaultTable()); - } - - //target foreign key case - public void testOrderColumnDefaultsJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 oneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - ((JoinColumnRelationship) oneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - ((Orderable2_0) oneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = ((Orderable2_0) oneToManyMapping.getOrderable()).getOrderColumn(); - - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("Address", orderColumn.getTable());//target table name - - Entity addressEntity = getPersistenceUnit().getEntity("test.Address"); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); - OneToManyRelationship2_0 rel = (OneToManyRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping2_0 mapping = (OneToManyMapping2_0) contextAttribute.getMapping(); - OneToManyRelationship2_0 rel = (OneToManyRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testMapKeySpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - - ListIterator specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.BAR"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BLAH"); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("BLAH", specifiedMapKeyAttributeOverrides.next().getName()); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("value.BAR", specifiedMapKeyAttributeOverrides.next().getName()); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedMapKeyAttributeOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertFalse(specifiedMapKeyAttributeOverrides.hasNext()); - } - - public void testMapKeyValueVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - ReadOnlyAttributeOverride defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable addressEmbeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) addressEmbeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("parcels", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = mapKeyAttributeOverrideContainer.virtualOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME +"_PropertyInfo", defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(0, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, mapKeyAttributeOverrideContainer.specifiedOverridesSize()); - } - - public void testMapKeyValueAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.overridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("value.FOO2"); - getJpaProject().synchronizeContextModel(); - - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(7, mapKeyAttributeOverrideContainer.overridesSize()); - } - - public void testMapKeyValueVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.city"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("key.state.foo"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("size"); - getJpaProject().synchronizeContextModel(); - assertEquals(2, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - public void testMapKeyValueAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - mapKeyAttributeOverrideContainer.specifiedOverrides().next().convertToVirtual(); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator virtualAttributeOverrides = mapKeyAttributeOverrideContainer.virtualOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state.foo", virtualAttributeOverrides.next().getName()); - assertEquals("state.address", virtualAttributeOverrides.next().getName()); - assertEquals("zip", virtualAttributeOverrides.next().getName()); - assertEquals(4, mapKeyAttributeOverrideContainer.virtualOverridesSize()); - } - - - public void testMapKeyValueMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddableKeyOneToManyMapping(); - createTestEmbeddableAddress(); - createTestEmbeddableState(); - createTestEntityPropertyInfo(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".PropertyInfo"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping2_0 oneToManyMapping = (JavaOneToManyMapping2_0) getJavaPersistentType().getAttributeNamed("parcels").getMapping(); - JavaAttributeOverrideContainer mapKeyAttributeOverrideContainer = oneToManyMapping.getMapKeyAttributeOverrideContainer(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - mapKeyAttributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - ListIterator specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("city", specifiedOverrides.next().getName()); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - Iterator attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("key.state.foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("key.city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - specifiedOverrides = mapKeyAttributeOverrideContainer.specifiedOverrides(); - assertEquals("state.foo", specifiedOverrides.next().getName()); - assertEquals("city", specifiedOverrides.next().getName()); - assertFalse(specifiedOverrides.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToOneMappingTests.java deleted file mode 100644 index 838ef9b1d7..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/EclipseLink2_0JavaOneToOneMappingTests.java +++ /dev/null @@ -1,817 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapsId2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.OneToOne2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; - -@SuppressWarnings("nls") -public class EclipseLink2_0JavaOneToOneMappingTests - extends EclipseLink2_0ContextModelTestCase -{ - public EclipseLink2_0JavaOneToOneMappingTests(String name) { - super(name); - } - - - private void createTestEntity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private Address address;"); - sb.append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(orphanRemoval=false)"); - sb.append(CR); - sb.append(" private Address address;"); - sb.append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithIdDerivedIdentity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - public void testUpdateDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceAttribute.addAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - annotation.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - annotation.setValue("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceAttribute.removeAnnotation(JPA2_0.MAPS_ID); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("address"); - JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); - - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - MapsId2_0Annotation annotation = - (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); - assertNotNull(annotation); - assertEquals("foo", annotation.getValue()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", annotation.getValue()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithIdDerivedIdentity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentType resourceType = - getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); - JavaPersistentType contextType = getJavaPersistentType(); - JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertTrue(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertNull(((JavaManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - // this is no longer supported (it was a bit of a testing hack anyway...) - // contextAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - // the *real* test is whether the Id annotation still results in a 1:1 mapping... - contextAttribute.setMappingKey(null); // clear any mapping annotation - resourceAttribute.addAnnotation(JPA.ID); // add Id annotation - this.getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaOneToOneMapping2_0); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaManyToOneMapping2_0); - - contextAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertNull(resourceAttribute.getAnnotation(JPA.ID)); - assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); - assertTrue(contextAttribute.getMapping() instanceof JavaBasicMapping); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - private JavaOrphanRemovable2_0 getOrphanRemovalOf(OneToOneMapping2_0 oneToOneMapping) { - return ((JavaOrphanRemovalHolder2_0) oneToOneMapping).getOrphanRemoval(); - } - - public void testDefaultOneToOneGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToOneMapping).isDefaultOrphanRemoval()); - } - - public void testSpecifiedOneToOneGetDefaultOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - assertEquals(false, this.getOrphanRemovalOf(oneToOneMapping).isDefaultOrphanRemoval()); - } - - public void testGetOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertEquals(false, mappingsOrphanRemoval.isOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(true, mappingsOrphanRemoval.isOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - oneToOne.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testGetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - - assertEquals(Boolean.FALSE, this.getOrphanRemovalOf(oneToOneMapping).getSpecifiedOrphanRemoval()); - } - - public void testSetSpecifiedOrphanRemoval() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - - assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_ONE)); // .getElement); - } - - public void testSetSpecifiedOrphanRemoval2() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - - assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); - - oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(null); - assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_ONE)); - } - - public void testGetSpecifiedOrphanRemovalUpdatesFromResourceModelChange() throws Exception { - this.createTestEntity(); - this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); - JavaOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToOneMapping); - - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); - oneToOne.setOrphanRemoval(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - oneToOne.setOrphanRemoval(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertSame(oneToOneMapping, persistentAttribute.getMapping()); - - oneToOne.setOrphanRemoval(Boolean.FALSE); - attributeResource.setPrimaryAnnotation(null, EmptyIterable.instance()); - getJpaProject().synchronizeContextModel(); - - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 mapping = (OneToOneMapping2_0) contextAttribute.getMapping(); - OneToOneRelationship2_0 rel = (OneToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToMappedBy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping2_0 mapping = (OneToOneMapping2_0) contextAttribute.getMapping(); - OneToOneRelationship2_0 rel = (OneToOneRelationship2_0) mapping.getRelationship(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/JptEclipseLink2_0JavaContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/JptEclipseLink2_0JavaContextModelTests.java deleted file mode 100644 index 95cac0fda0..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/java/JptEclipseLink2_0JavaContextModelTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLink2_0JavaContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink2_0JavaContextModelTests.class.getName()); - suite.addTestSuite(EclipseLink2_0JavaCollectionTableTests.class); - suite.addTestSuite(EclipseLink2_0JavaElementCollectionMappingTests.class); - suite.addTestSuite(EclipseLink2_0JavaEntityTests.class); - suite.addTestSuite(EclipseLink2_0JavaManyToManyMappingTests.class); - suite.addTestSuite(EclipseLink2_0JavaManyToOneMappingTests.class); - suite.addTestSuite(EclipseLink2_0JavaMappedSuperclassTests.class); - suite.addTestSuite(EclipseLink2_0JavaOneToManyMappingTests.class); - suite.addTestSuite(EclipseLink2_0JavaOneToOneMappingTests.class); - return suite; - } - - private JptEclipseLink2_0JavaContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmCollectionTableTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmCollectionTableTests.java deleted file mode 100644 index 98fe95cf8e..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmCollectionTableTests.java +++ /dev/null @@ -1,751 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.core.jpa2.context.CollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaCollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlCollectionTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlElementCollection_2_0; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; - -@SuppressWarnings("nls") -public class EclipseLink2_0OrmCollectionTableTests extends EclipseLink2_0OrmContextModelTestCase -{ - public EclipseLink2_0OrmCollectionTableTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntityWithValidElementCollection() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ElementCollection").append(CR); - sb.append(" private Collection projects;").append(CR); - sb.append("@Id").append(CR); - } - }); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = elementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - - - //set name in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setName("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedName()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getName()); - - //set name to null in the resource model - resourceElementCollection.getCollectionTable().setName(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable().getName()); - - resourceElementCollection.getCollectionTable().setName("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedName()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getName()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = elementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set name in the context model, verify resource model modified - ormCollectionTable.setSpecifiedName("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedName()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getName()); - - //set name to null in the context model - ormCollectionTable.setSpecifiedName(null); - assertNull(ormCollectionTable.getSpecifiedName()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testVirtualCollectionTable() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(TYPE_NAME + "_projects", virtualCollectionTable.getName()); - assertNull(virtualCollectionTable.getSpecifiedCatalog()); - assertNull(virtualCollectionTable.getSpecifiedSchema()); - assertEquals(0, virtualCollectionTable.specifiedJoinColumnsSize()); - JoinColumn virtualJoinColumn = virtualCollectionTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_id", virtualJoinColumn.getDefaultName()); - assertEquals("id", virtualJoinColumn.getDefaultReferencedColumnName()); - - JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) javaPersistentAttribute.getMapping(); - JavaCollectionTable2_0 javaCollectionTable = javaElementCollectionMapping.getCollectionTable(); - javaCollectionTable.setSpecifiedName("FOO"); - javaCollectionTable.setSpecifiedCatalog("CATALOG"); - javaCollectionTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaCollectionTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - - assertEquals("FOO", virtualCollectionTable.getSpecifiedName()); - assertEquals("CATALOG", virtualCollectionTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualCollectionTable.getSpecifiedSchema()); - assertEquals(1, virtualCollectionTable.specifiedJoinColumnsSize()); - virtualJoinColumn = virtualCollectionTable.specifiedJoinColumns().next(); - assertEquals("NAME", virtualJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", virtualJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "projects"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - assertEquals(TYPE_NAME + "_projects", ormCollectionTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).setSpecifiedName("Foo"); - assertEquals("Foo_projects", ormCollectionTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).setSpecifiedName("Bar"); - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals("Bar_projects", ormCollectionTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove element collection mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("projects"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute2.getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - assertTrue(ormPersistentAttribute2.isVirtual()); - assertEquals("JAVA_COLLECTION_TABLE", virtualCollectionTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - javaElementCollectionMapping.getCollectionTable().setSpecifiedName(null); - assertNull(virtualCollectionTable.getSpecifiedName()); - assertEquals("Bar_projects", virtualCollectionTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set schema in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setSchema("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getSchema()); - - //set Schema to null in the resource model - resourceElementCollection.getCollectionTable().setSchema(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable().getSchema()); - - resourceElementCollection.getCollectionTable().setSchema("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedSchema()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getSchema()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Schema in the context model, verify resource model modified - ormCollectionTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedSchema()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getSchema()); - - //set Schema to null in the context model - ormCollectionTable.setSpecifiedSchema(null); - assertNull(ormCollectionTable.getSpecifiedSchema()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Catalog in the resource model, verify context model updated - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - resourceElementCollection.getCollectionTable().setCatalog("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getCatalog()); - - //set Catalog to null in the resource model - resourceElementCollection.getCollectionTable().setCatalog(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable().getCatalog()); - - resourceElementCollection.getCollectionTable().setCatalog("FOO"); - assertEquals("FOO", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("FOO", resourceElementCollection.getCollectionTable().getCatalog()); - - resourceElementCollection.setCollectionTable(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - - //set Catalog in the context model, verify resource model modified - ormCollectionTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormCollectionTable.getSpecifiedCatalog()); - assertEquals("foo", resourceElementCollection.getCollectionTable().getCatalog()); - - //set Catalog to null in the context model - ormCollectionTable.setSpecifiedCatalog(null); - assertNull(ormCollectionTable.getSpecifiedCatalog()); - assertNull(resourceElementCollection.getCollectionTable()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - OrmJoinColumn joinColumn = ormCollectionTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormCollectionTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormCollectionTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - - ListIterator joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - ormCollectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormCollectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormCollectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals(3, resourceCollectionTable.getJoinColumns().size()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(2, resourceCollectionTable.getJoinColumns().size()); - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(1, resourceCollectionTable.getJoinColumns().size()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(0).getName()); - - ormCollectionTable.removeSpecifiedJoinColumn(0); - assertEquals(0, resourceCollectionTable.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - - ormCollectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormCollectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormCollectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - assertEquals(3, resourceCollectionTable.getJoinColumns().size()); - - - ormCollectionTable.moveSpecifiedJoinColumn(2, 0); - ListIterator joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - - - ormCollectionTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", resourceCollectionTable.getJoinColumns().get(0).getName()); - assertEquals("BAR", resourceCollectionTable.getJoinColumns().get(1).getName()); - assertEquals("FOO", resourceCollectionTable.getJoinColumns().get(2).getName()); - } - - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - resourceCollectionTable.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - - resourceCollectionTable.getJoinColumns().get(0).setName("FOO"); - resourceCollectionTable.getJoinColumns().get(1).setName("BAR"); - resourceCollectionTable.getJoinColumns().get(2).setName("BAZ"); - - ListIterator joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().move(2, 0); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().move(0, 1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(1); - joinColumns = ormCollectionTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - resourceCollectionTable.getJoinColumns().remove(0); - assertFalse(ormCollectionTable.specifiedJoinColumns().hasNext()); - } - - public void testUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ListIterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - assertEquals(0, ormCollectionTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormCollectionTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = resourceCollectionTable.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator uniqueConstraints = resourceCollectionTable.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, resourceCollectionTable.getUniqueConstraints().size()); - - ormCollectionTable.removeUniqueConstraint(1); - - ListIterator uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormCollectionTable.removeUniqueConstraint(1); - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormCollectionTable.removeUniqueConstraint(0); - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - ormCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, resourceCollectionTable.getUniqueConstraints().size()); - - - ormCollectionTable.moveUniqueConstraint(2, 0); - ListIterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - ListIterator uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormCollectionTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - - uniqueConstraintResources = resourceCollectionTable.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 resourceElementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - OrmCollectionTable2_0 ormCollectionTable = ormElementCollectionMapping.getCollectionTable(); - resourceElementCollection.setCollectionTable(OrmFactory.eINSTANCE.createXmlCollectionTable()); - XmlCollectionTable resourceCollectionTable = resourceElementCollection.getCollectionTable(); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - resourceCollectionTable.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(1); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - resourceCollectionTable.getUniqueConstraints().remove(0); - uniqueConstraints = ormCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntityWithValidElementCollection(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.attributes().next().getMapping(); - CollectionTable2_0 virtualCollectionTable = virtualElementCollectionMapping.getCollectionTable(); - - assertTrue(ormPersistentType.attributes().next().isVirtual()); - - ListIterator uniqueConstraints = (ListIterator) virtualCollectionTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping2_0 = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - JavaCollectionTable2_0 javaCollectionTable = javaElementCollectionMapping2_0.getCollectionTable(); - - javaCollectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaCollectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaCollectionTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = (ListIterator) virtualCollectionTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); - - ormPersistentType.attributes().next().convertToSpecified(); - - virtualElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentType.attributes().next().getMapping(); - assertEquals(0, virtualElementCollectionMapping.getCollectionTable().uniqueConstraintsSize()); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmContextModelTestCase.java deleted file mode 100644 index 53009c6598..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmContextModelTestCase.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm; - -import org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.eclipselink.core.context.orm.EclipseLinkEntityMappings; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; -import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationOperation; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.eclipselink.core.resource.orm.v2_0.EclipseLink2_0; -import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -@SuppressWarnings("nls") -public abstract class EclipseLink2_0OrmContextModelTestCase - extends EclipseLink2_0ContextModelTestCase -{ - protected JpaXmlResource eclipseLink2_0OrmXmlResource; - - - protected EclipseLink2_0OrmContextModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.eclipseLink2_0OrmXmlResource = getJpaProject().getDefaultEclipseLinkOrmXmlResource(); - } - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - // don't create default orm.xml - instead build eclipselink-orm.xml - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.FALSE); - return dataModel; - } - - @Override - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) throws Exception { - TestJpaProject testJpaProject = super.buildJpaProject(projectName, autoBuild, jpaConfig); - - EclipseLinkOrmFileCreationOperation operation = - new EclipseLinkOrmFileCreationOperation(buildEclipseLinkOrmConfig(testJpaProject)); - operation.execute(null, null); - - return testJpaProject; - } - - protected IDataModel buildEclipseLinkOrmConfig(TestJpaProject testJpaProject) { - IDataModel dataModel = - DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); - dataModel.setProperty(JptFileCreationDataModelProperties.CONTAINER_PATH, - testJpaProject.getProject().getFolder("src/META-INF").getFullPath()); - dataModel.setProperty(JpaFileCreationDataModelProperties.VERSION, EclipseLink2_0.SCHEMA_VERSION); - dataModel.setProperty(OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT, Boolean.TRUE); - return dataModel; - } - - @Override - protected void tearDown() throws Exception { - this.eclipseLink2_0OrmXmlResource = null; - super.tearDown(); - } - - @Override - protected JpaXmlResource getOrmXmlResource() { - return this.eclipseLink2_0OrmXmlResource; - } - - @Override - protected XmlEntityMappings getXmlEntityMappings() { - return (XmlEntityMappings) super.getXmlEntityMappings(); - } - - @Override - protected EclipseLinkEntityMappings getEntityMappings() { - return (EclipseLinkEntityMappings) super.getEntityMappings(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmElementCollectionMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmElementCollectionMappingTests.java deleted file mode 100644 index 40b402df55..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmElementCollectionMappingTests.java +++ /dev/null @@ -1,1445 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.ReadOnlyAttributeOverride; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.core.jpa2.context.ElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlElementCollection; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlElementCollection_2_0; - -@SuppressWarnings("nls") -public class EclipseLink2_0OrmElementCollectionMappingTests extends EclipseLink2_0OrmContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public EclipseLink2_0OrmElementCollectionMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection(targetClass=String.class, fetch=FetchType.EAGER)"); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithEmbeddableElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.FETCH_TYPE, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithNonGenericElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericBasicElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapElementCollectionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA2_0.ELEMENT_COLLECTION, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createSelfReferentialElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR).append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Foo").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.List elementCollection;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Foo.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertEquals("oneToOneMapping", ormElementCollectionMapping.getName()); - assertEquals("oneToOneMapping", elementCollection.getName()); - - //set name in the resource model, verify context model updated - elementCollection.setName("newName"); - assertEquals("newName", ormElementCollectionMapping.getName()); - assertEquals("newName", elementCollection.getName()); - - //set name to null in the resource model - elementCollection.setName(null); - assertNull(ormElementCollectionMapping.getName()); - assertNull(elementCollection.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertEquals("oneToOneMapping", ormElementCollectionMapping.getName()); - assertEquals("oneToOneMapping", elementCollection.getName()); - - //set name in the context model, verify resource model updated - ormElementCollectionMapping.setName("newName"); - assertEquals("newName", ormElementCollectionMapping.getName()); - assertEquals("newName", elementCollection.getName()); - - //set name to null in the context model - ormElementCollectionMapping.setName(null); - assertNull(ormElementCollectionMapping.getName()); - assertNull(elementCollection.getName()); - } - - public void testMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormElementCollectionMapping.getName()); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", virtualElementCollectionMapping.getName()); - assertEquals(FetchType.EAGER, virtualElementCollectionMapping.getSpecifiedFetch()); - assertEquals("String", virtualElementCollectionMapping.getSpecifiedTargetClass()); - - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormElementCollectionMapping.getName()); - assertEquals(null, ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getDefaultFetch()); - assertEquals(null, ormElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals(PACKAGE_NAME + ".Address", ormElementCollectionMapping.getDefaultTargetClass()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.convertToSpecified(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormElementCollectionMapping.getName()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityWithElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormElementCollectionMapping.getName()); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getFetch()); - } - - - public void testMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -// assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - assertFalse(elementCollectionMapping.isDefault()); - elementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertFalse(elementCollectionMapping.isDefault()); - - ormPersistentAttribute.setMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the resource model, verify context model updated - elementCollection.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, elementCollection.getFetch()); - - elementCollection.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, elementCollection.getFetch()); - - //set fetch to null in the resource model - elementCollection.setFetch(null); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - assertNull(elementCollection.getFetch()); - - //set fetch in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, elementCollection.getFetch()); - assertEquals(FetchType.EAGER, ormElementCollectionMapping.getSpecifiedFetch()); - - ormElementCollectionMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, elementCollection.getFetch()); - assertEquals(FetchType.LAZY, ormElementCollectionMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormElementCollectionMapping.setSpecifiedFetch(null); - assertNull(elementCollection.getFetch()); - assertNull(ormElementCollectionMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedTargetClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the resource model, verify context model updated - elementCollection.setTargetClass("newTargetClass"); - assertEquals("newTargetClass", ormElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the resource model - elementCollection.setTargetClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - public void testModifySpecifiedTargetClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection_2_0 elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - - //set target class in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedTargetClass("newTargetClass"); - assertEquals("newTargetClass", ormElementCollectionMapping.getSpecifiedTargetClass()); - assertEquals("newTargetClass", elementCollection.getTargetClass()); - - //set target class to null in the context model - ormElementCollectionMapping.setSpecifiedTargetClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedTargetClass()); - assertNull(elementCollection.getTargetClass()); - } - - - public void testGetValueTypeEmbeddable() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeEntity() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeNone() throws Exception { - createTestEntityWithNonGenericElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.NO_TYPE, elementCollectionMapping.getValueType()); - - elementCollectionMapping.setSpecifiedTargetClass("test.Address"); - assertEquals(ElementCollectionMapping2_0.Type.EMBEDDABLE_TYPE, elementCollectionMapping.getValueType()); - } - - public void testGetValueTypeBasic() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.Address"); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - assertEquals(ElementCollectionMapping2_0.Type.BASIC_TYPE, elementCollectionMapping.getValueType()); - } - - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualElementCollectionMapping.getSpecifiedMapKey()); - assertNull(virtualElementCollectionMapping.getMapKey()); - assertFalse(virtualElementCollectionMapping.isPkMapKey()); - assertFalse(virtualElementCollectionMapping.isCustomMapKey()); - assertTrue(virtualElementCollectionMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setPkMapKey(true); - assertEquals(null, virtualElementCollectionMapping.getMapKey());//no primary key on an embeddable - assertTrue(virtualElementCollectionMapping.isPkMapKey()); - assertFalse(virtualElementCollectionMapping.isCustomMapKey()); - assertFalse(virtualElementCollectionMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setCustomMapKey(true); - javaElementCollectionMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualElementCollectionMapping.getSpecifiedMapKey()); - assertEquals("city", virtualElementCollectionMapping.getMapKey()); - assertFalse(virtualElementCollectionMapping.isPkMapKey()); - assertTrue(virtualElementCollectionMapping.isCustomMapKey()); - assertFalse(virtualElementCollectionMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany xmlOneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(xmlOneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", xmlOneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKey(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKey()); - assertNull(xmlOneToMany.getMapKey().getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = - virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - OrmReadOnlyPersistentAttribute attribute = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) attribute.getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaElementCollectionMapping.setSpecifiedTargetClass("test.Address"); - mapKeyNames = virtualElementCollectionMapping.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - attribute.convertToSpecified(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = ormElementCollectionMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - ormElementCollectionMapping.setSpecifiedTargetClass("test.Address"); - mapKeyNames = ormElementCollectionMapping.candidateMapKeyNames(); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormElementCollectionMapping.setSpecifiedTargetClass("String"); - mapKeyNames = ormElementCollectionMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - elementCollection.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNotNull(elementCollection.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - elementCollection.getMapKeyClass().setClassName("String"); - assertEquals("String", ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", elementCollection.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - elementCollection.getMapKeyClass().setClassName(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass().getClassName()); - - elementCollection.getMapKeyClass().setClassName("String"); - elementCollection.setMapKeyClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualElementCollectionMapping.getMapKeyClass()); - assertEquals("java.lang.String", virtualElementCollectionMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaElementCollectionMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", virtualElementCollectionMapping.getMapKeyClass()); - assertEquals("Integer", virtualElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualElementCollectionMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - XmlElementCollection elementCollection = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormElementCollectionMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertEquals("String", elementCollection.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormElementCollectionMapping.setSpecifiedMapKeyClass(null); - assertNull(ormElementCollectionMapping.getSpecifiedMapKeyClass()); - assertNull(elementCollection.getMapKeyClass()); - } - public void testOrderColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = (Orderable2_0) elementCollectionMapping.getOrderable(); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", orderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - OrmElementCollectionMapping2_0 elementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = (Orderable2_0) elementCollectionMapping.getOrderable(); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaElementCollectionMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 virtualElementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute2.getMapping(); - orderable = (Orderable2_0) virtualElementCollectionMapping.getOrderable(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(false, orderable.isNoOrdering()); - assertEquals(TYPE_NAME + "_addresses", orderable.getOrderColumn().getTable()); - assertEquals("addresses_ORDER", orderable.getOrderColumn().getName()); - - ((Orderable2_0) javaElementCollectionMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_addresses", orderable.getOrderColumn().getTable()); - assertEquals("FOO", orderable.getOrderColumn().getName()); - } - - public void testVirtualValueColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attrubte in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getValueColumn(); - assertEquals("addresses", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getValueColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getValueColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getValueColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getValueColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getValueColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getValueColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", virtualColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, virtualColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), virtualColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), virtualColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), virtualColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullColumnDefaults() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmElementCollectionMapping2_0 addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - OrmColumn ormColumn = addressesVirtualMapping.getValueColumn(); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getValueColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getValueColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getValueColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getValueColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getValueColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getValueColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getValueColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualValueColumnTable() throws Exception { - createTestEntityWithGenericBasicElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getValueColumn(); - - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //entity table should have no affect on the collection table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //set Column table element in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - assertEquals("JAVA_COLLECTION_TABLE", virtualColumn.getTable()); - javaElementCollectionMapping.getValueColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - virtualColumn = addressesVirtualMapping.getValueColumn(); - assertNull(virtualColumn.getSpecifiedTable()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getDefaultTable()); - } - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - elementCollectionResource.getAttributeOverrides().get(0).setName("FOO"); - elementCollectionResource.getAttributeOverrides().get(1).setName("BAR"); - elementCollectionResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, elementCollectionResource.getAttributeOverrides().size()); - - attributeOverrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", elementCollectionResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", elementCollectionResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getAttributeOverrides().get(2).getName()); - - - attributeOverrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", elementCollectionResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", elementCollectionResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", elementCollectionResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "elementCollectionMapping"); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - XmlElementCollection_2_0 elementCollectionResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getElementCollections().get(0); - - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - elementCollectionResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - - elementCollectionResource.getAttributeOverrides().get(0).setName("FOO"); - elementCollectionResource.getAttributeOverrides().get(1).setName("BAR"); - elementCollectionResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().move(2, 0); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().move(0, 1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(1); - attributeOverrides = attributeOverrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - elementCollectionResource.getAttributeOverrides().remove(0); - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - } - - public void testElementCollectionMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmElementCollectionMapping2_0 ormElementCollectionMapping = (OrmElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - OrmAttributeOverrideContainer attributeOverrideContainer = ormElementCollectionMapping.getValueAttributeOverrideContainer(); - - assertEquals("foo", ormElementCollectionMapping.getName()); - - - assertFalse(attributeOverrideContainer.specifiedOverrides().hasNext()); - assertFalse(attributeOverrideContainer.virtualOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddableElementCollectionMapping(); - createTestTargetEmbeddableAddress(); - createTestEmbeddableState(); - - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType persistentType3 = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmReadOnlyPersistentAttribute ormPersistentAttribute = persistentType.getAttributeNamed("addresses"); - ElementCollectionMapping2_0 elementCollectionMapping = (ElementCollectionMapping2_0) ormPersistentAttribute.getMapping(); - AttributeOverrideContainer attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - ListIterator specifiedAttributeOverrides = (ListIterator) attributeOverrideContainer.specifiedOverrides(); - ReadOnlyAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - ListIterator virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - Column javaAttributeOverrideColumn = javaElementCollectionMapping.getValueAttributeOverrideContainer().specifiedOverrides().next().getColumn(); - - javaAttributeOverrideColumn.setSpecifiedName("FOO_COLUMN"); - javaAttributeOverrideColumn.setSpecifiedTable("FOO_TABLE"); - javaAttributeOverrideColumn.setColumnDefinition("COLUMN_DEF"); - javaAttributeOverrideColumn.setSpecifiedInsertable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUpdatable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedUnique(Boolean.TRUE); - javaAttributeOverrideColumn.setSpecifiedNullable(Boolean.FALSE); - javaAttributeOverrideColumn.setSpecifiedLength(Integer.valueOf(5)); - javaAttributeOverrideColumn.setSpecifiedPrecision(Integer.valueOf(6)); - javaAttributeOverrideColumn.setSpecifiedScale(Integer.valueOf(7)); - - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType3.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.specifiedOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEF", attributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, attributeOverride.getColumn().isInsertable()); - assertEquals(false, attributeOverride.getColumn().isUpdatable()); - assertEquals(true, attributeOverride.getColumn().isUnique()); - assertEquals(false, attributeOverride.getColumn().isNullable()); - assertEquals(5, attributeOverride.getColumn().getLength()); - assertEquals(6, attributeOverride.getColumn().getPrecision()); - assertEquals(7, attributeOverride.getColumn().getScale()); - - specifiedAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state.name", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state.abbr", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("addresses").convertToSpecified(); - elementCollectionMapping = (OrmElementCollectionMapping2_0) persistentType.getAttributeNamed("addresses").getMapping(); - attributeOverrideContainer = elementCollectionMapping.getValueAttributeOverrideContainer(); - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(4, attributeOverrideContainer.virtualOverridesSize()); - assertEquals(0, attributeOverrideContainer.specifiedOverridesSize()); - virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - ReadOnlyAttributeOverride virtualOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualOverride.getName()); - assertEquals("MY_STATE_COLUMN", virtualOverride.getColumn().getName()); - assertEquals(TYPE_NAME + "_addresses", virtualOverride.getColumn().getTable()); - assertEquals(null, virtualOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualOverride.getColumn().isInsertable()); - assertEquals(true, virtualOverride.getColumn().isUpdatable()); - assertEquals(false, virtualOverride.getColumn().isUnique()); - assertEquals(true, virtualOverride.getColumn().isNullable()); - assertEquals(255, virtualOverride.getColumn().getLength()); - assertEquals(0, virtualOverride.getColumn().getPrecision()); - assertEquals(0, virtualOverride.getColumn().getScale()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualOverride.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualOverride.getColumn().getDefaultTable()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - attributeOverrideContainer.virtualOverrides().next().convertToSpecified(); - - assertEquals(4, attributeOverrideContainer.overridesSize()); - assertEquals(1, attributeOverrideContainer.specifiedOverridesSize()); - assertEquals(3, attributeOverrideContainer.virtualOverridesSize()); - assertEquals("city", attributeOverrideContainer.specifiedOverrides().next().getName()); - virtualAttributeOverrides = (ListIterator) attributeOverrideContainer.virtualOverrides(); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.name", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("state.abbr", virtualOverride.getName()); - virtualOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualOverride.getName()); - } - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", virtualColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, virtualColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), virtualColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), virtualColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), virtualColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //no longer an element collection mapping - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmElementCollectionMapping2_0 addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaElementCollectionMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_addresses", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapElementCollectionMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ElementCollectionMapping2_0 addressesVirtualMapping = (ElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //entity table should have no affect on the collection table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getTable()); - - //set Column table element in Java - JavaElementCollectionMapping2_0 javaElementCollectionMapping = (JavaElementCollectionMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaElementCollectionMapping.getCollectionTable().setSpecifiedName("JAVA_COLLECTION_TABLE"); - assertEquals("JAVA_COLLECTION_TABLE", virtualColumn.getTable()); - javaElementCollectionMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", virtualColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmElementCollectionMapping2_0) addressesPersistentAttribute.getMapping(); - virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - assertNull(virtualColumn.getSpecifiedTable()); - assertEquals(TYPE_NAME + "_addresses", virtualColumn.getDefaultTable()); - } - - public void testSelfReferentialElementCollectionMapping() throws Exception { - createSelfReferentialElementCollection(); - OrmPersistentType persistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Foo"); - - ElementCollectionMapping2_0 mapping = (ElementCollectionMapping2_0) persistentType.getAttributeNamed("elementCollection").getMapping(); - assertFalse(mapping.allOverridableAttributeMappingNames().hasNext()); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmEntityTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmEntityTests.java deleted file mode 100644 index 0453b8d639..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmEntityTests.java +++ /dev/null @@ -1,1805 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.VirtualAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmVirtualAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmVirtualAttributeOverride; -import org.eclipse.jpt.core.jpa2.MappingKeys2_0; -import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkEntity; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMappedSuperclass; - -@SuppressWarnings("nls") -public class EclipseLink2_0OrmEntityTests extends EclipseLink2_0OrmContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public EclipseLink2_0OrmEntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE, JPA.MANY_TO_ONE, JPA.ONE_TO_MANY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int address3;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int address4;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestMappedSuperclassCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestMappedSuperclassCustomerWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("Customer "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEntityLongTimeCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("LongTimeCustomer extends Customer "); - sb.append("{}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "LongTimeCustomer.java", sourceWriter); - } - - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributes = entity.overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = entity.overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributeNames = entity.overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - - - entity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = entity.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributes = ormEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - OrmEntity abstractEntity = (OrmEntity) ormEntity.getParentEntity(); - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociations = ormEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - OrmEntity abstractEntity = (OrmEntity) ormEntity.getParentEntity(); - overridableAssociations = abstractEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } -//TODO -// public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { -// createTestMappedSuperclass(); -// createTestSubType(); -// addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); -// getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// Iterator overridableAttributes = getJavaEntity().allOverridableAttributes(); -// assertEquals("id", overridableAttributes.next().getName()); -// assertEquals("name", overridableAttributes.next().getName()); -// assertEquals("foo", overridableAttributes.next().getName()); -// assertFalse(overridableAttributes.hasNext()); -// } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAttributeNames = ormEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertEquals("foo", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - - ListIterator specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().add(1, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("BAZ"); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().move(1, 0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - specifiedAttributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testDefaultAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) ormEntity.getPersistentType().getSuperPersistentType().getMapping(); - - mappedSuperclass.getPersistentType().getAttributeNamed("id").convertToSpecified(); - BasicMapping idMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testDefaultAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - VirtualAttributeOverride virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - OrmEntity superclass = (OrmEntity) ormEntity.getParentEntity(); - - superclass.getPersistentType().getAttributeNamed("id").convertToSpecified(); - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(0, entityResource.getAttributeOverrides().size()); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(0, entityResource.getAttributeOverrides().size()); - - virtualAttributeOverride = overrideContainer.virtualOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride.convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("BAR"); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testDefaultAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.overridesSize()); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("bar"); - assertEquals(4, overrideContainer.overridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("id", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("name", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getAttributeOverrides().size()); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("foo", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals(2, entityResource.getAttributeOverrides().size()); - - Iterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - assertEquals("foo", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals(1, entityResource.getAttributeOverrides().size()); - - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - assertEquals(0, entityResource.getAttributeOverrides().size()); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals(3, entityResource.getAttributeOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(2, 0); - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - assertEquals("name", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("foo", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(2).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - assertEquals("foo", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("name", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("id", entityResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - entityResource.getAttributeOverrides().add(0, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().add(1, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().add(2, OrmFactory.eINSTANCE.createXmlAttributeOverride()); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(2, 0); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(0, 1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - attributeOverrides = overrideContainer.specifiedOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAttributeOverrideContainer overrideContainer = ormEntity.getAttributeOverrideContainer(); - - ListIterator virtualAttributeOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = overrideContainer.virtualOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity entity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociationNames = entity.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -// //TODO add all mapping types to the mapped superclass to test which ones are overridable - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociationNames = ormEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociationNames.next()); - assertEquals("address2", overridableAssociationNames.next()); - assertEquals("address3", overridableAssociationNames.next()); - assertEquals("address4", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociations() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - Iterator overridableAssociations = ormEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertEquals("address3", overridableAssociations.next()); - assertEquals("address4", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - //add an annotation to the resource model and verify the context model is updated - XmlAssociationOverride xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(0, xmlAssociationOverride); - xmlAssociationOverride.setName("FOO"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(1, xmlAssociationOverride); - xmlAssociationOverride.setName("BAR"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - xmlAssociationOverride = OrmFactory.eINSTANCE.createXmlAssociationOverride(); - entityResource.getAssociationOverrides().add(0, xmlAssociationOverride); - xmlAssociationOverride.setName("BAZ"); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - entityResource.getAssociationOverrides().move(1, 0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - entityResource.getAssociationOverrides().remove(0); - specifiedAssociationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testDefaultAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(FULLY_QUALIFIED_SUB_TYPE_NAME, entityResource.getClassName()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - OrmVirtualAssociationOverride virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - -// -// //MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); -// //BasicMapping idMapping = (BasicMapping) mappedSuperclass.persistentType().attributeNamed("id").getMapping(); -// //idMapping.getColumn().setSpecifiedName("FOO"); -// //idMapping.getColumn().setSpecifiedTable("BAR"); -// -// assertEquals(SUB_TYPE_NAME, entityResource.getName()); -// assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); -// assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - -// //idMapping.getColumn().setSpecifiedName(null); -// //idMapping.getColumn().setSpecifiedTable(null); -// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -// assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); -// assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride.convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals(0, overrideContainer.specifiedOverridesSize()); - - //add to the resource model and verify the context model is updated - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("BAR"); - - assertEquals(2, overrideContainer.specifiedOverridesSize()); - } - - public void testDefaultAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(3, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(2, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(1, overrideContainer.virtualOverridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(0, overrideContainer.virtualOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - assertEquals(4, overrideContainer.overridesSize()); - - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("bar"); - assertEquals(5, overrideContainer.overridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - AssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("address", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address2", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, entityResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals(2, entityResource.getAssociationOverrides().size()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(2, entityResource.getAssociationOverrides().size()); - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals(1, entityResource.getAssociationOverrides().size()); - - Iterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedOverrides().next().convertToVirtual(); - assertEquals(0, entityResource.getAssociationOverrides().size()); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - overrideContainer.virtualOverrides().next().convertToSpecified(); - - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(2, entityResource.getAssociationOverrides().size()); - - - overrideContainer.moveSpecifiedOverride(1, 0); - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - assertEquals("address2", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address", entityResource.getAssociationOverrides().get(1).getName()); - - - overrideContainer.moveSpecifiedOverride(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("address2", associationOverrides.next().getName()); - - assertEquals("address", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("address2", entityResource.getAssociationOverrides().get(1).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - - entityResource.getAssociationOverrides().add(0, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().add(1, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().add(2, OrmFactory.eINSTANCE.createXmlAssociationOverride()); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - ListIterator associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(2, 0); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(0, 1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = overrideContainer.specifiedOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - associationOverrides = overrideContainer.specifiedOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "test.AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmAssociationOverrideContainer overrideContainer = ormEntity.getAssociationOverrideContainer(); - - ListIterator virtualAssociationOverrides = overrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualOverrides().next().convertToSpecified(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.virtualOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address3", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address4", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - OrmPersistentType customerPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAttributeOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - - public void testNestedVirtualAttributeOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - OrmPersistentType customerPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - OrmPersistentType addressPersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentType zipCodePersistentType = getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - customerPersistentType.getJavaPersistentType().getAttributeNamed("address").setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); - OrmAttributeOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - - assertEquals(6, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAttributeOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.zip", virtualAttributeOverride.getName()); - assertEquals("zip", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("plusfour", virtualAttributeOverride.getColumn().getName()); - assertEquals("LongTimeCustomer", virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - zipCodePersistentType.getAttributeNamed("plusfour").convertToSpecified(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - //check the top-level embedded (Customer.address) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //set an attribute override on Address.zipCode embedded mapping - addressPersistentType.getAttributeNamed("zipCode").convertToSpecified(); - AttributeOverride specifiedAttributeOverride = ((VirtualAttributeOverride) ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getOverrideNamed("plusfour")).convertToSpecified(); - specifiedAttributeOverride.getColumn().setSpecifiedName("BLAH_OVERRIDE"); - specifiedAttributeOverride.getColumn().setSpecifiedTable("BLAH_TABLE_OVERRIDE"); - specifiedAttributeOverride.getColumn().setColumnDefinition("COLUMN_DEFINITION_OVERRIDE"); - - - attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAttributeOverrideContainer(); - virtualAttributeOverride = (OrmVirtualAttributeOverride) attributeOverrideContainer.getOverrideNamed("address.zipCode.plusfour"); - assertEquals("address.zipCode.plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH_OVERRIDE", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE_OVERRIDE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - specifiedAttributeOverride = virtualAttributeOverride.convertToSpecified(); - assertEquals(false, specifiedAttributeOverride.isVirtual()); - assertEquals("address.zipCode.plusfour", specifiedAttributeOverride.getName()); - //TODO I have the default wrong in this case, but this was wrong before as well. Need to fix this later -// assertEquals("plusfour", specifiedAttributeOverride.getColumn().getDefaultName()); - assertEquals("BLAH_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedName()); -// assertEquals("Customer", specifiedAttributeOverride.getColumn().getDefaultTable()); - assertEquals("BLAH_TABLE_OVERRIDE", specifiedAttributeOverride.getColumn().getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION_OVERRIDE", specifiedAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, specifiedAttributeOverride.getColumn().isInsertable()); - assertEquals(true, specifiedAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, specifiedAttributeOverride.getColumn().isUnique()); - assertEquals(true, specifiedAttributeOverride.getColumn().isNullable()); - assertEquals(255, specifiedAttributeOverride.getColumn().getLength()); - assertEquals(0, specifiedAttributeOverride.getColumn().getPrecision()); - assertEquals(0, specifiedAttributeOverride.getColumn().getScale()); - } - public void testNestedVirtualAssociationOverrides() throws Exception { - createTestMappedSuperclassCustomer(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAssociationOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testNestedVirtualAssociationOverridesElementCollection() throws Exception { - createTestMappedSuperclassCustomerWithElementCollection(); - createTestEntityLongTimeCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Customer"); - OrmPersistentType longTimeCustomerPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".LongTimeCustomer"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".ZipCode"); - - OrmAssociationOverrideContainer attributeOverrideContainer = ((OrmEntity) longTimeCustomerPersistentType.getMapping()).getAssociationOverrideContainer(); - - assertEquals(1, attributeOverrideContainer.virtualOverridesSize()); - ListIterator virtualAssociationOverrides = attributeOverrideContainer.virtualOverrides(); - OrmVirtualAssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address.state", virtualAssociationOverride.getName()); - } - - public void testSetSpecifiedCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable2_0 = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(null, cacheable2_0.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - - cacheable2_0.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable2_0.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, entityResource.getCacheable()); - - cacheable2_0.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable2_0.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, entityResource.getCacheable()); - - cacheable2_0.setSpecifiedCacheable(null); - assertEquals(null, cacheable2_0.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - } - - public void testGetSpecifiedCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlEntity entityResource = getXmlEntityMappings().getEntities().get(0); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - - entityResource.setCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, entityResource.getCacheable()); - - entityResource.setCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, entityResource.getCacheable()); - - entityResource.setCacheable(null); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, entityResource.getCacheable()); - } - - public void testIsDefaultCacheable() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - assertEquals(SharedCacheMode.DISABLE_SELECTIVE, persistenceUnit2_0.getSharedCacheMode()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.UNSPECIFIED); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromSuperType() throws Exception { - createTestEntity(); - createTestSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity subEntity = (EclipseLinkEntity) subOrmPersistentType.getMapping(); - EclipseLinkEntity entity = (EclipseLinkEntity) ormPersistentType.getMapping(); - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subEntity).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) entity).getCacheable(); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(null); - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromJava() throws Exception { - createTestEntity(); - createTestSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subOrmPersistentType.getMapping()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - - Cacheable2_0 javaCacheable = ((CacheableHolder2_0) ormPersistentType.getJavaPersistentType().getMapping()).getCacheable(); - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromMappedSuperClass() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkEntity subEntity = (EclipseLinkEntity) subOrmPersistentType.getMapping(); - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subEntity).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) mappedSuperclass).getCacheable(); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(null); - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java deleted file mode 100644 index 2fd4fc07af..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java +++ /dev/null @@ -1,963 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkManyToManyMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; - -@SuppressWarnings("nls") -public class EclipseLink2_0OrmManyToManyMappingTests - extends EclipseLink2_0OrmContextModelTestCase -{ - public EclipseLink2_0OrmManyToManyMappingTests(String name) { - super(name); - } - - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKey(OrmFactory.eINSTANCE.createMapKey()); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNotNull(manyToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKey().setName(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey().getName()); - - manyToMany.getMapKey().setName("myMapKey"); - manyToMany.setMapKey(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualManyToManyMapping.getSpecifiedMapKey()); - assertNull(virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertTrue(virtualManyToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setPkMapKey(true); - assertEquals("id", virtualManyToManyMapping.getMapKey()); - assertTrue(virtualManyToManyMapping.isPkMapKey()); - assertFalse(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setCustomMapKey(true); - javaManyToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualManyToManyMapping.getSpecifiedMapKey()); - assertEquals("city", virtualManyToManyMapping.getMapKey()); - assertFalse(virtualManyToManyMapping.isPkMapKey()); - assertTrue(virtualManyToManyMapping.isCustomMapKey()); - assertFalse(virtualManyToManyMapping.isNoMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedMapKey("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setSpecifiedMapKey(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKey()); - assertNull(manyToMany.getMapKey().getName()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = - virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - OrmManyToManyMapping specifiedManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = specifiedManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - specifiedManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = specifiedManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.foo", mapKeyNames.next()); - assertEquals("state.address", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - specifiedManyToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = specifiedManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNotNull(manyToMany.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKeyClass().setClassName("String"); - assertEquals("String", ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", manyToMany.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKeyClass().setClassName(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass().getClassName()); - - manyToMany.getMapKeyClass().setClassName("String"); - manyToMany.setMapKeyClass(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - ManyToManyMapping2_0 virtualManyToManyMapping = (ManyToManyMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertEquals("java.lang.String", virtualManyToManyMapping.getMapKeyClass()); - assertNull(virtualManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualManyToManyMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaManyToManyMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", virtualManyToManyMapping.getMapKeyClass()); - assertEquals("Integer", virtualManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualManyToManyMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping2_0 ormManyToManyMapping = (OrmManyToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", manyToMany.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(ormManyToManyMapping.getSpecifiedMapKeyClass()); - assertNull(manyToMany.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType printQueuePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - OrmPersistentAttribute jobsPersistentAttribute = printQueuePersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmManyToManyMapping jobsMapping = (OrmManyToManyMapping) jobsPersistentAttribute.getMapping(); - jobsMapping.getRelationship().setStrategyToMappedBy(); - jobsMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("queues"); - - OrmPersistentType printJobPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute queuesPersistentAttribute = printJobPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "queues"); - OrmManyToManyMapping queuesMapping = (OrmManyToManyMapping) queuesPersistentAttribute.getMapping(); - - getOrmXmlResource().save(null); - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - OrderColumn2_0 jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - OrderColumn2_0 queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - - jobsOrderable.setOrderColumnOrdering(true); - jobsOrderColumn = jobsOrderable.getOrderColumn(); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(null, jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderable.setOrderColumnOrdering(true); - queuesOrderColumn = queuesOrderable.getOrderColumn(); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(null, queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - jobsOrderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", jobsOrderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", jobsOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", jobsOrderColumn.getTable()); - queuesOrderColumn.setSpecifiedName("BAR"); - assertEquals("BAR", queuesOrderColumn.getSpecifiedName()); - assertEquals("queues_ORDER", queuesOrderColumn.getDefaultName()); - assertEquals("PrintJob_PrintQueue", queuesOrderColumn.getTable()); - - - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - assertEquals("MY_TABLE_PrintQueue", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_PrintQueue", queuesOrderColumn.getTable()); - - ((Entity) printQueuePersistentType.getMapping()).getTable().setSpecifiedName("OTHER_TABLE"); - assertEquals("MY_TABLE_OTHER_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_TABLE_OTHER_TABLE", queuesOrderColumn.getTable()); - - queuesMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - assertEquals("MY_JOIN_TABLE", jobsOrderColumn.getTable()); - assertEquals("MY_JOIN_TABLE", queuesOrderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType printQueuePersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - OrmPersistentAttribute jobsPersistentAttribute = printQueuePersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmManyToManyMapping jobsMapping = (OrmManyToManyMapping) jobsPersistentAttribute.getMapping(); - - OrmPersistentType printJobPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute queuesPersistentAttribute = printJobPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "queues"); - OrmManyToManyMapping queuesMapping = (OrmManyToManyMapping) queuesPersistentAttribute.getMapping(); - - Orderable2_0 jobsOrderable = ((Orderable2_0) jobsMapping.getOrderable()); - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - Orderable2_0 queuesOrderable = ((Orderable2_0) queuesMapping.getOrderable()); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - JavaManyToManyMapping javaJobsManyToManyMapping = (JavaManyToManyMapping) jobsPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaJobsManyToManyMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, jobsOrderable.isOrderColumnOrdering()); - assertEquals(true, jobsOrderable.isNoOrdering()); - assertEquals(false, queuesOrderable.isOrderColumnOrdering()); - assertEquals(true, queuesOrderable.isNoOrdering()); - - jobsPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute jobsPersistentAttribute2 = printQueuePersistentType.getAttributeNamed("jobs"); - ManyToManyMapping virtualJobsMapping = (ManyToManyMapping) jobsPersistentAttribute2.getMapping(); - jobsOrderable = ((Orderable2_0) virtualJobsMapping.getOrderable()); - assertEquals(true, jobsOrderable.isOrderColumnOrdering()); - assertEquals(false, jobsOrderable.isNoOrdering()); - assertEquals("PrintJob_PrintQueue", jobsOrderable.getOrderColumn().getTable()); - assertEquals("jobs_ORDER", jobsOrderable.getOrderColumn().getName()); - queuesPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute queuesPersistentAttribute2 = printJobPersistentType.getAttributeNamed("queues"); - ManyToManyMapping virtualQueuesMapping = (ManyToManyMapping) queuesPersistentAttribute2.getMapping(); - queuesOrderable = ((Orderable2_0) virtualQueuesMapping.getOrderable()); - assertEquals(true, queuesOrderable.isOrderColumnOrdering()); - assertEquals(false, queuesOrderable.isNoOrdering()); - assertEquals("PrintJob_PrintQueue", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - - ((Orderable2_0) javaJobsManyToManyMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals("PrintJob_PrintQueue", jobsOrderable.getOrderColumn().getTable()); - assertEquals("FOO", jobsOrderable.getOrderColumn().getName()); - assertEquals("PrintJob_PrintQueue", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - - JavaManyToManyMapping javaQueuesManyToManyMapping = (JavaManyToManyMapping) queuesPersistentAttribute2.getJavaPersistentAttribute().getMapping(); - javaQueuesManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JOIN_TABLE"); - assertEquals("JOIN_TABLE", jobsOrderable.getOrderColumn().getTable()); - assertEquals("FOO", jobsOrderable.getOrderColumn().getName()); - assertEquals("JOIN_TABLE", queuesOrderable.getOrderColumn().getTable()); - assertEquals("queues_ORDER", queuesOrderable.getOrderColumn().getName()); - } - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany(mappedBy=\"queues\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List queues;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ManyToManyMapping2_0 addressesVirtualMapping = (ManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column virtualColumn = addressesVirtualMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_Address", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - - //set Column annotation in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaManyToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", virtualColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", virtualColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", virtualColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, virtualColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, virtualColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), virtualColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), virtualColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), virtualColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - //becomes a 1-m by default - OneToManyMapping2_0 addressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - virtualColumn = addressesMapping.getMapKeyColumn(); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - - assertEquals("addresses_KEY", virtualColumn.getName()); - assertEquals(TYPE_NAME + "_Address", virtualColumn.getTable()); - assertEquals(null, virtualColumn.getColumnDefinition()); - assertTrue(virtualColumn.isInsertable()); - assertTrue(virtualColumn.isUpdatable()); - assertTrue(virtualColumn.isNullable()); - assertFalse(virtualColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, virtualColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, virtualColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, virtualColumn.getScale()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmManyToManyMapping2_0 addressesVirtualMapping = (OrmManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaManyToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ManyToManyMapping2_0 addressesVirtualMapping = (ManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_Address", ormColumn.getTable()); - - //entity table changes the join table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE_Address", ormColumn.getTable()); - - //set Column table element in Java - JavaManyToManyMapping2_0 javaManyToManyMapping = (JavaManyToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaManyToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - assertEquals("JAVA_JOIN_TABLE", ormColumn.getTable()); - javaManyToManyMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", ormColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - addressesVirtualMapping = (OrmManyToManyMapping2_0) addressesPersistentAttribute.getMapping(); - ormColumn = addressesVirtualMapping.getMapKeyColumn(); - assertNull(ormColumn.getSpecifiedTable()); - assertEquals("ORM_TABLE_Address", ormColumn.getDefaultTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToManyMapping virtualManyToManyMapping = (ManyToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualManyToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualManyToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualManyToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) virtualManyToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(virtualManyToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertEquals(EclipseLinkJoinFetchType.INNER, ((EclipseLinkJoinFetchMapping) virtualManyToManyMapping).getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - OrmPersistentAttribute ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmEclipseLinkManyToManyMapping ormManyToManyMapping = (OrmEclipseLinkManyToManyMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToManyMapping.getName()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch()); - assertEquals("test.Address", ormManyToManyMapping.getTargetEntity()); - assertNull(ormManyToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) ormManyToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertEquals(null, ormManyToManyMapping.getJoinFetch().getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmMappedSuperclassTests.java deleted file mode 100644 index 1fa8c9e46c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmMappedSuperclassTests.java +++ /dev/null @@ -1,2375 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; -import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.options.SharedCacheMode; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheCoordinationType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCacheType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkExistenceType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkStructConverter; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkTypeConverter; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkCaching; -import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkConverterContainer; -import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlChangeTrackingType; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlObjectTypeConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlStructConverter; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTypeConverter; - -@SuppressWarnings("nls") -public class EclipseLink2_0OrmMappedSuperclassTests extends EclipseLink2_0OrmContextModelTestCase -{ - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - public EclipseLink2_0OrmMappedSuperclassTests(String name) { - super(name); - } - - - private ICompilationUnit createTestMappedSuperclassForReadOnly() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.READ_ONLY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForCustomizer() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CUSTOMIZER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForChangeTracking() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS, EclipseLink.CHANGE_TRACKING); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private void createTestMappedSuperclassSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private ICompilationUnit createTestMappedSuperclassForConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForObjectTypeConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassForStructConverters() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass").append(CR); - } - }); - } - - public void testUpdateReadOnly() throws Exception { - createTestMappedSuperclassForReadOnly(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkMappedSuperclass javaContextMappedSuperclass = (JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to false, check override - - resourceMappedSuperclass.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceMappedSuperclass.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // clear xml read only, set java read only to true, check defaults - - resourceMappedSuperclass.setReadOnly(null); - javaContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - // set xml read only to false, check override - - resourceMappedSuperclass.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceMappedSuperclass.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertTrue(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // clear xml read only, set java read only to false, check defaults - - resourceMappedSuperclass.setReadOnly(null); - javaContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.FALSE); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to false, check override - - resourceMappedSuperclass.setReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set xml read only to true, check override - - resourceMappedSuperclass.setReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertFalse(javaContextMappedSuperclass.getReadOnly().isReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - } - - public void testModifyReadOnly() throws Exception { - createTestMappedSuperclassForReadOnly(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to true, check resource - - ormContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getReadOnly()); - assertTrue(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.TRUE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to false, check resource - - ormContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertEquals(Boolean.FALSE, ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - - // set context read only to null, check resource - - ormContextMappedSuperclass.getReadOnly().setSpecifiedReadOnly(null); - - assertNull(resourceMappedSuperclass.getReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isReadOnly()); - assertFalse(ormContextMappedSuperclass.getReadOnly().isDefaultReadOnly()); - assertNull(ormContextMappedSuperclass.getReadOnly().getSpecifiedReadOnly()); - } - - public void testUpdateCustomizerClass() throws Exception { - createTestMappedSuperclassForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkMappedSuperclass javaContextMappedSuperclass = (JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set xml customizer, check defaults - resourceMappedSuperclass.setCustomizer(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(resourceMappedSuperclass.getCustomizer().getClassName()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - - // set xml customizer class, check override - - resourceMappedSuperclass.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceMappedSuperclass.getCustomizer().getClassName()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // clear xml customizer class, set java customizer class, check defaults - - resourceMappedSuperclass.getCustomizer().setClassName(null); - javaContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass("bar"); - - assertNull(resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("bar", javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("bar", javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - // set xml customizer class, check override - - resourceMappedSuperclass.getCustomizer().setClassName("foo"); - - assertEquals("foo", resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("bar", javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertEquals("bar", ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - //set xml customizer null - javaContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass(null); - resourceMappedSuperclass.setCustomizer(null); - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(javaContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - } - - public void testModifyCustomizerClass() throws Exception { - createTestMappedSuperclassForCustomizer(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer, check resource - - ormContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass("foo"); - - assertEquals("foo", resourceMappedSuperclass.getCustomizer().getClassName()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertEquals("foo", ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - - // set context customizer to null, check resource - - ormContextMappedSuperclass.getCustomizer().setSpecifiedCustomizerClass(null); - - assertNull(resourceMappedSuperclass.getCustomizer()); - assertNull(ormContextMappedSuperclass.getCustomizer().getCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getDefaultCustomizerClass()); - assertNull(ormContextMappedSuperclass.getCustomizer().getSpecifiedCustomizerClass()); - } - - public void testUpdateChangeTracking() throws Exception { - createTestMappedSuperclassForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkMappedSuperclass javaContextMappedSuperclass = (JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to ATTRIBUTE, check context - - resourceMappedSuperclass.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to OBJECT, check context - - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to DEFERRED, check context - - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set xml type to AUTO, check context - - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // clear xml change tracking, set java change tracking, check defaults - - resourceMappedSuperclass.setChangeTracking(null); - javaContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // unset metadataComplete, set xml change tracking to OBJECT, check context - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - resourceMappedSuperclass.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking()); - resourceMappedSuperclass.getChangeTracking().setType(XmlChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, javaContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - } - - public void testModifyChangeTracking() throws Exception { - createTestMappedSuperclassForChangeTracking(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to ATTRIBUTE, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.ATTRIBUTE); - - assertEquals(XmlChangeTrackingType.ATTRIBUTE, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.ATTRIBUTE, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to OBJECT, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.OBJECT); - - assertEquals(XmlChangeTrackingType.OBJECT, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.OBJECT, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to DEFERRED, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.DEFERRED); - - assertEquals(XmlChangeTrackingType.DEFERRED, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.DEFERRED, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to AUTO, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(EclipseLinkChangeTrackingType.AUTO); - - assertEquals(XmlChangeTrackingType.AUTO, resourceMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - - // set context change tracking to null, check resource - - ormContextMappedSuperclass.getChangeTracking().setSpecifiedType(null); - - assertNull(resourceMappedSuperclass.getChangeTracking()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getType()); - assertEquals(EclipseLinkChangeTrackingType.AUTO, ormContextMappedSuperclass.getChangeTracking().getDefaultType()); - assertNull(ormContextMappedSuperclass.getChangeTracking().getSpecifiedType()); - } - - public void testUpdateCacheType() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // set xml cache type, check settings - resourceMappedSuperclass.getCache().setType(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getSpecifiedType()); - - - // set java cache type, check defaults - - javaContextCaching.setSpecifiedType(EclipseLinkCacheType.WEAK); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.FULL, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.FULL, ormContextCaching.getSpecifiedType()); - - // clear xml cache type, check defaults - resourceMappedSuperclass.getCache().setType(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.WEAK, javaContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheType() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - - // set context cache type, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedType(EclipseLinkCacheType.HARD_WEAK); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheType.HARD_WEAK, resourceMappedSuperclass.getCache().getType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(EclipseLinkCacheType.HARD_WEAK, ormContextCaching.getSpecifiedType()); - - // set context customizer to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedType(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getType()); - assertEquals(EclipseLinkCacheType.SOFT_WEAK, ormContextCaching.getDefaultType()); - assertEquals(null, ormContextCaching.getSpecifiedType()); - } - - public void testUpdateCacheCoordinationType() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // set xml cache type, check settings - resourceMappedSuperclass.getCache().setCoordinationType(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getSpecifiedCoordinationType()); - - - // set java cache type, check defaults - - javaContextCaching.setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.INVALIDATE_CHANGED_OBJECTS, ormContextCaching.getSpecifiedCoordinationType()); - - // clear xml cache type, check defaults - resourceMappedSuperclass.getCache().setCoordinationType(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, javaContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheCoordinationType() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - - // set context cache coordination type, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedCoordinationType(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, resourceMappedSuperclass.getCache().getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, ormContextCaching.getSpecifiedCoordinationType()); - - // set context coordination type to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedCoordinationType(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getCoordinationType()); - assertEquals(EclipseLinkCacheCoordinationType.SEND_OBJECT_CHANGES, ormContextCaching.getDefaultCoordinationType()); - assertEquals(null, ormContextCaching.getSpecifiedCoordinationType()); - } - - - public void testUpdateCacheSize() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass xmlMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, xmlMappedSuperclass.getCache()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - // set xml cache, check defaults - xmlMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, xmlMappedSuperclass.getCache().getSize()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // set xml cache size, check settings - xmlMappedSuperclass.getCache().setSize(new Integer(105)); - assertEquals(new Integer(105), xmlMappedSuperclass.getCache().getSize()); - assertEquals(100, javaContextCaching.getSize()); - assertEquals(105, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(105), ormContextCaching.getSpecifiedSize()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedSize(new Integer(50)); - - assertEquals(new Integer(105), xmlMappedSuperclass.getCache().getSize()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(105, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(105), ormContextCaching.getSpecifiedSize()); - - // clear xml cache size, check defaults - xmlMappedSuperclass.getCache().setSize(null); - - assertEquals(null, xmlMappedSuperclass.getCache().getSize()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // clear xml cache, check defaults - xmlMappedSuperclass.setCache(null); - - assertEquals(null, xmlMappedSuperclass.getCache()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(50, ormContextCaching.getSize()); - assertEquals(50, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, xmlMappedSuperclass.getCache()); - assertEquals(50, javaContextCaching.getSize()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyCacheSize() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedSize(new Integer(50)); - assertEquals(new Integer(50), resourceMappedSuperclass.getCache().getSize()); - assertEquals(50, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(new Integer(50), ormContextCaching.getSpecifiedSize()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedSize(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(100, ormContextCaching.getSize()); - assertEquals(100, ormContextCaching.getDefaultSize()); - assertEquals(null, ormContextCaching.getSpecifiedSize()); - } - - public void testUpdateCacheAlwaysRefresh() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set xml cache always refresh, check settings - resourceMappedSuperclass.getCache().setAlwaysRefresh(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(false, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set java cache always refresh, check defaults - - javaContextCaching.setSpecifiedAlwaysRefresh(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setAlwaysRefresh(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setAlwaysRefresh(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(true, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - } - - public void testModifyCacheAlwaysRefresh() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedAlwaysRefresh(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getAlwaysRefresh()); - assertEquals(true, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedAlwaysRefresh()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedAlwaysRefresh(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isAlwaysRefresh()); - assertEquals(false, ormContextCaching.isDefaultAlwaysRefresh()); - assertEquals(null, ormContextCaching.getSpecifiedAlwaysRefresh()); - } - - public void testUpdateCacheRefreshOnlyIfNewer() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set xml cache size, check settings - resourceMappedSuperclass.getCache().setRefreshOnlyIfNewer(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(false, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setRefreshOnlyIfNewer(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setRefreshOnlyIfNewer(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - } - - public void testModifyCacheRefreshOnlyIfNewer() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedRefreshOnlyIfNewer(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getRefreshOnlyIfNewer()); - assertEquals(true, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedRefreshOnlyIfNewer(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isRefreshOnlyIfNewer()); - assertEquals(false, ormContextCaching.isDefaultRefreshOnlyIfNewer()); - assertEquals(null, ormContextCaching.getSpecifiedRefreshOnlyIfNewer()); - } - - public void testUpdateCacheDisableHits() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set xml cache size, check settings - resourceMappedSuperclass.getCache().setDisableHits(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(false, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedDisableHits(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setDisableHits(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedDisableHits()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setDisableHits(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(true, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - } - - public void testModifyCacheDisableHits() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedDisableHits(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getDisableHits()); - assertEquals(true, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedDisableHits()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedDisableHits(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, ormContextCaching.isDisableHits()); - assertEquals(false, ormContextCaching.isDefaultDisableHits()); - assertEquals(null, ormContextCaching.getSpecifiedDisableHits()); - } - - public void testUpdateCacheShared() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - // set xml cache, check defaults - resourceMappedSuperclass.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache()); - assertEquals(null, resourceMappedSuperclass.getCache().getShared()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set xml cache size, check settings - resourceMappedSuperclass.getCache().setShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(true, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - - // set java cache size, check defaults - - javaContextCaching.setSpecifiedShared(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - // set xml cache always refresh to false - resourceMappedSuperclass.getCache().setShared(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.TRUE, ormContextCaching.getSpecifiedShared()); - - // clear xml cache always refresh, check defaults - resourceMappedSuperclass.getCache().setShared(null); - - assertEquals(null, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // clear xml cache, check defaults - resourceMappedSuperclass.setCache(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(false, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - - // set metadataComplete back to null, check defaults from java - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(false, javaContextCaching.isShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(false, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - } - - public void testModifyCacheShared() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - - // set context cache size, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedShared(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMappedSuperclass.getCache().getShared()); - assertEquals(false, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(Boolean.FALSE, ormContextCaching.getSpecifiedShared()); - - // set context cache size to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedShared(null); - - assertEquals(null, resourceMappedSuperclass.getCache()); - assertEquals(true, ormContextCaching.isShared()); - assertEquals(true, ormContextCaching.isDefaultShared()); - assertEquals(null, ormContextCaching.getSpecifiedShared()); - } - - public void testUpdateExistenceChecking() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaEclipseLinkCaching javaContextCaching = ((JavaEclipseLinkMappedSuperclass) ormPersistentType.getJavaPersistentType().getMapping()).getCaching(); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set xml existence checking, check settings - resourceMappedSuperclass.setExistenceChecking(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - - // set java cache existence checking, check defaults - - javaContextCaching.setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE); - - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - // clear xml existence checking, check defaults - resourceMappedSuperclass.setExistenceChecking(null); - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set metadataComplete to True, check defaults not from java - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_NON_EXISTENCE, javaContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - ormContextMappedSuperclass.setSpecifiedMetadataComplete(null); - } - - public void testModifyExistenceChecking() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - EclipseLinkCaching ormContextCaching = ormContextMappedSuperclass.getCaching(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - // check defaults - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - - // set context cache existence checking, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedExistenceType(EclipseLinkExistenceType.ASSUME_EXISTENCE); - assertEquals(org.eclipse.jpt.eclipselink.core.resource.orm.ExistenceType.ASSUME_EXISTENCE, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(EclipseLinkExistenceType.ASSUME_EXISTENCE, ormContextCaching.getSpecifiedExistenceType()); - - // set context existence checking to null, check resource - - ormContextMappedSuperclass.getCaching().setSpecifiedExistenceType(null); - - assertEquals(null, resourceMappedSuperclass.getExistenceChecking()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getExistenceType()); - assertEquals(EclipseLinkExistenceType.CHECK_DATABASE, ormContextCaching.getDefaultExistenceType()); - assertEquals(null, ormContextCaching.getSpecifiedExistenceType()); - } - public void testUpdateCustomConverters() throws Exception { - createTestMappedSuperclassForConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlConverter resourceConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceMappedSuperclass.getConverters().add(resourceConverter); - resourceConverter.setClassName("Foo"); - resourceConverter.setName("myConverter"); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlConverter resourceConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlConverter(); - resourceMappedSuperclass.getConverters().add(0, resourceConverter2); - resourceConverter2.setClassName("Foo2"); - resourceConverter2.setName("myConverter2"); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getConverters().remove(resourceConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyCustomConverters() throws Exception { - createTestMappedSuperclassForConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter = ormContextConverterHolder.addCustomConverter(0); - contextConverter.setConverterClass("Foo"); - contextConverter.setName("myConverter"); - - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ListIterator ormContextConverters = ormContextConverterHolder.customConverters(); - EclipseLinkCustomConverter ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkCustomConverter contextConverter2 = ormContextConverterHolder.addCustomConverter(0); - contextConverter2.setConverterClass("Foo2"); - contextConverter2.setName("myConverter2"); - - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getConverters().get(1).getClassName()); - assertEquals("myConverter", resourceMappedSuperclass.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveCustomConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getConverters().get(1).getClassName()); - assertEquals("myConverter2", resourceMappedSuperclass.getConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo", ormContextConverter.getConverterClass()); - assertEquals("myConverter", ormContextConverter.getName()); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(0); - - assertEquals(1, resourceMappedSuperclass.getConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getConverters().get(0).getClassName()); - assertEquals("myConverter2", resourceMappedSuperclass.getConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.customConvertersSize()); - ormContextConverters = ormContextConverterHolder.customConverters(); - ormContextConverter = ormContextConverters.next(); - assertEquals("Foo2", ormContextConverter.getConverterClass()); - assertEquals("myConverter2", ormContextConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeCustomConverter(contextConverter2); - - assertEquals(0, ormContextConverterHolder.customConvertersSize()); - assertFalse(ormContextConverterHolder.customConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateTypeConverters() throws Exception { - createTestMappedSuperclassForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceMappedSuperclass.getTypeConverters().add(resourceTypeConverter); - resourceTypeConverter.setDataType("Foo"); - resourceTypeConverter.setName("myTypeConverter"); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlTypeConverter resourceTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlTypeConverter(); - resourceMappedSuperclass.getTypeConverters().add(0, resourceTypeConverter2); - resourceTypeConverter2.setDataType("Foo2"); - resourceTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getTypeConverters().remove(resourceTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyTypeConverters() throws Exception { - createTestMappedSuperclassForTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter.setDataType("Foo"); - contextTypeConverter.setName("myTypeConverter"); - - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ListIterator ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - EclipseLinkTypeConverter ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkTypeConverter contextTypeConverter2 = ormContextConverterHolder.addTypeConverter(0); - contextTypeConverter2.setDataType("Foo2"); - contextTypeConverter2.setName("myTypeConverter2"); - - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter", resourceMappedSuperclass.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveTypeConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getTypeConverters().get(1).getDataType()); - assertEquals("myTypeConverter2", resourceMappedSuperclass.getTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter", ormContextTypeConverter.getName()); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(0); - - assertEquals(1, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getTypeConverters().get(0).getDataType()); - assertEquals("myTypeConverter2", resourceMappedSuperclass.getTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.typeConvertersSize()); - ormContextTypeConverters = ormContextConverterHolder.typeConverters(); - ormContextTypeConverter = ormContextTypeConverters.next(); - assertEquals("Foo2", ormContextTypeConverter.getDataType()); - assertEquals("myTypeConverter2", ormContextTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeTypeConverter(contextTypeConverter2); - - assertEquals(0, ormContextConverterHolder.typeConvertersSize()); - assertFalse(ormContextConverterHolder.typeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateObjectTypeConverters() throws Exception { - createTestMappedSuperclassForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceMappedSuperclass.getObjectTypeConverters().add(resourceObjectTypeConverter); - resourceObjectTypeConverter.setDataType("Foo"); - resourceObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlObjectTypeConverter resourceObjectTypeConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlObjectTypeConverter(); - resourceMappedSuperclass.getObjectTypeConverters().add(0, resourceObjectTypeConverter2); - resourceObjectTypeConverter2.setDataType("Foo2"); - resourceObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getObjectTypeConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getObjectTypeConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getObjectTypeConverters().remove(resourceObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyObjectTypeConverters() throws Exception { - createTestMappedSuperclassForObjectTypeConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter.setDataType("Foo"); - contextObjectTypeConverter.setName("myObjectTypeConverter"); - - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ListIterator ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - EclipseLinkObjectTypeConverter ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkObjectTypeConverter contextObjectTypeConverter2 = ormContextConverterHolder.addObjectTypeConverter(0); - contextObjectTypeConverter2.setDataType("Foo2"); - contextObjectTypeConverter2.setName("myObjectTypeConverter2"); - - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter", resourceMappedSuperclass.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveObjectTypeConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getObjectTypeConverters().get(1).getDataType()); - assertEquals("myObjectTypeConverter2", resourceMappedSuperclass.getObjectTypeConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter", ormContextObjectTypeConverter.getName()); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(0); - - assertEquals(1, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getDataType()); - assertEquals("myObjectTypeConverter2", resourceMappedSuperclass.getObjectTypeConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.objectTypeConvertersSize()); - ormContextObjectTypeConverters = ormContextConverterHolder.objectTypeConverters(); - ormContextObjectTypeConverter = ormContextObjectTypeConverters.next(); - assertEquals("Foo2", ormContextObjectTypeConverter.getDataType()); - assertEquals("myObjectTypeConverter2", ormContextObjectTypeConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeObjectTypeConverter(contextObjectTypeConverter2); - - assertEquals(0, ormContextConverterHolder.objectTypeConvertersSize()); - assertFalse(ormContextConverterHolder.objectTypeConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getObjectTypeConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testUpdateStructConverters() throws Exception { - createTestMappedSuperclassForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the resource model, check context model - XmlStructConverter resourceStructConverter = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceMappedSuperclass.getStructConverters().add(resourceStructConverter); - resourceStructConverter.setConverter("Foo"); - resourceStructConverter.setName("myStructConverter"); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the resource model, check context model - XmlStructConverter resourceStructConverter2 = EclipseLinkOrmFactory.eINSTANCE.createXmlStructConverter(); - resourceMappedSuperclass.getStructConverters().add(0, resourceStructConverter2); - resourceStructConverter2.setConverter("Foo2"); - resourceStructConverter2.setName("myStructConverter2"); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the resource model, check context model - resourceMappedSuperclass.getStructConverters().move(0, 1); - - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getStructConverters().remove(0); - - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the resource model, check context model - resourceMappedSuperclass.getStructConverters().remove(resourceStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testModifyStructConverters() throws Exception { - createTestMappedSuperclassForStructConverters(); - EclipseLinkPersistenceUnit persistenceUnit = getPersistenceUnit(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEclipseLinkMappedSuperclass ormContextMappedSuperclass = (OrmEclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - OrmEclipseLinkConverterContainer ormContextConverterHolder = ormContextMappedSuperclass.getConverterContainer(); - XmlMappedSuperclass resourceMappedSuperclass = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - - //add a converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter = ormContextConverterHolder.addStructConverter(0); - contextStructConverter.setConverterClass("Foo"); - contextStructConverter.setName("myStructConverter"); - - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ListIterator ormContextStructConverters = ormContextConverterHolder.structConverters(); - EclipseLinkStructConverter ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //add another converter to the context model, check resource model - EclipseLinkStructConverter contextStructConverter2 = ormContextConverterHolder.addStructConverter(0); - contextStructConverter2.setConverterClass("Foo2"); - contextStructConverter2.setName("myStructConverter2"); - - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals("Foo", resourceMappedSuperclass.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter", resourceMappedSuperclass.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //move a converter in the context model, check resource model - ormContextConverterHolder.moveStructConverter(0, 1); - - assertEquals(2, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals("Foo2", resourceMappedSuperclass.getStructConverters().get(1).getConverter()); - assertEquals("myStructConverter2", resourceMappedSuperclass.getStructConverters().get(1).getName()); - assertEquals(2, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter", ormContextStructConverter.getName()); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(2, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(0); - - assertEquals(1, resourceMappedSuperclass.getStructConverters().size()); - assertEquals("Foo2", resourceMappedSuperclass.getStructConverters().get(0).getConverter()); - assertEquals("myStructConverter2", resourceMappedSuperclass.getStructConverters().get(0).getName()); - assertEquals(1, ormContextConverterHolder.structConvertersSize()); - ormContextStructConverters = ormContextConverterHolder.structConverters(); - ormContextStructConverter = ormContextStructConverters.next(); - assertEquals("Foo2", ormContextStructConverter.getConverterClass()); - assertEquals("myStructConverter2", ormContextStructConverter.getName()); - assertEquals(1, CollectionTools.size(persistenceUnit.allConverters())); - - //remove a converter from the context model, check resource model - ormContextConverterHolder.removeStructConverter(contextStructConverter2); - - assertEquals(0, ormContextConverterHolder.structConvertersSize()); - assertFalse(ormContextConverterHolder.structConverters().hasNext()); - assertEquals(0, resourceMappedSuperclass.getStructConverters().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.allConverters())); - } - - public void testSetSpecifiedCacheable() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable2_0 = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlMappedSuperclass mappedSuperclassResource = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals(null, cacheable2_0.getSpecifiedCacheable()); - assertEquals(null, mappedSuperclassResource.getCacheable()); - - cacheable2_0.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable2_0.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, mappedSuperclassResource.getCacheable()); - - cacheable2_0.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable2_0.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, mappedSuperclassResource.getCacheable()); - - cacheable2_0.setSpecifiedCacheable(null); - assertEquals(null, cacheable2_0.getSpecifiedCacheable()); - assertEquals(null, mappedSuperclassResource.getCacheable()); - } - - public void testGetSpecifiedCacheable() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - XmlMappedSuperclass mappedSuperclassResource = (XmlMappedSuperclass) getXmlEntityMappings().getMappedSuperclasses().get(0); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, mappedSuperclassResource.getCacheable()); - - mappedSuperclassResource.setCacheable(Boolean.TRUE); - assertEquals(Boolean.TRUE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.TRUE, mappedSuperclassResource.getCacheable()); - - mappedSuperclassResource.setCacheable(Boolean.FALSE); - assertEquals(Boolean.FALSE, cacheable.getSpecifiedCacheable()); - assertEquals(Boolean.FALSE, mappedSuperclassResource.getCacheable()); - - mappedSuperclassResource.setCacheable(null); - assertEquals(null, cacheable.getSpecifiedCacheable()); - assertEquals(null, mappedSuperclassResource.getCacheable()); - } - - public void testIsDefaultCacheable() throws Exception { - createTestMappedSuperclass(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - assertEquals(SharedCacheMode.DISABLE_SELECTIVE, persistenceUnit2_0.getSharedCacheMode()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ALL); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.UNSPECIFIED); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromSuperType() throws Exception { - createTestMappedSuperclass(); - createTestMappedSuperclassSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass subMappedSuperclass = (EclipseLinkMappedSuperclass) subOrmPersistentType.getMapping(); - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subMappedSuperclass).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) mappedSuperclass).getCacheable(); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(null); - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromJava() throws Exception { - createTestMappedSuperclass(); - createTestMappedSuperclassSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subOrmPersistentType.getMapping()).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) ormPersistentType.getMapping()).getCacheable(); - - Cacheable2_0 javaCacheable = ((CacheableHolder2_0) ormPersistentType.getJavaPersistentType().getMapping()).getCacheable(); - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - javaCacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - } - - public void testIsDefaultCacheableFromMappedSuperClass() throws Exception { - createTestMappedSuperclass(); - createTestMappedSuperclassSubType(); - OrmPersistentType subOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_SUB_TYPE_NAME); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - EclipseLinkMappedSuperclass subMappedSuperclass = (EclipseLinkMappedSuperclass) subOrmPersistentType.getMapping(); - EclipseLinkMappedSuperclass mappedSuperclass = (EclipseLinkMappedSuperclass) ormPersistentType.getMapping(); - Cacheable2_0 subCacheable = ((CacheableHolder2_0) subMappedSuperclass).getCacheable(); - Cacheable2_0 cacheable = ((CacheableHolder2_0) mappedSuperclass).getCacheable(); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - PersistenceUnit2_0 persistenceUnit2_0 = getPersistenceUnit(); - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(null); - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.DISABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.FALSE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(true, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); - assertEquals(false, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - cacheable.setSpecifiedCacheable(Boolean.TRUE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - - persistenceUnit2_0.setSpecifiedSharedCacheMode(SharedCacheMode.NONE); - assertEquals(true, subCacheable.isDefaultCacheable()); - assertEquals(false, cacheable.isDefaultCacheable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java deleted file mode 100644 index dba64a3dc9..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java +++ /dev/null @@ -1,1076 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.ReadOnlyColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToManyRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.OrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.jpa2.resource.java.MapKeyColumn2_0Annotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.v2_0.context.EclipseLinkOneToManyRelationship2_0; - -/** - * EclipseLink2_0OrmOneToManyMappingTests - */ -@SuppressWarnings("nls") -public class EclipseLink2_0OrmOneToManyMappingTests - extends EclipseLink2_0OrmContextModelTestCase -{ - public EclipseLink2_0OrmOneToManyMappingTests(String name) { - super(name); - } - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityWithValidOneToManyMapping() throws Exception { - this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Collection
addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" private String abbr;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @OrderBy(\"city\""); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(CR); - sb.append(" private java.util.Collection
address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) { - return ((OrmOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval(); - } - - public void testUpdateSpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 oneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToManyResource.getOrphanRemoval()); - - //set enumerated in the resource model, verify context model updated - oneToManyResource.setOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval()); - - oneToManyResource.setOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval()); - } - - public void testModifySpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 oneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping); - XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToManyResource.getOrphanRemoval()); - - //set enumerated in the context model, verify resource model updated - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval()); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval()); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - public void testUpdateVirtualMapKey() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME_ + "Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME_ + "State"); - - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualOneToManyMapping.getSpecifiedMapKey()); - assertNull(virtualOneToManyMapping.getMapKey()); - assertFalse(virtualOneToManyMapping.isPkMapKey()); - assertFalse(virtualOneToManyMapping.isCustomMapKey()); - assertTrue(virtualOneToManyMapping.isNoMapKey()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setPkMapKey(true); - assertEquals("id", virtualOneToManyMapping.getMapKey()); - assertTrue(virtualOneToManyMapping.isPkMapKey()); - assertFalse(virtualOneToManyMapping.isCustomMapKey()); - assertFalse(virtualOneToManyMapping.isNoMapKey()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setCustomMapKey(true); - javaOneToManyMapping.setSpecifiedMapKey("city"); - assertEquals("city", virtualOneToManyMapping.getSpecifiedMapKey()); - assertEquals("city", virtualOneToManyMapping.getMapKey()); - assertFalse(virtualOneToManyMapping.isPkMapKey()); - assertTrue(virtualOneToManyMapping.isCustomMapKey()); - assertFalse(virtualOneToManyMapping.isNoMapKey()); - - //set metadata complete and verify that the orm model ignores the java annotations - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - virtualOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - assertEquals(null, virtualOneToManyMapping.getSpecifiedMapKey()); - assertEquals(null, virtualOneToManyMapping.getMapKey()); - assertFalse(virtualOneToManyMapping.isPkMapKey()); - assertFalse(virtualOneToManyMapping.isCustomMapKey()); - assertTrue(virtualOneToManyMapping.isNoMapKey()); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = - virtualOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator mapKeyNames = virtualOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = virtualOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormPersistentType.getAttributeNamed("addresses").convertToSpecified(); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentType.getAttributeNamed("addresses").getMapping(); - mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - ormOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("state.name", mapKeyNames.next()); - assertEquals("state.abbr", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - - ormOneToManyMapping.setSpecifiedTargetEntity("String"); - mapKeyNames = ormOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - } - - public void testUpdateMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKeyClass(OrmFactory.eINSTANCE.createXmlClassReference()); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNotNull(oneToMany.getMapKeyClass()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKeyClass().setClassName("String"); - assertEquals("String", ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", oneToMany.getMapKeyClass().getClassName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKeyClass().setClassName(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass().getClassName()); - - oneToMany.getMapKeyClass().setClassName("String"); - oneToMany.setMapKeyClass(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - } - - public void testUpdateVirtualMapKeyClass() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - - OneToManyMapping2_0 virtualOneToManyMapping = (OneToManyMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - assertNull(virtualOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualOneToManyMapping.getMapKeyClass()); - assertEquals("java.lang.String", virtualOneToManyMapping.getDefaultMapKeyClass()); - - //set pk mapKey in the java, verify virtual orm mapping updates - javaOneToManyMapping.setSpecifiedMapKeyClass("Integer"); - assertEquals("Integer", virtualOneToManyMapping.getMapKeyClass()); - assertEquals("Integer", virtualOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualOneToManyMapping.getDefaultMapKeyClass()); - - - //set custom specified mapKey in the java, verify virtual orm mapping updates - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - virtualOneToManyMapping = (OneToManyMapping2_0) ormPersistentType.getAttributeNamed("addresses").getMapping(); - assertEquals(null, virtualOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("java.lang.String", virtualOneToManyMapping.getMapKeyClass()); - assertEquals("java.lang.String", virtualOneToManyMapping.getDefaultMapKeyClass()); - } - - public void testModifyMapKeyClass() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedMapKeyClass("String"); - assertEquals("String", ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertEquals("String", oneToMany.getMapKeyClass().getClassName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setSpecifiedMapKeyClass(null); - assertNull(ormOneToManyMapping.getSpecifiedMapKeyClass()); - assertNull(oneToMany.getMapKeyClass()); - } - - public void testOrderColumnDefaults() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmOneToManyMapping oneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - oneToManyMapping.getRelationship().setStrategyToMappedBy(); - oneToManyMapping.getRelationship().getMappedByStrategy().setMappedByAttribute("queue"); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - orderable.setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = orderable.getOrderColumn(); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(null, orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - orderColumn.setSpecifiedName("FOO"); - assertEquals("FOO", orderColumn.getSpecifiedName()); - assertEquals("jobs_ORDER", orderColumn.getDefaultName()); - assertEquals("PrintJob", orderColumn.getTable()); - - OrmPersistentType printJobPersistentType = (OrmPersistentType) getPersistenceUnit().getPersistentType("test.PrintJob"); - ((Entity) printJobPersistentType.getMapping()).getTable().setSpecifiedName("MY_TABLE"); - - assertEquals("MY_TABLE", orderColumn.getTable()); - } - - public void testVirtualOrderColumn() throws Exception { - createTestEntityPrintQueue(); - createTestEntityPrintJob(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintQueue"); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".PrintJob"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "jobs"); - OrmOneToManyMapping oneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - Orderable2_0 orderable = ((Orderable2_0) oneToManyMapping.getOrderable()); - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) ormPersistentAttribute.getJavaPersistentAttribute().getMapping(); - ((Orderable2_0) javaOneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - - assertEquals(false, orderable.isOrderColumnOrdering()); - assertEquals(true, orderable.isNoOrdering()); - - ormPersistentAttribute.convertToVirtual(); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("jobs"); - OneToManyMapping virtualOneToManyMapping = (OneToManyMapping) ormPersistentAttribute2.getMapping(); - orderable = ((Orderable2_0) virtualOneToManyMapping.getOrderable()); - assertEquals(true, orderable.isOrderColumnOrdering()); - assertEquals(false, orderable.isNoOrdering()); - assertEquals("PrintJob", orderable.getOrderColumn().getTable()); - assertEquals("jobs_ORDER", orderable.getOrderColumn().getName()); - - ((Orderable2_0) javaOneToManyMapping.getOrderable()).getOrderColumn().setSpecifiedName("FOO"); - assertEquals("PrintJob", orderable.getOrderColumn().getTable()); - assertEquals("FOO", orderable.getOrderColumn().getName()); - } - - - private void createTestEntityPrintQueue() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ONE_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ORDER_COLUMN); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintQueue").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @OneToMany(mappedBy=\"queue\")").append(CR); - sb.append(" @OrderColumn").append(CR); - sb.append(" private java.util.List jobs;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintQueue.java", sourceWriter); - } - - private void createTestEntityPrintJob() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_ONE); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("PrintJob").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private PrintQueue queue;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "PrintJob.java", sourceWriter); - } - - public void testVirtualMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no value Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - OneToManyMapping2_0 addressesVirtualMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - assertEquals("addresses_KEY", ormColumn.getName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertTrue(ormColumn.isInsertable()); - assertTrue(ormColumn.isUpdatable()); - assertTrue(ormColumn.isNullable()); - assertFalse(ormColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getScale()); - - //set Column annotation in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaOneToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", ormColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), ormColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - OneToManyMapping2_0 addressesMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - ormColumn = addressesMapping.getMapKeyColumn(); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, addressesPersistentAttribute.getMappingKey()); - - assertEquals("addresses_KEY", ormColumn.getName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertTrue(ormColumn.isInsertable()); - assertTrue(ormColumn.isUpdatable()); - assertTrue(ormColumn.isNullable()); - assertFalse(ormColumn.isUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getScale()); - } - - public void testNullMapKeyColumnDefaults() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - OrmPersistentAttribute addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - - OrmOneToManyMapping2_0 addressesVirtualMapping = (OrmOneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - //set Column annotation in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("FOO_TABLE"); - javaOneToManyMapping.getMapKeyColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedInsertable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedNullable(Boolean.FALSE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedUnique(Boolean.TRUE); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedLength(Integer.valueOf(45)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("addresses_KEY", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME + "_Address", ormColumn.getDefaultTable()); - assertEquals(true, ormColumn.isDefaultInsertable()); - assertEquals(true, ormColumn.isDefaultUpdatable()); - assertEquals(true, ormColumn.isDefaultNullable()); - assertEquals(false, ormColumn.isDefaultUnique()); - assertEquals(ReadOnlyColumn.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(ReadOnlyColumn.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(ReadOnlyColumn.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualMapKeyColumnTable() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmReadOnlyPersistentAttribute addressesPersistentAttribute = ormPersistentType.virtualAttributes().next(); - OneToManyMapping2_0 addressesVirtualMapping = (OneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - Column ormColumn = addressesVirtualMapping.getMapKeyColumn(); - - assertEquals(TYPE_NAME + "_Address", ormColumn.getTable()); - - //entity table changes the join table default name - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE_Address", ormColumn.getTable()); - - //set Column table element in Java - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - javaOneToManyMapping.getRelationship().getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - assertEquals("JAVA_JOIN_TABLE", ormColumn.getTable()); - javaOneToManyMapping.getMapKeyColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", ormColumn.getTable()); - - //make name persistent attribute not virtual - addressesPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "addresses"); - OrmOneToManyMapping2_0 addressesMapping = (OrmOneToManyMapping2_0) addressesPersistentAttribute.getMapping(); - ormColumn = addressesMapping.getMapKeyColumn(); - assertNull(ormColumn.getSpecifiedTable()); - assertEquals("ORM_TABLE_Address", ormColumn.getDefaultTable()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); - OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); - EclipseLinkOneToManyRelationship2_0 rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinColumn(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithValidOneToManyMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("addresses"); - OrmEclipseLinkOneToManyMapping contextMapping = (OrmEclipseLinkOneToManyMapping) contextAttribute.getMapping(); - EclipseLinkOneToManyRelationship2_0 rel = contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToMany resourceMapping = resourceEntity.getAttributes().getOneToManys().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNotNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertTrue(rel.strategyIsMappedBy()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertNull(resourceMapping.getMappedBy()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - assertFalse(rel.strategyIsMappedBy()); - } - - public void testTargetForeignKeyJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 virtualOneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - ((OneToManyRelationship2_0) javaOneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - JoinColumn joinColumn = ((OneToManyRelationship2_0) virtualOneToManyMapping.getRelationship()).getJoinColumnStrategy().specifiedJoinColumns().next(); - assertTrue(persistentAttribute.isVirtual()); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("Address", joinColumn.getDefaultTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - assertFalse(((OneToManyRelationship2_0) ormOneToManyMapping.getRelationship()).strategyIsJoinColumn()); - - ((OneToManyRelationship2_0) ormOneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - joinColumn = ((OneToManyRelationship2_0) ormOneToManyMapping.getRelationship()).getJoinColumnStrategy().specifiedJoinColumns().next(); - assertFalse(persistentAttribute.isVirtual()); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - - joinColumn.setSpecifiedName("FOO"); - assertEquals("addresses_id", joinColumn.getDefaultName()); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", joinColumn.getDefaultTable()); - } - - //target foreign key case - public void testGetMapKeyColumnJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 virtualOneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - ((OneToManyRelationship2_0) javaOneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - - assertTrue(persistentAttribute.isVirtual()); - assertEquals("addresses_KEY", virtualOneToManyMapping.getMapKeyColumn().getName()); - assertEquals("Address", virtualOneToManyMapping.getMapKeyColumn().getTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", virtualOneToManyMapping.getMapKeyColumn().getTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - MapKeyColumn2_0Annotation column = (MapKeyColumn2_0Annotation) attributeResource.addAnnotation(JPA2_0.MAP_KEY_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", virtualOneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("foo", virtualOneToManyMapping.getMapKeyColumn().getName()); - assertEquals("addresses_KEY", virtualOneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("ADDRESS_PRIMARY_TABLE", virtualOneToManyMapping.getMapKeyColumn().getDefaultTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - assertFalse(((OneToManyRelationship2_0) ormOneToManyMapping.getRelationship()).strategyIsJoinColumn()); - - ((OneToManyRelationship2_0) ormOneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - assertEquals("addresses_KEY", ormOneToManyMapping.getMapKeyColumn().getName()); - assertEquals("ADDRESS_PRIMARY_TABLE", ormOneToManyMapping.getMapKeyColumn().getTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("addresses_KEY", ormOneToManyMapping.getMapKeyColumn().getName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", ormOneToManyMapping.getMapKeyColumn().getTable());//target table name - - ormOneToManyMapping.getMapKeyColumn().setSpecifiedName("FOO"); - assertEquals("addresses_KEY", ormOneToManyMapping.getMapKeyColumn().getDefaultName()); - assertEquals("FOO", ormOneToManyMapping.getMapKeyColumn().getSpecifiedName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", ormOneToManyMapping.getMapKeyColumn().getDefaultTable()); - } - - //target foreign key case - public void testOrderColumnDefaultsJoinColumnStrategy() throws Exception { - createTestEntityWithValidGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType ormTargetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //test virtual orm mapping, setting the join column on the java mapping - OrmReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OneToManyMapping2_0 virtualOneToManyMapping = (OneToManyMapping2_0) persistentAttribute.getMapping(); - JavaOneToManyMapping2_0 javaOneToManyMapping = (JavaOneToManyMapping2_0) persistentAttribute.getJavaPersistentAttribute().getMapping(); - ((OneToManyRelationship2_0) javaOneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - ((Orderable2_0) javaOneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - OrderColumn2_0 orderColumn = ((Orderable2_0) virtualOneToManyMapping.getOrderable()).getOrderColumn(); - - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("Address", orderColumn.getTable());//target table name - - JavaEntity addressEntity = (JavaEntity) ormTargetPersistentType.getJavaPersistentType().getMapping(); - addressEntity.getTable().setSpecifiedName("ADDRESS_PRIMARY_TABLE"); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable()); - - //override the mapping in orm.xml - persistentAttribute.convertToSpecified(); - persistentAttribute = ormPersistentType.getAttributeNamed("addresses"); - OrmOneToManyMapping2_0 ormOneToManyMapping = (OrmOneToManyMapping2_0) persistentAttribute.getMapping(); - assertFalse(persistentAttribute.isVirtual()); - assertFalse(((OneToManyRelationship2_0) ormOneToManyMapping.getRelationship()).strategyIsJoinColumn()); - - ((OneToManyRelationship2_0) ormOneToManyMapping.getRelationship()).setStrategyToJoinColumn(); - assertFalse(((Orderable2_0) ormOneToManyMapping.getOrderable()).isOrderColumnOrdering()); - ((Orderable2_0) ormOneToManyMapping.getOrderable()).setOrderColumnOrdering(true); - orderColumn = ((Orderable2_0) ormOneToManyMapping.getOrderable()).getOrderColumn(); - - assertNull(orderColumn.getSpecifiedName()); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name - - OrmEntity ormAddressEntity = (OrmEntity) ormTargetPersistentType.getMapping(); - ormAddressEntity.getTable().setSpecifiedName("ORM_ADDRESS_PRIMARY_TABLE"); - assertEquals("addresses_ORDER", orderColumn.getName()); - assertEquals("ORM_ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - EclipseLinkOneToManyMapping virtualOneToManyMapping = (EclipseLinkOneToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToManyMapping.getName()); - assertEquals(FetchType.EAGER, virtualOneToManyMapping.getSpecifiedFetch()); - assertEquals("Address", virtualOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToManyMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) virtualOneToManyMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertTrue(virtualOneToManyMapping.getOrderable().isCustomOrdering()); - assertEquals("city", virtualOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertTrue(((OrphanRemovalHolder2_0) virtualOneToManyMapping).getOrphanRemoval().isOrphanRemoval()); - assertEquals(EclipseLinkJoinFetchType.INNER, virtualOneToManyMapping.getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToManyMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - - EclipseLinkOneToManyMapping virtualOneToManyMapping = (EclipseLinkOneToManyMapping) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToManyMapping.getName()); - assertEquals(FetchType.LAZY, virtualOneToManyMapping.getFetch()); - assertEquals("test.Address", virtualOneToManyMapping.getTargetEntity()); - assertNull(virtualOneToManyMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - Cascade2_0 cascade = (Cascade2_0) virtualOneToManyMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertTrue(virtualOneToManyMapping.getOrderable().isNoOrdering()); - assertEquals(null, virtualOneToManyMapping.getOrderable().getSpecifiedOrderBy()); - - assertFalse(((OrphanRemovalHolder2_0) virtualOneToManyMapping).getOrphanRemoval().isOrphanRemoval()); - assertEquals(null, virtualOneToManyMapping.getJoinFetch().getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java deleted file mode 100644 index 3148b4c470..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java +++ /dev/null @@ -1,910 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.ReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.OneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.OrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlDerivedId_2_0; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapsId_2_0; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.v2_0.context.EclipseLinkOneToOneMapping2_0; - -@SuppressWarnings("nls") -public class EclipseLink2_0OrmOneToOneMappingTests - extends EclipseLink2_0OrmContextModelTestCase -{ - public EclipseLink2_0OrmOneToOneMappingTests(String name) { - super(name); - } - - - private void createTestEntityWithIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestTargetEntityAddressWithElementCollection() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA2_0.ELEMENT_COLLECTION); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @ElementCollection").append(CR); - sb.append(" private java.util.Collection state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private void createTestEntityWithOneToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE, EclipseLink.PRIVATE_OWNED); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(CR); - sb.append(" @PrivateOwned)"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testUpdateDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute contextAttribute = (OrmPersistentAttribute) contextType.getAttributeNamed("oneToOne"); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - - XmlOneToOne resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - resourceOneToOne.setMapsId("foo"); - assertNull(resourceOneToOne.getId()); - assertFalse(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceOneToOne.getMapsId()); - assertEquals("foo", ((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - XmlManyToOne resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - assertNull(resourceManyToOne.getId()); - assertFalse(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceManyToOne.getMapsId()); - assertEquals("foo", ((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - assertNull(resourceOneToOne.getId()); - assertFalse(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertEquals("foo", resourceOneToOne.getMapsId()); - assertEquals("foo", ((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - public void testCandidateMappedByAttributeNamesElementCollection() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddressWithElementCollection(); - createTestEmbeddableState(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - getEntityMappings().addPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".State"); - ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - ReadOnlyPersistentAttribute persistentAttribute = ormPersistentType.attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationship().getMappedByStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("state.foo", attributeNames.next()); - assertEquals("state.address", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertEquals("foo", stateFooMapping.getName()); - } - - private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToOneMapping2_0 oneToOneMapping) { - return ((OrmOrphanRemovalHolder2_0) oneToOneMapping).getOrphanRemoval(); - } - - public void testUpdateSpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToOneMapping); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToOneResource.getOrphanRemoval()); - - //set enumerated in the resource model, verify context model updated - oneToOneResource.setOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.TRUE, oneToOneResource.getOrphanRemoval()); - - oneToOneResource.setOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(Boolean.FALSE, oneToOneResource.getOrphanRemoval()); - } - - public void testModifySpecifiedOrphanRemoval() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(ormOneToOneMapping); - XmlOneToOne oneToOneResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - assertEquals(null, oneToOneResource.getOrphanRemoval()); - - //set enumerated in the context model, verify resource model updated - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneResource.getOrphanRemoval()); - assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - - mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneResource.getOrphanRemoval()); - assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidOneToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - JavaOneToOneMapping2_0 javaOneToOneMapping = ((JavaOneToOneMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping()); - OneToOneMapping2_0 virtualOneToOneMapping = (OneToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - JoinTable virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, virtualJoinTable.getSpecifiedName()); - - createTestTargetEntityAddress(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - assertEquals(TYPE_NAME + "_Address", virtualJoinTable.getName()); - assertNull(virtualJoinTable.getSpecifiedCatalog()); - assertNull(virtualJoinTable.getSpecifiedSchema()); - assertEquals(0, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(0, virtualJoinTable.specifiedInverseJoinColumnsSize()); - JoinColumn virtualJoinColumn = virtualJoinTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_Address", virtualJoinColumn.getDefaultTable()); - assertEquals(TYPE_NAME + "_id", virtualJoinColumn.getDefaultName()); - assertEquals("id", virtualJoinColumn.getDefaultReferencedColumnName()); - JoinColumn virtualInverseOrmJoinColumn = virtualJoinTable.getDefaultInverseJoinColumn(); - assertEquals(TYPE_NAME + "_Address", virtualInverseOrmJoinColumn.getDefaultTable()); - assertEquals("address_id", virtualInverseOrmJoinColumn.getDefaultName()); - assertEquals("id", virtualInverseOrmJoinColumn.getDefaultReferencedColumnName()); - - JavaJoinTable javaJoinTable = ((JavaOneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", virtualJoinTable.getSpecifiedName()); - assertEquals("CATALOG", virtualJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", virtualJoinTable.getSpecifiedSchema()); - assertEquals(1, virtualJoinTable.specifiedJoinColumnsSize()); - assertEquals(1, virtualJoinTable.specifiedInverseJoinColumnsSize()); - virtualJoinColumn = virtualJoinTable.specifiedJoinColumns().next(); - assertEquals("NAME", virtualJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", virtualJoinColumn.getSpecifiedReferencedColumnName()); - virtualInverseOrmJoinColumn = virtualJoinTable.specifiedInverseJoinColumns().next(); - assertEquals("INVERSE_NAME", virtualInverseOrmJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", virtualInverseOrmJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidOneToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((OneToOneRelationship2_0) ormOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - OrmJoinTable ormJoinTable = ((OrmOneToOneRelationship2_0) ormOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTestTargetEntityAddress(); - OrmPersistentType targetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - JavaOneToOneMapping2_0 javaOneToOneMapping = (JavaOneToOneMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("address").getMapping(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("address"); - OneToOneMapping2_0 virtualOneToOneMapping = (OneToOneMapping2_0) ormPersistentAttribute2.getMapping(); - JoinTable virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertTrue(ormPersistentAttribute2.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", virtualJoinTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).getJoinTableStrategy().removeStrategy(); - virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(virtualJoinTable); - ((OneToOneRelationship2_0) javaOneToOneMapping.getRelationship()).setStrategyToJoinTable(); - virtualJoinTable = ((OneToOneRelationship2_0) virtualOneToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("BAR_FOO", virtualJoinTable.getName()); - assertEquals("BAR_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", virtualJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", virtualJoinTable.getDefaultName()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmOneToOneRelationship2_0 rel = (OrmOneToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToMappedBy(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToPrimaryKeyJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmOneToOneMapping2_0 contextMapping = (OrmOneToOneMapping2_0) contextAttribute.getMapping(); - OrmOneToOneRelationship2_0 rel = (OrmOneToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlOneToOne resourceMapping = resourceEntity.getAttributes().getOneToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertFalse(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getPrimaryKeyJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertTrue(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertTrue(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(null); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertTrue(resourceMapping.getPrimaryKeyJoinColumns().isEmpty()); - assertNull(resourceMapping.getMappedBy()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsPrimaryKeyJoinColumn()); - assertFalse(rel.strategyIsMappedBy()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - EclipseLinkOneToOneMapping2_0 virtualOneToOneMapping = (EclipseLinkOneToOneMapping2_0) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualOneToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualOneToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualOneToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(virtualOneToOneMapping.getRelationship(). - getMappedByStrategy().getMappedByAttribute()); - - JoinColumn ormJoinColumn = - virtualOneToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) virtualOneToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertEquals(EclipseLinkJoinFetchType.INNER, virtualOneToOneMapping.getJoinFetch().getValue()); - assertTrue(virtualOneToOneMapping.getPrivateOwned().isPrivateOwned()); - - assertTrue(((OrphanRemovalHolder2_0) virtualOneToOneMapping).getOrphanRemoval().isOrphanRemoval()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - EclipseLinkOneToOneMapping2_0 ormOneToOneMapping = (EclipseLinkOneToOneMapping2_0) virtualPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(true, ormOneToOneMapping.isOptional()); - assertEquals("test.Address", ormOneToOneMapping.getTargetEntity()); - assertNull(ormOneToOneMapping.getRelationship().getMappedByStrategy().getMappedByAttribute()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertEquals(null, ormOneToOneMapping.getJoinFetch().getValue()); - assertFalse(ormOneToOneMapping.getPrivateOwned().isPrivateOwned()); - - assertFalse(((OrphanRemovalHolder2_0) ormOneToOneMapping).getOrphanRemoval().isOrphanRemoval()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java deleted file mode 100644 index 255f5c1bca..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java +++ /dev/null @@ -1,589 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.Cascade2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.ManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneRelationship2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlDerivedId_2_0; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapsId_2_0; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchMapping; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; - -@SuppressWarnings("nls") -public class Eclipselink2_0OrmManyToOneMappingTests - extends EclipseLink2_0OrmContextModelTestCase -{ - public Eclipselink2_0OrmManyToOneMappingTests(String name) { - super(name); - } - - - private void createTestEntityWithIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @Id").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private void createTestEntityWithMapsIdDerivedIdentity() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA2_0.MAPS_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne @MapsId").append(CR); - sb.append(" private " + TYPE_NAME + " manyToOne;").append(CR); - sb.append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityWithValidManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEntityWithManyToOneMapping() throws Exception { - createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - for (OrmReadOnlyPersistentAttribute each : CollectionTools.iterable(ormPersistentType.attributes())) { - each.convertToSpecified(); - } - } - - private ICompilationUnit createTestEntityManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator imports() { - return new ArrayIterator(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" @JoinFetch(JoinFetchType.INNER)"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - public void testUpdateDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.FALSE); - assertEquals(Boolean.FALSE, resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - resourceMapping.setId(null); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testSetDerivedId() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlDerivedId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(true); - assertEquals(Boolean.TRUE, resourceMapping.getId()); - assertTrue(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - - contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().setValue(false); - assertNull(resourceMapping.getId()); - assertFalse(contextMapping.getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - } - - public void testUpdateMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - resourceMapping.setMapsId(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testSetMapsId() throws Exception { - createTestEntityWithMapsIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("manyToOne"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlMapsId_2_0 resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("foo"); - assertEquals("foo", resourceMapping.getMapsId()); - assertEquals("foo", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue("bar"); - assertEquals("bar", resourceMapping.getMapsId()); - assertEquals("bar", contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().setSpecifiedValue(null); - assertNull(resourceMapping.getMapsId()); - assertNull(contextMapping.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testMorphMapping() throws Exception { - createTestEntityWithIdDerivedIdentity(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute contextAttribute = (OrmPersistentAttribute) contextType.getAttributeNamed("manyToOne"); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - - XmlManyToOne resourceManyToOne = resourceEntity.getAttributes().getManyToOnes().get(0); - resourceManyToOne.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceManyToOne.getId()); - assertTrue(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceManyToOne.getMapsId()); - assertNull(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - XmlOneToOne resourceOneToOne = resourceEntity.getAttributes().getOneToOnes().get(0); - assertEquals(Boolean.TRUE, resourceOneToOne.getId()); - assertTrue(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceOneToOne.getMapsId()); - assertNull(((OrmOneToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - - contextAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - resourceManyToOne.setId(Boolean.TRUE); - assertEquals(Boolean.TRUE, resourceManyToOne.getId()); - assertTrue(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getIdDerivedIdentityStrategy().getValue()); - assertNull(resourceManyToOne.getMapsId()); - assertNull(((OrmManyToOneMapping2_0) contextAttribute.getMapping()). - getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getSpecifiedValue()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidManyToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - JavaManyToOneMapping2_0 javaManyToOneMapping = ((JavaManyToOneMapping2_0) ormPersistentAttribute.getJavaPersistentAttribute().getMapping()); - ManyToOneMapping2_0 virtualManyToOneMapping = (ManyToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - JoinTable ormJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, ormJoinTable.getSpecifiedName()); - - createTestTargetEntityAddress(); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getName()); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertEquals(0, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals(0, ormJoinTable.specifiedInverseJoinColumnsSize()); - JoinColumn ormJoinColumn = ormJoinTable.getDefaultJoinColumn(); - assertEquals(TYPE_NAME + "_Address", ormJoinColumn.getDefaultTable()); - assertEquals(TYPE_NAME + "_id", ormJoinColumn.getDefaultName()); - assertEquals("id", ormJoinColumn.getDefaultReferencedColumnName()); - JoinColumn inverseOrmJoinColumn = ormJoinTable.getDefaultInverseJoinColumn(); - assertEquals(TYPE_NAME + "_Address", inverseOrmJoinColumn.getDefaultTable()); - assertEquals("address_id", inverseOrmJoinColumn.getDefaultName()); - assertEquals("id", inverseOrmJoinColumn.getDefaultReferencedColumnName()); - - JavaJoinTable javaJoinTable = ((JavaManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("CATALOG", ormJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", ormJoinTable.getSpecifiedSchema()); - assertEquals(1, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals(1, ormJoinTable.specifiedInverseJoinColumnsSize()); - ormJoinColumn = ormJoinTable.specifiedJoinColumns().next(); - assertEquals("NAME", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); - inverseOrmJoinColumn = ormJoinTable.specifiedInverseJoinColumns().next(); - assertEquals("INVERSE_NAME", inverseOrmJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", inverseOrmJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidManyToOneMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - OrmManyToOneMapping2_0 ormManyToOneMapping = (OrmManyToOneMapping2_0) ormPersistentAttribute.getMapping(); - ((ManyToOneRelationship2_0) ormManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - JoinTable ormJoinTable = ((OrmManyToOneRelationship2_0) ormManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTestTargetEntityAddress(); - OrmPersistentType targetPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - JavaManyToOneMapping2_0 javaManyToOneMapping = (JavaManyToOneMapping2_0) ormPersistentType.getJavaPersistentType().getAttributeNamed("address").getMapping(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Address", ormJoinTable.getDefaultName()); - - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.convertToVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - OrmReadOnlyPersistentAttribute ormPersistentAttribute2 = ormPersistentType.getAttributeNamed("address"); - ManyToOneMapping2_0 virtualManyToOneMapping = (ManyToOneMapping2_0) ormPersistentAttribute2.getMapping(); - ormJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertTrue(ormPersistentAttribute2.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", ormJoinTable.getSpecifiedName());//specifiedName since this is a virtual mapping now - - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).getJoinTableStrategy().removeStrategy(); - ormJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertNull(ormJoinTable); - ((ManyToOneRelationship2_0) javaManyToOneMapping.getRelationship()).setStrategyToJoinTable(); - ormJoinTable = ((ManyToOneRelationship2_0) virtualManyToOneMapping.getRelationship()).getJoinTableStrategy().getJoinTable(); - assertEquals("BAR_FOO", ormJoinTable.getName()); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", ormJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", ormJoinTable.getDefaultName()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmManyToOneRelationship2_0 rel = (OrmManyToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinTable(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - - rel.setStrategyToJoinColumn(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME); - OrmReadOnlyPersistentAttribute contextAttribute = contextType.getAttributeNamed("id"); - OrmManyToOneMapping2_0 contextMapping = (OrmManyToOneMapping2_0) contextAttribute.getMapping(); - OrmManyToOneRelationship2_0 rel = (OrmManyToOneRelationship2_0) contextMapping.getRelationship(); - XmlEntity resourceEntity = (XmlEntity) contextType.getMapping().getXmlTypeMapping(); - XmlManyToOne resourceMapping = resourceEntity.getAttributes().getManyToOnes().get(0); - - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumn()); - getJpaProject().synchronizeContextModel(); - assertFalse(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.getJoinColumns().clear(); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNull(resourceMapping.getJoinTable()); - assertTrue(rel.strategyIsJoinColumn()); - assertFalse(rel.strategyIsJoinTable()); - - resourceMapping.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTable()); - getJpaProject().synchronizeContextModel(); - assertTrue(resourceMapping.getJoinColumns().isEmpty()); - assertNotNull(resourceMapping.getJoinTable()); - assertFalse(rel.strategyIsJoinColumn()); - assertTrue(rel.strategyIsJoinTable()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - ManyToOneMapping2_0 virtualManyToOneMapping = (ManyToOneMapping2_0) virtualPersistentAttribute.getMapping(); - assertEquals("address", virtualManyToOneMapping.getName()); - assertEquals(FetchType.LAZY, virtualManyToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, virtualManyToOneMapping.getSpecifiedOptional()); - assertEquals("Address", virtualManyToOneMapping.getSpecifiedTargetEntity()); - - JoinColumn virtualJoinColumn = virtualManyToOneMapping.getRelationship().getJoinColumnStrategy().specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", virtualJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", virtualJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, virtualJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, virtualJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", virtualJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", virtualJoinColumn.getSpecifiedTable()); - - Cascade2_0 cascade = (Cascade2_0) virtualManyToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - assertTrue(cascade.isDetach()); - - assertEquals(EclipseLinkJoinFetchType.INNER, ((EclipseLinkJoinFetchMapping) virtualManyToOneMapping).getJoinFetch().getValue()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmReadOnlyPersistentAttribute virtualPersistentAttribute = ormPersistentType.getAttributeNamed("address"); - - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, virtualPersistentAttribute.getMappingKey()); - assertTrue(virtualPersistentAttribute.isVirtual()); - - virtualPersistentAttribute.convertToSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - - OrmManyToOneMapping2_0 ormManyToOneMapping = (OrmManyToOneMapping2_0) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch()); - assertEquals(true, ormManyToOneMapping.isDefaultOptional()); - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - Cascade2_0 cascade = (Cascade2_0) ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - assertFalse(cascade.isDetach()); - - assertEquals(null, ((EclipseLinkJoinFetchMapping) ormManyToOneMapping).getJoinFetch().getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/JptEclipseLink2_0OrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/JptEclipseLink2_0OrmContextModelTests.java deleted file mode 100644 index 484105f77c..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/JptEclipseLink2_0OrmContextModelTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptEclipseLink2_0OrmContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink2_0OrmContextModelTests.class.getName()); - suite.addTestSuite(EclipseLink2_0OrmCollectionTableTests.class); - suite.addTestSuite(EclipseLink2_0OrmElementCollectionMappingTests.class); - suite.addTestSuite(EclipseLink2_0OrmEntityTests.class); - suite.addTestSuite(EclipseLink2_0OrmManyToManyMappingTests.class); - suite.addTestSuite(Eclipselink2_0OrmManyToOneMappingTests.class); - suite.addTestSuite(EclipseLink2_0OrmMappedSuperclassTests.class); - suite.addTestSuite(EclipseLink2_0OrmOneToOneMappingTests.class); - suite.addTestSuite(EclipseLink2_0OrmOneToManyMappingTests.class); - return suite; - } - - private JptEclipseLink2_0OrmContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0ConnectionTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0ConnectionTests.java deleted file mode 100644 index ffb0565d45..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0ConnectionTests.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009 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.eclipselink2_0.core.tests.internal.context.persistence; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.core.jpa2.context.persistence.connection.JpaConnection2_0; -import org.eclipse.jpt.eclipselink.core.context.persistence.connection.Connection; -import org.eclipse.jpt.eclipselink.core.v2_0.context.persistence.connection.Connection2_0; - -/** - * EclipseLink2_0ConnectionTests - */ -public class EclipseLink2_0ConnectionTests extends EclipseLink2_0PersistenceUnitTestCase -{ - private Connection2_0 connection; - - public static final String NATIVE_SQL_KEY = Connection.ECLIPSELINK_NATIVE_SQL; - public static final Boolean NATIVE_SQL_TEST_VALUE = false; - public static final Boolean NATIVE_SQL_TEST_VALUE_2 = ! NATIVE_SQL_TEST_VALUE; - - public static final String DRIVER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_DRIVER; - public static final String DRIVER_TEST_VALUE = "connection.driver"; - public static final String DRIVER_TEST_VALUE_2 = "connection.driver.2"; - public static final String LEGACY_DRIVER_KEY = Connection.ECLIPSELINK_DRIVER; - public static final String LEGACY_DRIVER_TEST_VALUE = "legacy.connection.driver"; - - public static final String URL_KEY = JpaConnection2_0.PERSISTENCE_JDBC_URL; - public static final String URL_TEST_VALUE = "test"; - public static final String URL_TEST_VALUE_2 = "test_2"; - public static final String LEGACY_URL_KEY = Connection.ECLIPSELINK_URL; - public static final String LEGACY_URL_TEST_VALUE = "legacy.connection.url"; - - public static final String USER_KEY = JpaConnection2_0.PERSISTENCE_JDBC_USER; - public static final String USER_TEST_VALUE = "test"; - public static final String USER_TEST_VALUE_2 = "test_2"; - public static final String LEGACY_USER_KEY = Connection.ECLIPSELINK_USER; - public static final String LEGACY_USER_TEST_VALUE = "legacy.connection.user"; - - public static final String PASSWORD_KEY = JpaConnection2_0.PERSISTENCE_JDBC_PASSWORD; - public static final String PASSWORD_TEST_VALUE = "test"; - public static final String PASSWORD_TEST_VALUE_2 = "test_2"; - public static final String LEGACY_PASSWORD_KEY = Connection.ECLIPSELINK_PASSWORD; - public static final String LEGACY_PASSWORD_TEST_VALUE = "legacy.connection.password"; - - public EclipseLink2_0ConnectionTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.connection = (Connection2_0) this.subject.getConnection(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.connection.addPropertyChangeListener(Connection.DRIVER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.URL_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.USER_PROPERTY, propertyChangeListener); - this.connection.addPropertyChangeListener(Connection.PASSWORD_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PU properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 8; // EclipseLink properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 4 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes EclipseLink properties - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(LEGACY_DRIVER_KEY, LEGACY_DRIVER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(DRIVER_KEY, DRIVER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(LEGACY_URL_KEY, LEGACY_URL_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(URL_KEY, URL_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(LEGACY_USER_KEY, LEGACY_USER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(USER_KEY, USER_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(LEGACY_PASSWORD_KEY, LEGACY_PASSWORD_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(PASSWORD_KEY, PASSWORD_TEST_VALUE.toString()); - - return; - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.connection; - } - - // ********** get/set property ********** - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - - if (propertyName.equals(Connection.DRIVER_PROPERTY)) - modelValue = this.connection.getDriver(); - else if (propertyName.equals(Connection.URL_PROPERTY)) - modelValue = this.connection.getUrl(); - else if (propertyName.equals(Connection.USER_PROPERTY)) - modelValue = this.connection.getUser(); - else if (propertyName.equals(Connection.PASSWORD_PROPERTY)) - modelValue = this.connection.getPassword(); - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Connection.DRIVER_PROPERTY)) - this.connection.setDriver((String) newValue); - else if (propertyName.equals(Connection.URL_PROPERTY)) - this.connection.setUrl((String) newValue); - else if (propertyName.equals(Connection.USER_PROPERTY)) - this.connection.setUser((String) newValue); - else if (propertyName.equals(Connection.PASSWORD_PROPERTY)) - this.connection.setPassword((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - - // ********** Properties Name Migration tests ********** - public void testDriverPropertyNameMigration() throws Exception { - - // Verify legacy driver exists - assertTrue("Legacy driver not exists", this.propertyValueEquals(LEGACY_DRIVER_KEY, LEGACY_DRIVER_TEST_VALUE)); - - // Verify driver read in - assertEquals("Incorrect driver read", this.connection.getDriver(), DRIVER_TEST_VALUE); - - // Change driver value - this.connection.setDriver(DRIVER_TEST_VALUE_2); - // Verify driver value changed - assertEquals("Driver not set", this.connection.getDriver(), DRIVER_TEST_VALUE_2); - assertTrue("PersistenceUnit property not set", this.propertyValueEquals(DRIVER_KEY, DRIVER_TEST_VALUE_2)); - - // Verify legacy entry has been deleted - this.verifyPuHasNotProperty(LEGACY_DRIVER_KEY, "Legacy property has not been deleted"); - } - - public void testPropertiesNamesMigration() throws Exception { - // connection.initializeProperties() occurred before test.puPopulate() therefore - // we cannot test the case where there are legacy properties only exist in the xml - // Verify that User & Password exist in both forms - this.verifyPuHasProperty(USER_KEY, "Property not exists"); - this.verifyPuHasProperty(PASSWORD_KEY, "Property not exists"); - this.verifyPuHasProperty(LEGACY_USER_KEY, "Legacy property not exists"); - this.verifyPuHasProperty(LEGACY_PASSWORD_KEY, "Legacy property not exists"); - - // Change a property value to trigger migration routine - this.connection.setNativeSql(NATIVE_SQL_TEST_VALUE); - - // Verify that all legacy entry has been deleted - this.verifyPuHasNotProperty(LEGACY_DRIVER_KEY, "Legacy property has not been deleted"); - this.verifyPuHasNotProperty(LEGACY_URL_KEY, "Legacy property has not been deleted"); - this.verifyPuHasNotProperty(LEGACY_USER_KEY, "Legacy property has not been deleted"); - this.verifyPuHasNotProperty(LEGACY_PASSWORD_KEY, "Legacy property has not been deleted"); - } - - - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0LoggingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0LoggingTests.java deleted file mode 100644 index 42e696b1e4..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0LoggingTests.java +++ /dev/null @@ -1,430 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.persistence; - -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.context.persistence.logging.LoggingLevel; -import org.eclipse.jpt.eclipselink.core.v2_0.context.persistence.logging.Logging2_0; - -/** - * EclipseLink2_0LoggingTests - */ -public class EclipseLink2_0LoggingTests extends EclipseLink2_0PersistenceUnitTestCase -{ - private Logging2_0 logging; - - public static final String SQL_LOGGING_KEY = Logging2_0.ECLIPSELINK_SQL_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel SQL_LOGGING_TEST_VALUE = LoggingLevel.off; - public static final LoggingLevel SQL_LOGGING_TEST_VALUE_2 = LoggingLevel.severe; - - public static final String TRANSACTION_LOGGING_KEY = Logging2_0.ECLIPSELINK_TRANSACTION_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel TRANSACTION_LOGGING_TEST_VALUE = LoggingLevel.warning; - public static final LoggingLevel TRANSACTION_LOGGING_TEST_VALUE_2 = LoggingLevel.info; - - public static final String EVENT_LOGGING_KEY = Logging2_0.ECLIPSELINK_EVENT_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel EVENT_LOGGING_TEST_VALUE = LoggingLevel.config; - public static final LoggingLevel EVENT_LOGGING_TEST_VALUE_2 = LoggingLevel.fine; - - public static final String CONNECTION_LOGGING_KEY = Logging2_0.ECLIPSELINK_CONNECTION_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel CONNECTION_LOGGING_TEST_VALUE = LoggingLevel.finer; - public static final LoggingLevel CONNECTION_LOGGING_TEST_VALUE_2 = LoggingLevel.finest; - - public static final String QUERY_LOGGING_KEY = Logging2_0.ECLIPSELINK_QUERY_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel QUERY_LOGGING_TEST_VALUE = LoggingLevel.all; - public static final LoggingLevel QUERY_LOGGING_TEST_VALUE_2 = LoggingLevel.off; - - public static final String CACHE_LOGGING_KEY = Logging2_0.ECLIPSELINK_CACHE_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel CACHE_LOGGING_TEST_VALUE = LoggingLevel.severe; - public static final LoggingLevel CACHE_LOGGING_TEST_VALUE_2 = LoggingLevel.warning; - - public static final String PROPAGATION_LOGGING_KEY = Logging2_0.ECLIPSELINK_PROPAGATION_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel PROPAGATION_LOGGING_TEST_VALUE = LoggingLevel.info; - public static final LoggingLevel PROPAGATION_LOGGING_TEST_VALUE_2 = LoggingLevel.config; - - public static final String SEQUENCING_LOGGING_KEY = Logging2_0.ECLIPSELINK_SEQUENCING_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel SEQUENCING_LOGGING_TEST_VALUE = LoggingLevel.fine; - public static final LoggingLevel SEQUENCING_LOGGING_TEST_VALUE_2 = LoggingLevel.finer; - - public static final String EJB_LOGGING_KEY = Logging2_0.ECLIPSELINK_EJB_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel EJB_LOGGING_TEST_VALUE = LoggingLevel.finest; - public static final LoggingLevel EJB_LOGGING_TEST_VALUE_2 = LoggingLevel.all; - - public static final String DMS_LOGGING_KEY = Logging2_0.ECLIPSELINK_DMS_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel DMS_LOGGING_TEST_VALUE = LoggingLevel.off; - public static final LoggingLevel DMS_LOGGING_TEST_VALUE_2 = LoggingLevel.severe; - - public static final String EJB_OR_METADATA_LOGGING_KEY = Logging2_0.ECLIPSELINK_EJB_OR_METADATA_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel EJB_OR_METADATA_LOGGING_TEST_VALUE = LoggingLevel.warning; - public static final LoggingLevel EJB_OR_METADATA_LOGGING_TEST_VALUE_2 = LoggingLevel.info; - - public static final String METAMODEL_LOGGING_KEY = Logging2_0.ECLIPSELINK_METAMODEL_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel METAMODEL_LOGGING_TEST_VALUE = LoggingLevel.config; - public static final LoggingLevel METAMODEL_LOGGING_TEST_VALUE_2 = LoggingLevel.fine; - - public static final String WEAVER_LOGGING_KEY = Logging2_0.ECLIPSELINK_WEAVER_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel WEAVER_LOGGING_TEST_VALUE = LoggingLevel.finer; - public static final LoggingLevel WEAVER_LOGGING_TEST_VALUE_2 = LoggingLevel.finest; - - public static final String PROPERTIES_LOGGING_KEY = Logging2_0.ECLIPSELINK_PROPERTIES_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel PROPERTIES_LOGGING_TEST_VALUE = LoggingLevel.all; - public static final LoggingLevel PROPERTIES_LOGGING_TEST_VALUE_2 = LoggingLevel.off; - - public static final String SERVER_LOGGING_KEY = Logging2_0.ECLIPSELINK_SERVER_CATEGORY_LOGGING_LEVEL; - public static final LoggingLevel SERVER_LOGGING_TEST_VALUE = LoggingLevel.severe; - public static final LoggingLevel SERVER_LOGGING_TEST_VALUE_2 = LoggingLevel.warning; - - // ********** constructors ********** - public EclipseLink2_0LoggingTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.logging = (Logging2_0) this.subject.getLogging(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.logging.addPropertyChangeListener(Logging2_0.SQL_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.TRANSACTION_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.EVENT_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.CONNECTION_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.QUERY_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.CACHE_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.PROPAGATION_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.SEQUENCING_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.EJB_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.DMS_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.EJB_OR_METADATA_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.METAMODEL_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.WEAVER_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.PROPERTIES_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - this.logging.addPropertyChangeListener(Logging2_0.SERVER_CATEGORY_LOGGING_PROPERTY, propertyChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PersistenceUnit properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 15; // PersistenceUnit properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 1 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes PersistenceUnit properties - this.persistenceUnitSetProperty("misc.property.1", "value.1"); - this.persistenceUnitSetProperty(SQL_LOGGING_KEY, SQL_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(TRANSACTION_LOGGING_KEY, TRANSACTION_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(EVENT_LOGGING_KEY, EVENT_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(CONNECTION_LOGGING_KEY, CONNECTION_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(QUERY_LOGGING_KEY, QUERY_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(CACHE_LOGGING_KEY, CACHE_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(PROPAGATION_LOGGING_KEY, PROPAGATION_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(SEQUENCING_LOGGING_KEY, SEQUENCING_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(EJB_LOGGING_KEY, EJB_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(DMS_LOGGING_KEY, DMS_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(EJB_OR_METADATA_LOGGING_KEY, EJB_OR_METADATA_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(METAMODEL_LOGGING_KEY, METAMODEL_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(WEAVER_LOGGING_KEY, WEAVER_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(PROPERTIES_LOGGING_KEY, PROPERTIES_LOGGING_TEST_VALUE); - this.persistenceUnitSetProperty(SERVER_LOGGING_KEY, SERVER_LOGGING_TEST_VALUE); - - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.logging; - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - - return this.logging.getLevel(propertyName); - } - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - - this.logging.setLevel(propertyName, (LoggingLevel) newValue); - } - - // ********** Sql Level tests ********** - public void testSetSqlLoggingLevel() throws Exception { - this.verifyModelInitialized( - SQL_LOGGING_KEY, - SQL_LOGGING_TEST_VALUE); - this.verifySetProperty( - SQL_LOGGING_KEY, - SQL_LOGGING_TEST_VALUE, - SQL_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveSqlLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - SQL_LOGGING_KEY, - SQL_LOGGING_TEST_VALUE, - SQL_LOGGING_TEST_VALUE_2); - } - - // ********** Transaction Level tests ********** - public void testSetTransactionLoggingLevel() throws Exception { - this.verifyModelInitialized( - TRANSACTION_LOGGING_KEY, - TRANSACTION_LOGGING_TEST_VALUE); - this.verifySetProperty( - TRANSACTION_LOGGING_KEY, - TRANSACTION_LOGGING_TEST_VALUE, - TRANSACTION_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveTransactionLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - TRANSACTION_LOGGING_KEY, - TRANSACTION_LOGGING_TEST_VALUE, - TRANSACTION_LOGGING_TEST_VALUE_2); - } - - // ********** Event Level tests ********** - public void testSetEventLoggingLevel() throws Exception { - this.verifyModelInitialized( - EVENT_LOGGING_KEY, - EVENT_LOGGING_TEST_VALUE); - this.verifySetProperty( - EVENT_LOGGING_KEY, - EVENT_LOGGING_TEST_VALUE, - EVENT_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveEventLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - EVENT_LOGGING_KEY, - EVENT_LOGGING_TEST_VALUE, - EVENT_LOGGING_TEST_VALUE_2); - } - - // ********** Connection Level tests ********** - public void testSetConnectionLoggingLevel() throws Exception { - this.verifyModelInitialized( - CONNECTION_LOGGING_KEY, - CONNECTION_LOGGING_TEST_VALUE); - this.verifySetProperty( - CONNECTION_LOGGING_KEY, - CONNECTION_LOGGING_TEST_VALUE, - CONNECTION_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveConnectionLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - CONNECTION_LOGGING_KEY, - CONNECTION_LOGGING_TEST_VALUE, - CONNECTION_LOGGING_TEST_VALUE_2); - } - - // ********** Query Level tests ********** - public void testSetQueryLoggingLevel() throws Exception { - this.verifyModelInitialized( - QUERY_LOGGING_KEY, - QUERY_LOGGING_TEST_VALUE); - this.verifySetProperty( - QUERY_LOGGING_KEY, - QUERY_LOGGING_TEST_VALUE, - QUERY_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveQueryLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - QUERY_LOGGING_KEY, - QUERY_LOGGING_TEST_VALUE, - QUERY_LOGGING_TEST_VALUE_2); - } - - // ********** Cache Level tests ********** - public void testSetCacheLoggingLevel() throws Exception { - this.verifyModelInitialized( - CACHE_LOGGING_KEY, - CACHE_LOGGING_TEST_VALUE); - this.verifySetProperty( - CACHE_LOGGING_KEY, - CACHE_LOGGING_TEST_VALUE, - CACHE_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveCacheLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - CACHE_LOGGING_KEY, - CACHE_LOGGING_TEST_VALUE, - CACHE_LOGGING_TEST_VALUE_2); - } - - // ********** Propagation Level tests ********** - public void testSetPropagationLoggingLevel() throws Exception { - this.verifyModelInitialized( - PROPAGATION_LOGGING_KEY, - PROPAGATION_LOGGING_TEST_VALUE); - this.verifySetProperty( - PROPAGATION_LOGGING_KEY, - PROPAGATION_LOGGING_TEST_VALUE, - PROPAGATION_LOGGING_TEST_VALUE_2); - } - - public void testAddRemovePropagationLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - PROPAGATION_LOGGING_KEY, - PROPAGATION_LOGGING_TEST_VALUE, - PROPAGATION_LOGGING_TEST_VALUE_2); - } - - // ********** Sequencing Level tests ********** - public void testSetSequencingLoggingLevel() throws Exception { - this.verifyModelInitialized( - SEQUENCING_LOGGING_KEY, - SEQUENCING_LOGGING_TEST_VALUE); - this.verifySetProperty( - SEQUENCING_LOGGING_KEY, - SEQUENCING_LOGGING_TEST_VALUE, - SEQUENCING_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveSequencingLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - SEQUENCING_LOGGING_KEY, - SEQUENCING_LOGGING_TEST_VALUE, - SEQUENCING_LOGGING_TEST_VALUE_2); - } - - // ********** EJB Level tests ********** - public void testSetEJBLoggingLevel() throws Exception { - this.verifyModelInitialized( - EJB_LOGGING_KEY, - EJB_LOGGING_TEST_VALUE); - this.verifySetProperty( - EJB_LOGGING_KEY, - EJB_LOGGING_TEST_VALUE, - EJB_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveEJBLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - EJB_LOGGING_KEY, - EJB_LOGGING_TEST_VALUE, - EJB_LOGGING_TEST_VALUE_2); - } - - // ********** DMS Level tests ********** - public void testSetDMSLoggingLevel() throws Exception { - this.verifyModelInitialized( - DMS_LOGGING_KEY, - DMS_LOGGING_TEST_VALUE); - this.verifySetProperty( - DMS_LOGGING_KEY, - DMS_LOGGING_TEST_VALUE, - DMS_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveDMSLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - DMS_LOGGING_KEY, - DMS_LOGGING_TEST_VALUE, - DMS_LOGGING_TEST_VALUE_2); - } - - // ********** EJB or Metadata Level tests ********** - public void testSetEJBOrMetadataLoggingLevel() throws Exception { - this.verifyModelInitialized( - EJB_OR_METADATA_LOGGING_KEY, - EJB_OR_METADATA_LOGGING_TEST_VALUE); - this.verifySetProperty( - EJB_OR_METADATA_LOGGING_KEY, - EJB_OR_METADATA_LOGGING_TEST_VALUE, - EJB_OR_METADATA_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveEJBOrMetadataLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - EJB_OR_METADATA_LOGGING_KEY, - EJB_OR_METADATA_LOGGING_TEST_VALUE, - EJB_OR_METADATA_LOGGING_TEST_VALUE_2); - } - - // ********** Metamodel Level tests ********** - public void testSetMetamodelLoggingLevel() throws Exception { - this.verifyModelInitialized( - METAMODEL_LOGGING_KEY, - METAMODEL_LOGGING_TEST_VALUE); - this.verifySetProperty( - METAMODEL_LOGGING_KEY, - METAMODEL_LOGGING_TEST_VALUE, - METAMODEL_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveMetamodelLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - METAMODEL_LOGGING_KEY, - METAMODEL_LOGGING_TEST_VALUE, - METAMODEL_LOGGING_TEST_VALUE_2); - } - - // ********** Weaver Level tests ********** - public void testSetWeaverLoggingLevel() throws Exception { - this.verifyModelInitialized( - WEAVER_LOGGING_KEY, - WEAVER_LOGGING_TEST_VALUE); - this.verifySetProperty( - WEAVER_LOGGING_KEY, - WEAVER_LOGGING_TEST_VALUE, - WEAVER_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveWeaverLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - WEAVER_LOGGING_KEY, - WEAVER_LOGGING_TEST_VALUE, - WEAVER_LOGGING_TEST_VALUE_2); - } - - // ********** Properties Level tests ********** - public void testSetPropertiesLoggingLevel() throws Exception { - this.verifyModelInitialized( - PROPERTIES_LOGGING_KEY, - PROPERTIES_LOGGING_TEST_VALUE); - this.verifySetProperty( - PROPERTIES_LOGGING_KEY, - PROPERTIES_LOGGING_TEST_VALUE, - PROPERTIES_LOGGING_TEST_VALUE_2); - } - - public void testAddRemovePropertiesLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - PROPERTIES_LOGGING_KEY, - PROPERTIES_LOGGING_TEST_VALUE, - PROPERTIES_LOGGING_TEST_VALUE_2); - } - - // ********** Server Level tests ********** - public void testSetServerLoggingLevel() throws Exception { - this.verifyModelInitialized( - SERVER_LOGGING_KEY, - SERVER_LOGGING_TEST_VALUE); - this.verifySetProperty( - SERVER_LOGGING_KEY, - SERVER_LOGGING_TEST_VALUE, - SERVER_LOGGING_TEST_VALUE_2); - } - - public void testAddRemoveServerLoggingLevel() throws Exception { - this.verifyAddRemoveProperty( - SERVER_LOGGING_KEY, - SERVER_LOGGING_TEST_VALUE, - SERVER_LOGGING_TEST_VALUE_2); - } -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java deleted file mode 100644 index f6c4de3b99..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0OptionsTests.java +++ /dev/null @@ -1,519 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.persistence; - -import java.util.ListIterator; - -import org.eclipse.jpt.common.utility.model.event.ListAddEvent; -import org.eclipse.jpt.common.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.common.utility.model.event.ListClearEvent; -import org.eclipse.jpt.common.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.common.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.v2_0.context.persistence.options.Options2_0; - -/** - * EclipseLinkOptions2_0Tests - */ -public class EclipseLink2_0OptionsTests extends EclipseLink2_0PersistenceUnitTestCase -{ - private Options2_0 options; - private ListChangeEvent prePersistEvent; - private ListChangeEvent preUpdateEvent; - private ListChangeEvent preRemoveEvent; - - public static final String LOCK_TIMEOUT_KEY = Options2_0.PERSISTENCE_LOCK_TIMEOUT; - public static final Integer LOCK_TIMEOUT_TEST_VALUE = 100; - public static final Integer LOCK_TIMEOUT_TEST_VALUE_2 = 200; - - public static final String QUERY_TIMEOUT_KEY = Options2_0.PERSISTENCE_QUERY_TIMEOUT; - public static final Integer QUERY_TIMEOUT_TEST_VALUE = 100; - public static final Integer QUERY_TIMEOUT_TEST_VALUE_2 = 200; - - public static final String VALIDATION_GROUP_PRE_PERSIST_KEY = Options2_0.PERSISTENCE_VALIDATION_GROUP_PRE_PERSIST; - public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE = "test_pre-persist_group"; - public static final String VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2 = "test_2_pre-persist_group"; - - public static final String VALIDATION_GROUP_PRE_UPDATE_KEY = Options2_0.PERSISTENCE_VALIDATION_GROUP_PRE_UPDATE; - public static final String VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE = "test_pre-update_group"; - public static final String VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2 = "test_2_pre-update_group"; - - public static final String VALIDATION_GROUP_PRE_REMOVE_KEY = Options2_0.PERSISTENCE_VALIDATION_GROUP_PRE_REMOVE; - public static final String VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE = "test_pre-remove_group"; - public static final String VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2 = "test_2_pre-remove_group"; - - // ********** constructors ********** - public EclipseLink2_0OptionsTests(String name) { - super(name); - } - - // ********** behavior ********** - @Override - protected void setUp() throws Exception { - super.setUp(); - this.options = (Options2_0) this.subject.getOptions(); - PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener(); - - this.options.addPropertyChangeListener(Options2_0.LOCK_TIMEOUT_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options2_0.QUERY_TIMEOUT_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, propertyChangeListener); - this.options.addPropertyChangeListener(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, propertyChangeListener); - - ListChangeListener validationGroupListChangeListener = this.buildValidationGroupListChangeListener(); - this.options.addListChangeListener(Options2_0.VALIDATION_GROUP_PRE_PERSIST_LIST, validationGroupListChangeListener); - this.options.addListChangeListener(Options2_0.VALIDATION_GROUP_PRE_UPDATE_LIST, validationGroupListChangeListener); - this.options.addListChangeListener(Options2_0.VALIDATION_GROUP_PRE_REMOVE_LIST, validationGroupListChangeListener); - - this.clearEvent(); - } - - /** - * Initializes directly the PersistenceUnit properties before testing. - */ - @Override - protected void populatePu() { - this.modelPropertiesSizeOriginal = 5; // PersistenceUnit properties - this.propertiesTotal = this.modelPropertiesSizeOriginal + 1; // 1 misc properties - this.modelPropertiesSize = this.modelPropertiesSizeOriginal; - - // Initializes PersistenceUnit properties - this.persistenceUnitSetProperty(LOCK_TIMEOUT_KEY, LOCK_TIMEOUT_TEST_VALUE.toString()); - this.persistenceUnitSetProperty(QUERY_TIMEOUT_KEY, QUERY_TIMEOUT_TEST_VALUE.toString()); - this.persistenceUnitSetProperty("misc.property.3", "value.3"); - - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_PERSIST_KEY, VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_UPDATE_KEY, VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.persistenceUnitSetProperty(VALIDATION_GROUP_PRE_REMOVE_KEY, VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - } - - @Override - protected PersistenceUnitProperties getModel() { - return this.options; - } - - @Override - protected Object getProperty(String propertyName) throws NoSuchFieldException { - Object modelValue = null; - if (propertyName.equals(Options2_0.LOCK_TIMEOUT_PROPERTY)) - modelValue = this.options.getLockTimeout(); - else if (propertyName.equals(Options2_0.QUERY_TIMEOUT_PROPERTY)) - modelValue = this.options.getQueryTimeout(); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) { - ListIterator iterator = this.options.validationGroupPrePersists(); - modelValue = this.getFirstElement(iterator); - } - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) { - ListIterator iterator = this.options.validationGroupPreUpdates(); - modelValue = this.getFirstElement(iterator); - } - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) { - ListIterator iterator = this.options.validationGroupPreRemoves(); - modelValue = this.getFirstElement(iterator); - } - else - this.throwMissingDefinition("getProperty", propertyName); - return modelValue; - } - - @Override - protected void setProperty(String propertyName, Object newValue) throws Exception { - if (propertyName.equals(Options2_0.LOCK_TIMEOUT_PROPERTY)) - this.options.setLockTimeout((Integer) newValue); - else if (propertyName.equals(Options2_0.QUERY_TIMEOUT_PROPERTY)) - this.options.setQueryTimeout((Integer) newValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.addValidationGroupPrePersist((String) newValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.addValidationGroupPreUpdate((String) newValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.addValidationGroupPreRemove((String) newValue); - else - this.throwMissingDefinition("setProperty", propertyName); - } - - // ********** LockTimeout tests ********** - public void testSetLockTimeout() throws Exception { - this.verifyModelInitialized( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE); - this.verifySetProperty( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE, - LOCK_TIMEOUT_TEST_VALUE_2); - } - - public void testAddRemoveLockTimeout() throws Exception { - this.verifyAddRemoveProperty( - LOCK_TIMEOUT_KEY, - LOCK_TIMEOUT_TEST_VALUE, - LOCK_TIMEOUT_TEST_VALUE_2); - } - - // ********** QueryTimeout tests ********** - public void testSetQueryTimeout() throws Exception { - this.verifyModelInitialized( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE); - this.verifySetProperty( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE, - QUERY_TIMEOUT_TEST_VALUE_2); - } - - public void testAddRemoveQueryTimeout() throws Exception { - this.verifyAddRemoveProperty( - QUERY_TIMEOUT_KEY, - QUERY_TIMEOUT_TEST_VALUE, - QUERY_TIMEOUT_TEST_VALUE_2); - } - - // ********** ValidationGroupPrePersist tests ********** - public void testSetValidationGroupPrePersist() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE); - this.verifySetValidationGroupProperty( - Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPrePersist() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testAddValidationGroupPrePersistCompositeValue() throws Exception { - this.verifyAddCompositeValue( - Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPrePersistCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_KEY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2); - } - - // ********** ValidationGroupPreUpdate tests ********** - public void testSetValidationGroupPreUpdate() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE); - this.verifySetValidationGroupProperty( - Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPreUpdate() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testAddValidationGroupPreUpdateCompositeValue() throws Exception { - this.verifyAddCompositeValue( - Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPreUpdateCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_KEY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2); - } - - // ********** ValidationGroupPreRemove tests ********** - public void testSetValidationGroupPreRemove() throws Exception { - this.verifyModelInitialized( - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE); - this.verifySetValidationGroupProperty( - Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testAddRemoveValidationGroupPreRemove() throws Exception { - this.verifyAddRemoveValidationGroupProperty( - Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testAddValidationGroupPreRemoveCompositeValue() throws Exception { - this.verifyAddCompositeValue( - Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - public void testRemoveValidationGroupPreRemoveCompositeValue() throws Exception { - this.verifyRemoveCompositeValue( - Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_KEY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2); - } - - // ********** ValidationGroups list ********** - public void testValidationGroupsList() throws Exception { - this.verifyListEvents( - Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY, - VALIDATION_GROUP_PRE_PERSIST_TEST_VALUE_2, - Options2_0.VALIDATION_GROUP_PRE_PERSIST_LIST); - - this.verifyListEvents( - Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY, - VALIDATION_GROUP_PRE_UPDATE_TEST_VALUE_2, - Options2_0.VALIDATION_GROUP_PRE_UPDATE_LIST); - - this.verifyListEvents( - Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY, - VALIDATION_GROUP_PRE_REMOVE_TEST_VALUE_2, - Options2_0.VALIDATION_GROUP_PRE_REMOVE_LIST); - } - - // ********** override ********** - - @Override - protected void clearEvent() { - super.clearEvent(); - this.prePersistEvent = null; - this.preUpdateEvent = null; - this.preRemoveEvent = null; - } - - // ****** convenience methods ******* - - // ********** verify ValidationGroup property ********** - protected void verifySetValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - // Replace - this.persistenceUnitSetProperty(key, testValue2, true); - this.propertiesTotal++; - this.verifyPutValidationGroupProperty(propertyName, testValue1); - } - - @SuppressWarnings("unused") - protected void verifyAddRemoveValidationGroupProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - assertTrue(this.validationGroupValueExists(propertyName, (String)testValue1)); - // Remove - this.clearEvent(); - --this.propertiesTotal; - --this.modelPropertiesSize; - this.getPersistenceUnit().removeProperty(key, (String)testValue1); - assertFalse(this.validationGroupValueExists(propertyName, (String)testValue1)); - assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1); - - // Add original Property - ++this.propertiesTotal; - ++this.modelPropertiesSize; - this.persistenceUnitSetProperty(key, testValue1, true); - this.verifyPutValidationGroupProperty(propertyName, testValue1); - } - - protected void verifyAddCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - String stringTestValue1 = (String)testValue1; - String stringTestValue2 = (String)testValue2; - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertEquals(this.getValidationGroupSize(propertyName), 1); - this.addValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 2); - - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue2)); - - String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); - assertTrue(propertyValue.indexOf(stringTestValue1) != -1); - assertTrue(propertyValue.indexOf(stringTestValue2) != -1); - } - - protected void verifyRemoveCompositeValue(String propertyName, String key, Object testValue1, Object testValue2) throws Exception { - String stringTestValue1 = (String)testValue1; - String stringTestValue2 = (String)testValue2; - assertTrue(this.validationGroupValueExists(propertyName, stringTestValue1)); - assertEquals(this.getValidationGroupSize(propertyName), 1); - this.addValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 2); - - this.removeValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 1); - assertFalse(this.validationGroupValueExists(propertyName, stringTestValue2)); - String propertyValue = this.getPersistenceUnit().getProperty(key).getValue(); - assertTrue(propertyValue.indexOf(stringTestValue1) != -1); - assertTrue(propertyValue.indexOf(stringTestValue2) == -1); - - this.removeValidationGroupValue(propertyName, stringTestValue2); - assertEquals(this.getValidationGroupSize(propertyName), 1); - - this.removeValidationGroupValue(propertyName, stringTestValue1); - assertEquals(this.getValidationGroupSize(propertyName), 0); - assertFalse(this.validationGroupValueExists(propertyName, stringTestValue1)); - - assertNull(this.getPersistenceUnit().getProperty(key)); - } - - protected void verifyListEvents(String propertyName, String testValue, String listName) throws Exception { - // add - this.clearEvent(); - this.addValidationGroupValue(propertyName, testValue); - - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event for the expected property - assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); - - // remove - this.clearEvent(); - - this.removeValidationGroupValue(propertyName, testValue); - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event for the expected property - assertEquals("Wrong Event.", this.getEventFor(propertyName).getListName(), listName); - } - - protected void verifyPutValidationGroupProperty(String propertyName, Object expectedValue) throws Exception { - // verify event received - assertNotNull("No Event Fired.", this.getEventFor(propertyName)); - // verify event value - assertTrue(this.validationGroupValueExists(propertyName, (String) expectedValue)); - return; - } - - // ********** internal method ********** - - private ListChangeListener buildValidationGroupListChangeListener() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsRemoved(ListRemoveEvent e) { - EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsReplaced(ListReplaceEvent e) { - EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void itemsMoved(ListMoveEvent e) { - EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void listCleared(ListClearEvent e) { - EclipseLink2_0OptionsTests.this.throwUnsupportedOperationException(e); - } - - public void listChanged(ListChangeEvent e) { - - EclipseLink2_0OptionsTests.this.validationGroupChanged(e); - } - }; - } - - private void validationGroupChanged(ListChangeEvent e) { - String listName = e.getListName(); - - if (listName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_LIST)) - this.prePersistEvent = e; - else if (listName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_LIST)) - this.preUpdateEvent = e; - else if (listName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_LIST)) - this.preRemoveEvent = e; - else - this.throwUnsupportedOperationException(e); - } - - private void addValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { - if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.addValidationGroupPrePersist(propertyValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.addValidationGroupPreUpdate(propertyValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.addValidationGroupPreRemove(propertyValue); - else - this.throwMissingDefinition("addValidationGroupValue", propertyName); - } - - private void removeValidationGroupValue(String propertyName, String propertyValue) throws NoSuchFieldException { - if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - this.options.removeValidationGroupPrePersist(propertyValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - this.options.removeValidationGroupPreUpdate(propertyValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - this.options.removeValidationGroupPreRemove(propertyValue); - else - this.throwMissingDefinition("removeValidationGroupValue", propertyName); - } - - private boolean validationGroupValueExists(String propertyName, String propertyValue) throws NoSuchFieldException { - boolean result = false; - if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - result = this.options.validationGroupPrePersistExists(propertyValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - result = this.options.validationGroupPreUpdateExists(propertyValue); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - result = this.options.validationGroupPreRemoveExists(propertyValue); - else - this.throwMissingDefinition("verifyValidationGroupValueExists", propertyName); - return result; - } - - private int getValidationGroupSize(String propertyName) throws NoSuchFieldException { - int result = 0; - if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - result = this.options.validationGroupPrePersistsSize(); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - result = this.options.validationGroupPreUpdatesSize(); - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - result = this.options.validationGroupPreRemovesSize(); - else - this.throwMissingDefinition("verifyValidationGroupSize", propertyName); - return result; - } - - private ListChangeEvent getEventFor(String propertyName) throws NoSuchFieldException { - ListChangeEvent event = null; - if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_PERSIST_PROPERTY)) - event = this.prePersistEvent; - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_UPDATE_PROPERTY)) - event = this.preUpdateEvent; - else if (propertyName.equals(Options2_0.VALIDATION_GROUP_PRE_REMOVE_PROPERTY)) - event = this.preRemoveEvent; - else - this.throwMissingDefinition("getEventFor", propertyName); - return event; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0PersistenceUnitTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0PersistenceUnitTestCase.java deleted file mode 100644 index cb485012e1..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/EclipseLink2_0PersistenceUnitTestCase.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.persistence; - -import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.core.JpaFacet; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.tests.internal.context.persistence.PersistenceUnitTestCase; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.platform.EclipseLinkPlatform; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * EclipseLink2_0PersistenceUnitTestCase - */ -public abstract class EclipseLink2_0PersistenceUnitTestCase extends PersistenceUnitTestCase -{ - protected EclipseLinkPersistenceUnit subject; - - protected PropertyValueModel subjectHolder; - - // ********** constructors ********** - protected EclipseLink2_0PersistenceUnitTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject = this.getPersistenceUnit(); - this.subjectHolder = new SimplePropertyValueModel(this.subject); - this.populatePu(); - } - - @Override - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = super.buildJpaConfigDataModel(); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JpaFacet.VERSION_2_0.getVersionString()); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, EclipseLinkPlatform.VERSION_2_0); - return dataModel; - } - - @Override - protected EclipseLinkPersistenceUnit getPersistenceUnit() { - return (EclipseLinkPersistenceUnit) super.getPersistenceUnit(); - } - -} \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/JptEclipseLink2_0CorePersistenceContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/JptEclipseLink2_0CorePersistenceContextModelTests.java deleted file mode 100644 index 7d3e1c8071..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/persistence/JptEclipseLink2_0CorePersistenceContextModelTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2009, 2010 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.eclipselink2_0.core.tests.internal.context.persistence; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * decentralize test creation code - */ -public class JptEclipseLink2_0CorePersistenceContextModelTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptEclipseLink2_0CorePersistenceContextModelTests.class.getPackage().getName()); - - suite.addTestSuite(EclipseLink2_0ConnectionTests.class); - suite.addTestSuite(EclipseLink2_0LoggingTests.class); - suite.addTestSuite(EclipseLink2_0OptionsTests.class); - - return suite; - } - - private JptEclipseLink2_0CorePersistenceContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/test.xml b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/test.xml deleted file mode 100644 index 09669091c6..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/test.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/.classpath b/jpa/tests/org.eclipse.jpt.gen.tests/.classpath deleted file mode 100644 index 482a6d9aa6..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/.classpath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/.project b/jpa/tests/org.eclipse.jpt.gen.tests/.project index 2159feb5ef..633d887433 100644 --- a/jpa/tests/org.eclipse.jpt.gen.tests/.project +++ b/jpa/tests/org.eclipse.jpt.gen.tests/.project @@ -1,28 +1,5 @@ org.eclipse.jpt.gen.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - + renamed to org.eclipse.jpt.jpa.gen.tests + \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 2c6dda4a74..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Jan 15 11:12:14 EST 2008 -eclipse.preferences.version=1 -encoding/=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.jdt.core.prefs b/jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 8bab913c29..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Mon Jul 07 20:13:24 EDT 2008 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.gen.tests/META-INF/MANIFEST.MF deleted file mode 100644 index eb89425bc6..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,14 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.gen.tests -Bundle-Version: 2.0.0 -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.4.0", - org.eclipse.jdt.core;bundle-version="3.4.0", - org.eclipse.jpt.common.utility;bundle-version="1.2.0", - org.eclipse.jpt.jpa.db;bundle-version="1.1.1", - org.eclipse.jpt.gen;bundle-version="1.1.0", - org.junit;bundle-version="3.8.0" -Export-Package: org.eclipse.jpt.gen.tests.internal;x-internal:=true diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/about.html b/jpa/tests/org.eclipse.jpt.gen.tests/about.html deleted file mode 100644 index be534ba44f..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/about.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - -About - - - - - -

About This Content

- -

May 02, 2008

- -

License

- -

The Eclipse Foundation makes available all content in this plug-in -("Content"). Unless otherwise indicated below, the Content is provided to you -under the terms and conditions of the Eclipse Public License Version 1.0 -("EPL"). A copy of the EPL is available at -http://www.eclipse.org/org/documents/epl-v10.php. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the -Content is being redistributed by another party ("Redistributor") and different -terms and conditions may apply to your use of any object code in the Content. -Check the Redistributor's license that was provided with the Content. If no such -license exists, contact the Redistributor. Unless otherwise indicated below, the -terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at -http://www.eclipse.org/.

- - - diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/build.properties b/jpa/tests/org.eclipse.jpt.gen.tests/build.properties deleted file mode 100644 index e68d4bf9e4..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/build.properties +++ /dev/null @@ -1,18 +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 -################################################################################ -javacSource = 1.5 -javacTarget = 1.5 -bin.includes = .,\ - META-INF/,\ - about.html,\ - test.xml,\ - plugin.properties -source.. = src/ -output.. = bin/ diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.gen.tests/plugin.properties deleted file mode 100644 index f81a674adc..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/plugin.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 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 -################################################################################ -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName=Java Persistence Tools Entity Generation Tests -providerName=Eclipse.org diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/EntityGenToolsTests.java b/jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/EntityGenToolsTests.java deleted file mode 100644 index 944e9f402f..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/EntityGenToolsTests.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.gen.tests.internal; - -import java.util.HashSet; -import org.eclipse.jpt.gen.internal.util.EntityGenTools; - -import junit.framework.TestCase; - -/** - * - */ -@SuppressWarnings("nls") -public class EntityGenToolsTests extends TestCase { - - public EntityGenToolsTests(String name) { - super(name); - } - - public void testConvertToUniqueJavaStyleClassName1() { - HashSet names = new HashSet(); - assertEquals("Foo", EntityGenTools.convertToUniqueJavaStyleClassName("Foo", names)); - assertEquals("Foo", EntityGenTools.convertToUniqueJavaStyleClassName("foo", names)); - assertEquals("Foo", EntityGenTools.convertToUniqueJavaStyleClassName("FOO", names)); - assertEquals("Foo", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_", names)); - assertEquals("Foo", EntityGenTools.convertToUniqueJavaStyleClassName("_FOO", names)); - assertEquals("Foo_", EntityGenTools.convertToUniqueJavaStyleClassName("FOO*", names)); - assertEquals("_oo", EntityGenTools.convertToUniqueJavaStyleClassName("5oo", names)); - } - - public void testConvertToUniqueJavaStyleClassName2() { - HashSet names = new HashSet(); - names.add("Foo"); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("Foo", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("foo", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("FOO", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("_FOO", names)); - assertEquals("Foo_", EntityGenTools.convertToUniqueJavaStyleClassName("FOO*", names)); - assertEquals("_oo", EntityGenTools.convertToUniqueJavaStyleClassName("5OO", names)); - } - - public void testConvertToUniqueJavaStyleClassName3() { - HashSet names = new HashSet(); - names.add("foo"); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("Foo", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("foo", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("FOO", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_", names)); - assertEquals("Foo2", EntityGenTools.convertToUniqueJavaStyleClassName("_FOO", names)); - assertEquals("Foo_", EntityGenTools.convertToUniqueJavaStyleClassName("FOO*", names)); - assertEquals("_oo", EntityGenTools.convertToUniqueJavaStyleClassName("5OO", names)); - } - - public void testConvertToUniqueJavaStyleClassName4() { - HashSet names = new HashSet(); - assertEquals("FooBar", EntityGenTools.convertToUniqueJavaStyleClassName("FooBar", names)); - assertEquals("Foo_bar", EntityGenTools.convertToUniqueJavaStyleClassName("foo_bar", names)); - assertEquals("FooBar", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_BAR", names)); - assertEquals("FooBar", EntityGenTools.convertToUniqueJavaStyleClassName("_FOO_BAR", names)); - assertEquals("FooBar", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_BAR_", names)); - assertEquals("FooBar_", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_BAR_*", names)); - assertEquals("_fooBar", EntityGenTools.convertToUniqueJavaStyleClassName("4FOO_BAR", names)); - } - - public void testConvertToUniqueJavaStyleClassName5() { - HashSet names = new HashSet(); - names.add("FooBar"); - assertEquals("FooBar2", EntityGenTools.convertToUniqueJavaStyleClassName("FooBar", names)); - assertEquals("Foo_bar", EntityGenTools.convertToUniqueJavaStyleClassName("foo_bar", names)); - assertEquals("FooBar2", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_BAR", names)); - assertEquals("FooBar2", EntityGenTools.convertToUniqueJavaStyleClassName("_FOO_BAR", names)); - assertEquals("FooBar2", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_BAR_", names)); - assertEquals("FooBar_", EntityGenTools.convertToUniqueJavaStyleClassName("FOO_BAR_*", names)); - assertEquals("_fooBar", EntityGenTools.convertToUniqueJavaStyleClassName("4FOO_BAR", names)); - } - - public void testConvertToUniqueJavaStyleAttributeName1() { - HashSet names = new HashSet(); - assertEquals("foo", EntityGenTools.convertToUniqueJavaStyleAttributeName("Foo", names)); - assertEquals("foo", EntityGenTools.convertToUniqueJavaStyleAttributeName("foo", names)); - assertEquals("foo", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO", names)); - assertEquals("foo", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_", names)); - assertEquals("foo", EntityGenTools.convertToUniqueJavaStyleAttributeName("_FOO", names)); - assertEquals("foo_", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO*", names)); - assertEquals("_oo", EntityGenTools.convertToUniqueJavaStyleAttributeName("5oo", names)); - } - - public void testConvertToUniqueJavaStyleAttributeName2() { - HashSet names = new HashSet(); - names.add("Foo"); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("Foo", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("foo", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("_FOO", names)); - assertEquals("foo_", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO*", names)); - assertEquals("_oo", EntityGenTools.convertToUniqueJavaStyleAttributeName("5OO", names)); - } - - public void testConvertToUniqueJavaStyleAttributeName3() { - HashSet names = new HashSet(); - names.add("foo"); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("Foo", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("foo", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_", names)); - assertEquals("foo2", EntityGenTools.convertToUniqueJavaStyleAttributeName("_FOO", names)); - assertEquals("foo_", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO*", names)); - assertEquals("_oo", EntityGenTools.convertToUniqueJavaStyleAttributeName("5OO", names)); - } - - public void testConvertToUniqueJavaStyleAttributeName4() { - HashSet names = new HashSet(); - assertEquals("fooBar", EntityGenTools.convertToUniqueJavaStyleAttributeName("FooBar", names)); - assertEquals("foo_bar", EntityGenTools.convertToUniqueJavaStyleAttributeName("foo_bar", names)); - assertEquals("fooBar", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_BAR", names)); - assertEquals("fooBar", EntityGenTools.convertToUniqueJavaStyleAttributeName("_FOO_BAR", names)); - assertEquals("fooBar", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_BAR_", names)); - assertEquals("fooBar_", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_BAR_*", names)); - assertEquals("_fooBar", EntityGenTools.convertToUniqueJavaStyleAttributeName("4FOO_BAR", names)); - } - - public void testConvertToUniqueJavaStyleAttributeName5() { - HashSet names = new HashSet(); - names.add("FooBar"); - assertEquals("fooBar2", EntityGenTools.convertToUniqueJavaStyleAttributeName("FooBar", names)); - assertEquals("foo_bar", EntityGenTools.convertToUniqueJavaStyleAttributeName("foo_bar", names)); - assertEquals("fooBar2", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_BAR", names)); - assertEquals("fooBar2", EntityGenTools.convertToUniqueJavaStyleAttributeName("_FOO_BAR", names)); - assertEquals("fooBar2", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_BAR_", names)); - assertEquals("fooBar_", EntityGenTools.convertToUniqueJavaStyleAttributeName("FOO_BAR_*", names)); - assertEquals("_fooBar", EntityGenTools.convertToUniqueJavaStyleAttributeName("4FOO_BAR", names)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/JptGenTests.java b/jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/JptGenTests.java deleted file mode 100644 index 1e79d7d032..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/src/org/eclipse/jpt/gen/tests/internal/JptGenTests.java +++ /dev/null @@ -1,32 +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.gen.tests.internal; - -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.gen.tests.internal.EntityGenToolsTests; - -/** - * - */ -public class JptGenTests { - - public static Test suite() { - TestSuite suite = new TestSuite("JPT Entity Generation Tests"); //$NON-NLS-1$ - suite.addTestSuite(EntityGenToolsTests.class); - return suite; - } - - private JptGenTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.gen.tests/test.xml b/jpa/tests/org.eclipse.jpt.gen.tests/test.xml deleted file mode 100644 index 2b842d92fc..0000000000 --- a/jpa/tests/org.eclipse.jpt.gen.tests/test.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/.classpath b/jpa/tests/org.eclipse.jpt.ui.tests/.classpath deleted file mode 100644 index 382639e1d7..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/.classpath +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/.project b/jpa/tests/org.eclipse.jpt.ui.tests/.project index 0240774761..ab9bd7f596 100644 --- a/jpa/tests/org.eclipse.jpt.ui.tests/.project +++ b/jpa/tests/org.eclipse.jpt.ui.tests/.project @@ -1,28 +1,5 @@ org.eclipse.jpt.ui.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - + renamed to org.eclipse.jpt.jpa.ui.tests + \ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index d364a0f24e..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Mon Apr 07 14:27:16 EDT 2008 -eclipse.preferences.version=1 -encoding/=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.jdt.core.prefs b/jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index d909c105d5..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Sun May 27 14:55:01 EDT 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF deleted file mode 100644 index a8256df8a0..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,23 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.ui.tests -Bundle-Version: 1.0.1 -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: - org.junit;bundle-version="4.3.1", - org.eclipse.core.resources, - org.eclipse.core.runtime, - org.eclipse.jface, - org.eclipse.jpt.common.core.tests, - org.eclipse.jpt.core.tests, - org.eclipse.jpt.core.tests.extension.resource, - org.eclipse.jpt.common.utility, - org.eclipse.jpt.core, - org.eclipse.jpt.ui, - org.eclipse.ui.navigator;bundle-version="3.4.0", - org.eclipse.ui.forms;bundle-version="3.3.100", - org.eclipse.ui.workbench;bundle-version="3.4.0" -Export-Package: org.eclipse.jpt.ui.tests;x-internal:=true, - org.eclipse.jpt.ui.tests.internal.platform;x-internal:=true diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/build.properties b/jpa/tests/org.eclipse.jpt.ui.tests/build.properties deleted file mode 100644 index 50f0aa3fd9..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/build.properties +++ /dev/null @@ -1,13 +0,0 @@ -################################################################################ -# Copyright (c) 2007, 2010 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 -################################################################################ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.ui.tests/plugin.properties deleted file mode 100644 index ac887adeab..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/plugin.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 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 -################################################################################ -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName=Dali Java Persistence Tools - UI Tests -providerName=Eclipse Web Tools Platform diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java deleted file mode 100644 index 0f79d82ce5..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 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.ui.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.ui.tests.internal.platform.JptUiPlatformTests; - -/** - * Runs all JPT UI Tests - */ -public class JptUiTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptUiTests.class.getPackage().getName()); - suite.addTest(JptUiPlatformTests.suite()); - return suite; - } - - private JptUiTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JpaPlatformUiExtensionTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JpaPlatformUiExtensionTests.java deleted file mode 100644 index 3c7cb6eeee..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JpaPlatformUiExtensionTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.ui.tests.internal.platform; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.internal.platform.JpaPlatformManagerImpl; -import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatformProvider; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; - -@SuppressWarnings("nls") -public class JpaPlatformUiExtensionTests extends TestCase -{ - protected TestJpaProject testProject; - - protected static final String PROJECT_NAME = "ExtensionTestProject"; - protected static final String PACKAGE_NAME = "extension.test"; - - public static final String TEST_PLUGIN_CLASS = ExtensionTestPlugin.class.getName(); - public static final String TEST_PLUGIN_ID = ExtensionTestPlugin.PLUGIN_ID; - - public static final String TEST_PLATFORM_ID = TestJpaPlatformProvider.ID; - public static final String TEST_PLATFORM_CLASS = TestJpaPlatformProvider.class.getName(); - public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform"; - - public static final String TEST_UI_PLATFORM_ID = TEST_PLATFORM_ID; - - public JpaPlatformUiExtensionTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.testProject = this.buildJpaProject(PROJECT_NAME, false); // false = no auto-build - } - - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild) throws Exception { - return new TestJpaProject(projectName, autoBuild); // false = no auto-build - } - - @Override - protected void tearDown() throws Exception { - this.testProject.getProject().delete(true, true, null); - this.testProject = null; - super.tearDown(); - } - - protected JpaProject jpaProject() { - return this.testProject.getJpaProject(); - } - - public void testJpaPlatform() { - assertNotNull(JpaPlatformManagerImpl.instance().buildJpaPlatformImplementation(this.testProject.getProject())); - } -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JptUiPlatformTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JptUiPlatformTests.java deleted file mode 100644 index 50bcc99cfc..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JptUiPlatformTests.java +++ /dev/null @@ -1,27 +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.ui.tests.internal.platform; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptUiPlatformTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptUiPlatformTests.class.getPackage().getName()); - suite.addTestSuite(JpaPlatformUiExtensionTests.class); - return suite; - } - - private JptUiPlatformTests() { - super(); - throw new UnsupportedOperationException(); - } -} -- cgit v1.2.3