Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf')
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractActionTest.java138
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTest.java125
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTestAction.java120
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/StoreTestException.java43
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/Utils.java173
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/ConfigurableTestSuite.java107
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/MultiCfgTestSuite.java151
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfiguration.java118
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfigurations.java124
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/Testbed.java168
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.java162
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.persistence.xml25
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AttributeOverridesAction.java60
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BasicAction.java63
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BookAction.java136
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.java231
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.persistence.xml39
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CompositeIdAction.java64
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/DuplicatesAction.java66
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.java136
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.persistence.xml25
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedAction.java156
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.java59
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.persistence.xml22
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EntityAction.java112
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ExternalAction.java137
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ForcedIdBagAction.java114
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/HbMapKeysAction.java110
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdAction.java111
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.java116
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.persistence.xml18
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.java207
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.persistence.xml43
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java224
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml32
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IntegerDiscriminatorAction.java100
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/JoinColumnsAction.java163
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LazyLibraryAction.java224
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.java81
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.persistence.xml18
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ManyToManyAction.java149
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MapKeyAction.java199
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MappedSuperClassAction.java149
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/NaturalIdAction.java168
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OnetoonePKAction.java66
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OverrideSecondaryAction.java116
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/PKeyJoinAction.java89
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondaryTableActionJDO.java98
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.java140
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.persistence.xml25
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetNMAction.java95
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetResourceAction.java199
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.java80
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.persistence.xml34
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.java69
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.persistence.xml19
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.java85
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.persistence.xml25
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/VariousAction.java117
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/_template.persistence.xml15
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/small_play.xml49
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachAction.java217
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachEListAction.java241
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachFeatureMapAction.java284
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1to1Action.java260
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1tonAction.java276
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/RelationntomAction.java196
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/AccountingAction.java81
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CapaAction.java110
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CarAction.java100
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogAction.java301
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogResourceAction.java378
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ClaimAction.java117
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/Ecore.ecore357
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/EcoreAction.java198
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ExtendedPO2Action.java190
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/FleetAction.java129
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ForumAction.java89
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java92
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction_old.persistence.xml15
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/InventoryAction.java92
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/JuliaAction.java60
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryAction.java345
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryCheckNameAction.java59
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryColLengthAction.java149
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDBothAction.java38
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDFeatureIDAction.java39
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryFKAction.java37
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryGlobalEagerAction.java221
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java123
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryLargeAction.java161
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryListAsBagAction.java105
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNonResolvingAction.java231
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNotifyingTestAction.java205
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryQualifyActionHB.java102
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java277
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceCutPasteAction.java148
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceVisitTreeAction.java99
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java183
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryUseMappingFileAction.java129
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryValidateResourceAction.java184
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ListAsIdBagAction.java106
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/MindMapAction.java146
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/NoEscapeLibraryAction.java45
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayAction.java139
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayImExportAction.java54
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PrimerPOAction.java90
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ProductAction.java136
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalMapAsClassAction.java164
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalResourceReferenceAction.java131
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SchoolLibraryAction.java257
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleLibraryResourceAction.java107
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleRentalAction.java105
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SunBooksAction.java297
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/WorkFlowAction.java40
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/debFile.ecore77
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mindmap62
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/default.mmd988
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/library.ecore104
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AnyTypeAction.java237
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/AttributesAction.java106
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DateTimeAction.java108
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DocumentRootAction.java131
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/DurationAction.java102
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/EcoreAttrsAction.java127
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ExtensionAction.java195
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/GroupAction.java197
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListAction.java99
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ListUnionAction.java111
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/MixedAction.java206
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/ModelGroupAction.java44
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/NestedGroupAction.java51
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/QNameAction.java82
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/RestrictionAction.java58
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimpleTypeAction.java434
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SimplefeaturemapAction.java91
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionAction.java203
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/SubstitutionzvonAction.java64
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/schemaconstructs/document_root.xml2
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractReferenceAction.java116
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/AbstractTopClassAction.java103
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ224991Action.java38
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.java38
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296Action.persistence.xml33
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.java38
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ225296_2Action.persistence.xml470
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237361Action.java64
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237498Action.java87
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237790Action.java79
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ237994Action.java64
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247785Action.java67
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ247939Action.java66
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249246Action.java35
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ249440Action.java46
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ253799Action.java52
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277546Action.java55
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ277570Action.java79
-rw-r--r--tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BZ302933Action.java38
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/BagDuplicateAction.java85
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/EnumTestAction.java108
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/FruitsAction.java38
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/GeneralTestAction.java143
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InheritanceAction.java68
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/InterfaceTrueAction.java84
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/LargeMapValueAction.java72
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MTMSameAction.java91
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MainAction.java147
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/MultipleInheritanceAction.java172
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/NavTopAction.java46
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceAction.java99
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/ResourceUnloadAction.java97
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SecondarytableInheritanceAction.java136
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SimplenmAction.java109
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/SupInterfacesAction.java308
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/TopClassesAction.java110
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/issues/UpdateAction.java64
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStore.java148
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/AbstractTestStoreFactory.java64
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/BaseTestDatabaseAdapter.java261
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/HsqldbTestDatabaseAdapter.java95
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/MssqlJDBCTestDatabaseAdapter.java37
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/PgsqlTestDatabaseAdapter.java189
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDBAdapters.java102
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestDatabaseAdapter.java78
-rwxr-xr-xtests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/stores/TestStore.java154
185 files changed, 23294 insertions, 0 deletions
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractActionTest.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractActionTest.java
new file mode 100755
index 000000000..90ae9c790
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractActionTest.java
@@ -0,0 +1,138 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: AbstractActionTest.java,v 1.8 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test;
+
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+
+/**
+ * Hibernate test based on abstract action.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class AbstractActionTest extends AbstractTest {
+ /** The action contains the real test */
+ protected AbstractTestAction itsTestAction;
+
+ private Properties properties;
+
+ /** Constructor */
+ public AbstractActionTest(Class<?> testActionClass) {
+ super("testAction");
+ try {
+ itsTestAction = (AbstractTestAction) testActionClass.newInstance();
+ } catch (Exception e) {
+ throw new StoreTestException("Exception while instantiating " + testActionClass.getName(), e);
+ }
+ }
+
+ /** Constructor */
+ public AbstractActionTest(AbstractTestAction itsTestAction) {
+ this(itsTestAction, null);
+ }
+
+ /**
+ * Constructs an instance with additional OR-mapping properties.
+ *
+ * @param itsTestAction
+ * @param properties
+ */
+ public AbstractActionTest(AbstractTestAction itsTestAction, Properties properties) {
+ super("testAction");
+ this.itsTestAction = itsTestAction;
+ this.properties = properties;
+ }
+
+ /** returns the underlying test action */
+ public AbstractTestAction getTestAction() {
+ return itsTestAction;
+ }
+
+ /** The actual test run */
+ public void testAction() {
+ getTestAction().doAction(getStore());
+ }
+
+ /** Return the epackages for which this test is done */
+ @Override
+ public EPackage[] getEPackages() {
+ return getTestAction().getEPackages();
+ }
+
+ /** Return the test package name */
+ @Override
+ public String getTestPackageName() {
+ return getTestAction().getTestPackageName();
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties props) {
+ properties = props;
+ }
+
+ /** Return the test package name */
+ @Override
+ public Package getTestPackage() {
+ return getTestAction().getClass().getPackage();
+ }
+
+ /** Returns extra properties which are passed to the or layer for additional configuration */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ Properties allProperties = getTestAction().getExtraConfigurationProperties();
+
+ // override some defaults
+ if (allProperties.get(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT) == null) {
+ allProperties.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ }
+
+ if (allProperties.get(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY) == null) {
+ allProperties.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY, "ejb3");
+ }
+
+ if (this.properties != null) {
+ allProperties.putAll(this.properties);
+ }
+ return allProperties;
+ }
+
+ /** Add extensions if you want */
+ @Override
+ public void setExtensions(ExtensionManager extensionManager) {
+ getTestAction().setExtensions(extensionManager);
+ }
+
+ /** Returns a unique name based on the class name of the testAction class */
+ @Override
+ public String getName() {
+ return itsTestAction.getClass().getName();
+ }
+
+ /** Returns a simple name based on the class name of the testAction class. */
+ @Override
+ public String getSimpleName() {
+ final String name = getName();
+ return name.substring(name.lastIndexOf(".") + 1);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTest.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTest.java
new file mode 100755
index 000000000..6b76aa125
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTest.java
@@ -0,0 +1,125 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: AbstractTest.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+import org.eclipse.emf.teneo.test.conf.Testbed;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Base class for hibernate store based tests. The tests inheriting from this class will get a
+ * dedicated store to be used in order to perform the test.
+ *
+ * <p>
+ * The standard test suite will run such tests once for each configured test setting (see
+ * test.properties).
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public abstract class AbstractTest extends TestCase {
+ // very strange but there was a compile (or runtime) error in one of the ecore packages, had to
+ // set this
+ static {
+ System.setProperty("org.eclipse.emf.ecore.EPackage.Registry.INSTANCE",
+ "org.eclipse.emf.ecore.impl.EPackageRegistryImpl");
+ }
+
+ /** The test store is the connection to the database and specific datalayer actions */
+ private TestStore itsStore;
+
+ /** Keep track if the run failed (exception occured) */
+ private boolean lastRunFailed;
+
+ /**
+ * @return Returrns true if last run failed. Meaningless if invoked before the test method
+ * completes, reports correct value if invoked in tearDown.
+ */
+ public final boolean lastRunFailed() {
+ return lastRunFailed;
+ }
+
+ /** Set of epackages for which this test runs */
+ public abstract EPackage[] getEPackages();
+
+ /** Return the test package name */
+ public abstract String getTestPackageName();
+
+ /** The test method (testAction) */
+ AbstractTest(String testMethod) {
+ super(testMethod);
+ }
+
+ /** Return the store used */
+ protected TestStore getStore() {
+ return itsStore;
+ }
+
+ /** Setup the store */
+ @Override
+ public void setUp() throws Exception {
+ itsStore = Testbed.instance().createStore(this);
+ }
+
+ /** Run the test */
+ @Override
+ protected void runTest() throws Throwable {
+ try {
+ lastRunFailed = false;
+ super.runTest();
+ } catch (Throwable t) {
+ lastRunFailed = true;
+ throw t;
+ }
+ }
+
+ /** Tear down after the test */
+ @Override
+ public void tearDown() {
+ getStore().tearDown(!lastRunFailed);
+ }
+
+ /** Returns extra properties which are passed to the or layer for additional configuration */
+ public Properties getExtraConfigurationProperties() {
+ return new Properties();
+ }
+
+ /** Add extensions if you want */
+ public void setExtensions(ExtensionManager extensionManager) {
+
+ }
+
+ /** Returns a name based on the class name of the testAction class. */
+ @Override
+ public String getName() {
+ return this.getClass().getName();
+ }
+
+ /** Returns a simple name based on the class name of the testAction class. */
+ public String getSimpleName() {
+ return this.getClass().getSimpleName();
+ }
+
+ /** Return the test package name */
+ public abstract Package getTestPackage();
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTestAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTestAction.java
new file mode 100755
index 000000000..01d8191c4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/AbstractTestAction.java
@@ -0,0 +1,120 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: AbstractTestAction.java,v 1.9 2009/12/16 16:14:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test;
+
+import java.net.URL;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+import org.eclipse.emf.teneo.test.conf.ConfigurableTestSuite;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Abstract TestAction used in backend specific test cases.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.9 $
+ */
+public abstract class AbstractTestAction extends TestCase {
+ // very strange but there was a compile (or runtime) error in one of the ecore packages, had to
+ // set this
+ static {
+ System.setProperty("org.eclipse.emf.ecore.EPackage.Registry.INSTANCE",
+ "org.eclipse.emf.ecore.impl.EPackageRegistryImpl");
+ }
+
+ /** The epackage */
+ private EPackage[] epackages = null;
+
+ /**
+ * Constructor for test without epackages
+ */
+ public AbstractTestAction() {
+ this((EPackage[]) null);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param the
+ * epackage for which this test is run
+ */
+ public AbstractTestAction(EPackage epackage) {
+ this(new EPackage[] { epackage });
+ }
+
+ /**
+ * Constructor for array of epackages
+ *
+ * @param epackages
+ */
+ public AbstractTestAction(EPackage[] epackages) {
+ this.epackages = epackages;
+ }
+
+ public EPackage[] getEPackages() {
+ return epackages;
+ }
+
+ /** Return the packagename of the test sample, Is needed in case of non emf test cases */
+ public String getTestPackageName() {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ /** Performs the actual test action */
+ public abstract void doAction(TestStore store);
+
+ /**
+ * Can be overridden by subclass returns properties which control the or layer. Such as setting of eager loading.
+ */
+ public Properties getExtraConfigurationProperties() {
+ return new Properties();
+ }
+
+ /** Add extensions if you want */
+ public void setExtensions(ExtensionManager extensionManager) {
+
+ }
+
+ /**
+ * Returns the path of the XML persistence mapping file on the classpath or null if none is available.
+ * <p>
+ * Returning non-null will cause the TestAction to be run twice: first for a PAnnotatedModel populated from
+ * EAnnotations and then for a PAnnotatedModel populated from the XML persistence mapping.
+ * <p>
+ * This implementation looks for a mapping file on the classpath named &lt;class name&gt;.persistence.xml, returning
+ * its path if it exists or null if it does not.
+ *
+ * @see ConfigurableTestSuite
+ */
+ public String getPersistenceXmlPath() {
+ final String path = getClass().getName().replace('.', '/') + ".persistence.xml";
+ // Note: use ClassLoader.getResource() instead of Class.getResource().
+ final URL resource = getClass().getClassLoader().getResource(path);
+ if (resource == null) {
+ return null;
+ }
+ return path;
+ }
+
+ protected boolean isEAVTest() {
+ return this.getClass().getName().contains("EAV");
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/StoreTestException.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/StoreTestException.java
new file mode 100755
index 000000000..26052164a
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/StoreTestException.java
@@ -0,0 +1,43 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * StoreTestException.java,v 1.4 2007/02/01 12:35:37 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test;
+
+import org.eclipse.emf.teneo.TeneoException;
+
+/**
+ * This exception is the base class of all exceptions which occur in the generation process. This
+ * class offers automatic logging to commons logging. Note that this class extends RuntimeException,
+ * so no forced throws and catch statements. Although there are very differing views on this topic
+ * but it is our experience that to many checked exceptions only distract the programmer and have no
+ * added value.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $ $Date: 2008/02/28 07:08:16 $
+ */
+
+public class StoreTestException extends TeneoException {
+ /**
+ * A serialized version id
+ */
+ private static final long serialVersionUID = -6313295414030858545L;
+
+ /**
+ * The constructor, logs the exception also
+ */
+ public StoreTestException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ /**
+ * The constructor, logs the exception also
+ */
+ public StoreTestException(String msg) {
+ super(msg);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/Utils.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/Utils.java
new file mode 100755
index 000000000..a0fbf94cf
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/Utils.java
@@ -0,0 +1,173 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: Utils.java,v 1.4 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.samples.SamplesSource;
+
+/**
+ * Contains utility methods for testing.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $ $Date: 2008/02/28 07:08:16 $
+ */
+
+public class Utils {
+ /** The propertyname used to specify which database to use */
+ public static String DATABASE_PROP_NAME = "database";
+
+ /**
+ * Returns test properties.
+ */
+ public static Properties getTestProperties() {
+ // set the log4j properties
+ // PropertyConfigurator.configure(Utils.class.getResource("log4j.properties"));
+
+ final Properties props = new Properties();
+ try {
+ final InputStream is = Utils.class.getResourceAsStream("test.properties");
+ props.load(is);
+ is.close();
+ } catch (Exception e) {
+ throw new StoreTestException("Exception when loading properties file test.properties", e);
+ }
+ return props;
+ }
+
+ // /**
+ // * Returns an array of test properties for one or more databases.
+ // */
+ // public static Properties[] getAllTestProperties()
+ // {
+ // // read all the testproperties
+ // final Properties props = new Properties();
+ // try
+ // {
+ // final InputStream is = Utils.class.getResourceAsStream("/test.properties");
+ // props.load(is);
+ // is.close();
+ // }
+ // catch (Exception e)
+ // {
+ // throw new StoreTestException("Exception when loading properties file test.properties", e);
+ // }
+ //
+ // return hiearchizeProps(props);
+ // }
+
+ public static Map hiearchizeProps(final Properties props) {
+ Map hProps = new HashMap();
+ for (Iterator i = props.keySet().iterator(); i.hasNext();) {
+ String propName = (String) i.next();
+ int delimitAt = propName.indexOf('.');
+ String propPrefix = (delimitAt < 0) ? propName : propName.substring(0, delimitAt);
+ String propSuffix = (delimitAt < 0) ? "." : propName.substring(delimitAt + 1);
+
+ Properties subProps = (Properties) hProps.get(propPrefix);
+ if (subProps == null) {
+ subProps = new Properties();
+ hProps.put(propPrefix, subProps);
+ }
+ subProps.put(propSuffix, props.getProperty(propName));
+ }
+ return hProps;
+ }
+
+ /**
+ * Returns the directory which contains the sources which are to be parsed.
+ */
+ public static String getStartSource(String packageName) {
+ try {
+ return SamplesSource.getSourceDirectory(packageName).getAbsolutePath();
+ } catch (FileNotFoundException e) {
+ throw new StoreTestException("Cannot find source folder for package " + packageName, e);
+ }
+ }
+
+ /**
+ * Returns the outputdirectory
+ */
+ public static String getOutputDirectory() {
+ // this file is now in test/src/org/elver/store/test/Utils.class
+ File file = new File(Utils.class.getResource('/' + Utils.class.getName().replace('.', '/') + ".class").getFile());
+
+ // now go up 5 directories:
+ // Utils test store elver org bin
+ return file.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile().getAbsolutePath();
+ }
+
+ /**
+ * Returns the outputlocation of the package of the passed class
+ */
+ public static String getOutputDirectory(String className) {
+ // this file is now in test/src/org/elver/store/test/Utils.class
+ File file = new File(Utils.class.getResource('/' + Utils.class.getName().replace('.', '/') + ".class").getFile());
+
+ // now go up 5 directories:
+ // Utils test store elver org bin
+ file = file.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile();
+
+ // now go down again to the package
+ String path = className.replace('.', File.separatorChar);
+ path = path.substring(0, path.lastIndexOf(File.separatorChar));
+
+ file = new File(file, path);
+
+ if (!file.exists()) {
+ throw new StoreTestException("Directory " + file.getAbsolutePath() + " within test directory does not exist. Tried path: "
+ + file.getAbsolutePath());
+ }
+ return file.getAbsolutePath();
+ }
+
+ /** Copies a file */
+ public static void copyFile(File src, File dst) throws IOException {
+ InputStream in = new FileInputStream(src);
+ OutputStream out = new FileOutputStream(dst);
+
+ // Transfer bytes from in to out
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+
+ /** Returns the output location of the passed class, only supports directories (no jars!) */
+ public static File getClassParentDirectory(Class cls) {
+ final ClassLoader clsl = cls.getClassLoader();
+ final String clsFile = cls.getName ().replace ('.', '/').concat (".class");
+ final URL url = clsl != null ? clsl.getResource(clsFile) :
+ ClassLoader.getSystemResource(clsFile);
+ final File file = new File(url.getFile());
+ return file.getParentFile();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/ConfigurableTestSuite.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/ConfigurableTestSuite.java
new file mode 100755
index 000000000..a811b0ed1
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/ConfigurableTestSuite.java
@@ -0,0 +1,107 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * Davide Marchignoli
+ * </copyright>
+ *
+ * $Id: ConfigurableTestSuite.java,v 1.5 2008/05/27 07:42:12 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.conf;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import org.eclipse.emf.teneo.test.AbstractActionTest;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+
+/**
+ * The configurable test suite takes care of setting the active configuration before starting the
+ * test.
+ *
+ * @author Davide Marchignoli
+ * @author Martin Taal
+ * @version $Revision: 1.5 $
+ */
+public class ConfigurableTestSuite extends TestSuite {
+
+ /** the configuration that will be used to rn the tests */
+ final TestConfiguration runConfiguration;
+
+ /**
+ * Constructs a TestSuite whose tests will be run in the given configuration.
+ */
+ public ConfigurableTestSuite(TestConfiguration cfg, String name) {
+ super(name);
+ this.runConfiguration = cfg;
+ }
+
+ /**
+ * Constructs a TestSuite whose tests will be run in the given configuration.
+ */
+ public ConfigurableTestSuite(TestConfiguration cfg) {
+ this(cfg, cfg == null ? "Null configuration" : cfg.getName());
+ }
+
+ /** Gets the configuration of this run */
+ public TestConfiguration getRunConfiguration() {
+ return runConfiguration;
+ }
+
+ /** Run the test using the specified configuration */
+ @Override
+ public void runTest(Test test, TestResult result) {
+ if (Testbed.instance().getActiveConfiguration() != runConfiguration) {
+ Testbed.instance().setActiveConfiguration(getRunConfiguration());
+ }
+ super.runTest(test, result);
+ }
+
+ /**
+ * Returns a test which will fail and log a warning message.
+ */
+ public static Test warning(final String message) {
+ return new TestCase("warning") {
+ @Override
+ protected void runTest() {
+ fail(message);
+ }
+ };
+ }
+
+ /** Encapsulates an action object in a test */
+ protected TestSuite createTestForAction(Class actionClass) {
+ TestSuite componentSuite = new TestSuite(actionClass.getName());
+ Test componentTest;
+ try {
+ componentTest = new AbstractActionTest((AbstractTestAction) actionClass.newInstance());
+ } catch (Throwable e) {
+ componentTest = warning("Cannot istantiate " + actionClass.getName() + " due to\n" + e.getMessage());
+ }
+ componentSuite.addTest(componentTest);
+ return componentSuite;
+ }
+
+ /**
+ * Handles specially testClass derived from AbstractTestAction. For this class a suite is
+ * created acting as a corresponding subclass of AbstractHibernateActionTest
+ */
+ @Override
+ public void addTestSuite(Class testClass) {
+ if (AbstractTestAction.class.isAssignableFrom(testClass)) {
+ super.addTest(createTestForAction(testClass));
+ } else {
+ super.addTestSuite(testClass);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/MultiCfgTestSuite.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/MultiCfgTestSuite.java
new file mode 100755
index 000000000..c6bd7f0fc
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/MultiCfgTestSuite.java
@@ -0,0 +1,151 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * Davide Marchignoli
+ * </copyright>
+ *
+ * $Id: MultiCfgTestSuite.java,v 1.5 2008/02/28 07:08:17 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.conf;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.test.AbstractActionTest;
+import org.eclipse.emf.teneo.test.AbstractTest;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+
+/**
+ * Test suite containing a subsuite for each configuration.
+ *
+ * @author Davide Marchignoli
+ * @author Martin Taal
+ * @version $Revision: 1.5 $
+ */
+public class MultiCfgTestSuite extends TestSuite {
+
+ /** map indexed by available configurations with values on ConfigurableTestSuite */
+ private Map suitesByCfg = new HashMap();
+
+ /** Constructor */
+ public MultiCfgTestSuite(String name, TestConfigurations availableCfgs) {
+ this(availableCfgs);
+ setName(name);
+ }
+
+ /** Constructor with the available configs */
+ public MultiCfgTestSuite(TestConfigurations availableCfgs) {
+ super();
+ for (Iterator i = availableCfgs.getConfigurations().iterator(); i.hasNext();) {
+ TestConfiguration cfg = (TestConfiguration) i.next();
+ ConfigurableTestSuite innerSuite = new ConfigurableTestSuite(cfg);
+ addTest(innerSuite);
+ suitesByCfg.put(cfg, innerSuite);
+ }
+ }
+
+ /** Add one test suite for a specific config */
+ protected void addTestSuite(Class testSuite, TestConfiguration cfg) {
+ ((ConfigurableTestSuite) suitesByCfg.get(cfg)).addTestSuite(testSuite);
+ }
+
+ /**
+ * Adds a persistence XML test suite if the TestAction has an associated "&ltActionClass&gt;.persistence.xml" file.
+ *
+ * @param testActionClass
+ * @param testConfiguration
+ */
+ private void addPersistenceXmlTestSuite(Class testActionClass, TestConfiguration testConfiguration) {
+ final AbstractTestAction testAction;
+ try {
+ testAction = (AbstractTestAction) testActionClass.newInstance();
+ } catch (Exception e) {
+ throw new AssertionError(e);
+ }
+
+ final String xmlPersistenceMappingPath = testAction.getPersistenceXmlPath();
+ if (xmlPersistenceMappingPath != null) {
+ // Run this TestAction with XML persistence mapping.
+ final Properties properties = new Properties();
+ properties.setProperty(PersistenceOptions.PERSISTENCE_XML, xmlPersistenceMappingPath);
+ // Ignore the existing EAnnotations, since we want to test only the XML mapping.
+ properties.setProperty(PersistenceOptions.IGNORE_EANNOTATIONS, "true");
+
+ TestSuite testSuite = new TestSuite(testActionClass.getName() + " (persistence.xml)");
+ testSuite.addTest(new AbstractActionTest(testAction, properties));
+ ((TestSuite) suitesByCfg.get(testConfiguration)).addTest(testSuite);
+ }
+ }
+
+ /** Add one test suite for a specific config */
+ protected void addTest(AbstractActionTest test, TestConfiguration cfg) {
+ ((ConfigurableTestSuite) suitesByCfg.get(cfg)).addTest(test);
+ }
+
+ /** Add a test class */
+ @Override
+ public void addTestSuite(Class testClass) {
+ if (AbstractTest.class.isAssignableFrom(testClass) || AbstractTestAction.class.isAssignableFrom(testClass)) {
+ for (Iterator i = suitesByCfg.keySet().iterator(); i.hasNext();) {
+ final TestConfiguration testConfiguration = (TestConfiguration) i.next();
+ if (!testConfiguration.isXml()) {
+ addTestSuite(testClass, testConfiguration);
+ } else if (AbstractTestAction.class.isAssignableFrom(testClass)) {
+ addPersistenceXmlTestSuite(testClass, testConfiguration);
+ }
+ }
+ } else {
+ super.addTestSuite(testClass);
+ }
+ }
+
+ /** Add a test action */
+ public void addTest(AbstractActionTest test) {
+ for (Iterator i = suitesByCfg.keySet().iterator(); i.hasNext();) {
+ final TestConfiguration tc = (TestConfiguration) i.next();
+ if (tc.isXml()) {
+ if (test.getTestAction().getPersistenceXmlPath() != null) {
+ if (test.getProperties() == null) {
+ test.setProperties(new Properties());
+ }
+ final Properties properties = test.getProperties();
+ properties.setProperty(PersistenceOptions.PERSISTENCE_XML, test.getTestAction()
+ .getPersistenceXmlPath());
+ properties.setProperty(PersistenceOptions.IGNORE_EANNOTATIONS, "true");
+ addTest(test, tc);
+ }
+ } else {
+ addTest(test, tc);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestSuite#addTest(junit.framework.Test)
+ */
+ @Override
+ public void addTest(Test test) {
+ if (test instanceof AbstractActionTest) {
+ addTest((AbstractActionTest) test);
+ } else {
+ super.addTest(test);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfiguration.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfiguration.java
new file mode 100755
index 000000000..25a7b1d82
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfiguration.java
@@ -0,0 +1,118 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * Davide Marchignoli
+ * </copyright>
+ *
+ * $Id: TestConfiguration.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.conf;
+
+import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
+import org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter;
+
+/**
+ * Contains the parameters which define how the test should be run, for example inheritance mapping.
+ *
+ * @author Davide Marchignoli
+ * @author Martin Taal
+ * @version $Revision: 1.5 $
+ */
+public class TestConfiguration {
+
+ private final String name;
+
+ private final TestDatabaseAdapter dbAdapter;
+
+ private final InheritanceType mappingStrategy;
+
+ private final boolean optimistic;
+
+ private final boolean ejb3;
+
+ private final boolean xml;
+
+ /** Constructor */
+ public TestConfiguration(String name, TestDatabaseAdapter dbAdapter, InheritanceType mappingStrategy,
+ boolean optimistic, boolean ejb3, boolean xml) {
+ this.name = name;
+ this.dbAdapter = dbAdapter;
+ this.mappingStrategy = mappingStrategy;
+ this.optimistic = optimistic;
+ this.ejb3 = ejb3;
+ this.xml = xml;
+ }
+
+ /** ToString for logging */
+ @Override
+ public String toString() {
+ StringBuffer s = new StringBuffer();
+ s.append("HibernateTestConfiguration(name=").append(getName()).append(", dbAdapter=").append(getDbAdapter())
+ .append(", ").append("mappingStrategy= ").append(getMappingStrategy().toString()).append(", ").append(
+ "optimistic= ").append(isOptimistic());
+ return s.toString();
+ }
+
+ /** Hashcode computed on the basis of the contents of the configuration */
+ @Override
+ public int hashCode() {
+ return getDbAdapter().hashCode() + getMappingStrategy().hashCode() + (isOptimistic() ? 1 : 0);
+ }
+
+ /** Equal configuration */
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof TestConfiguration) {
+ TestConfiguration otherCfg = (TestConfiguration) other;
+ return otherCfg.getDbAdapter() == getDbAdapter() && otherCfg.getMappingStrategy() == getMappingStrategy() &&
+ otherCfg.isOptimistic() == isOptimistic() && otherCfg.isEjb3() == isEjb3() &&
+ otherCfg.isXml() == isXml();
+ }
+ ;
+ return false;
+ }
+
+ /** The configuration name */
+ public String getName() {
+ return name;
+ }
+
+ /** Returns the test databaseadapter */
+ public TestDatabaseAdapter getDbAdapter() {
+ return dbAdapter;
+ }
+
+ /** Returns the current inheritance mapping */
+ public InheritanceType getMappingStrategy() {
+ return mappingStrategy;
+ }
+
+ /** Test optimistic locking */
+ public boolean isOptimistic() {
+ return optimistic;
+ }
+
+ /**
+ * @return the ejb3
+ */
+ public boolean isEjb3() {
+ return ejb3;
+ }
+
+ /**
+ * @return the xml
+ */
+ public boolean isXml() {
+ return xml;
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfigurations.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfigurations.java
new file mode 100755
index 000000000..7e994d75f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/TestConfigurations.java
@@ -0,0 +1,124 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * Davide Marchignoli
+ * </copyright>
+ *
+ * $Id: TestConfigurations.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.conf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
+import org.eclipse.emf.teneo.test.Utils;
+import org.eclipse.emf.teneo.test.stores.TestDBAdapters;
+import org.eclipse.emf.teneo.test.stores.TestDatabaseAdapter;
+
+/**
+ * Manages multiple configurations
+ *
+ * @author Davide Marchignoli
+ * @author Martin Taal
+ * @version $Revision: 1.5 $
+ */
+public class TestConfigurations {
+
+ /** Map with configs */
+ private Map cfgs = new LinkedHashMap();
+
+ /** The list of read database adapters */
+ private final TestDBAdapters dbAdapters;
+
+ /** Constructor */
+ public TestConfigurations(TestDBAdapters dbAdapters) {
+ this.dbAdapters = dbAdapters;
+ }
+
+ /**
+ * Add the given configuration.
+ *
+ * @throws NullPointerException
+ * if the argument is null
+ * @throws IllegalArgumentException
+ * if a configuration with the same name is already present
+ */
+ public void addConfiguration(TestConfiguration cfg) {
+ if (cfgs.containsKey(cfg.getName())) {
+ throw new IllegalArgumentException("Duplicate configuration " + cfg.getName());
+ }
+ cfgs.put(cfg.getName(), cfg);
+ }
+
+ /**
+ * Add the configurations defined in a set of properties
+ *
+ * @param props
+ */
+ public void addConfigurations(Properties props) {
+ Map hProps = Utils.hiearchizeProps(props);
+
+ for (Iterator pNames = hProps.keySet().iterator(); pNames.hasNext();) {
+ String cfgName = (String) pNames.next();
+ Properties cfgValues = (Properties) hProps.get(cfgName);
+
+ TestDatabaseAdapter dbAdapter = dbAdapters.get(((String) cfgValues.get("dbadapter")).trim());
+ InheritanceType mapStrategy = parseStrategy((String) cfgValues.get("mapstrategy"));
+ boolean optimistic = Boolean.valueOf((String) cfgValues.get("optimistic")).booleanValue();
+ boolean ejb3 =
+ cfgValues.get("ejb3") != null ? Boolean.valueOf((String) cfgValues.get("ejb3")).booleanValue()
+ : false;
+ boolean xml =
+ cfgValues.get("xml") != null ? Boolean.valueOf((String) cfgValues.get("xml")).booleanValue()
+ : false;
+ addConfiguration(new TestConfiguration(cfgName, dbAdapter, mapStrategy, optimistic, ejb3, xml));
+ }
+ }
+
+ /** Add configuration */
+ public void addConfigurations(InputStream propertiesStream) throws IOException {
+ Properties props = new Properties();
+ props.load(propertiesStream);
+ addConfigurations(props);
+ }
+
+ /** Determines the strategy */
+ private InheritanceType parseStrategy(String s) {
+ InheritanceType inheritanceType = InheritanceType.get(s);
+ if (inheritanceType == null) {
+ throw new IllegalArgumentException("Unknown mapping strategy " + s);
+ }
+ return inheritanceType;
+ }
+
+ /** Returns all configurations */
+ public Collection getConfigurations() {
+ return cfgs.values();
+ }
+
+ /** Returns the names of the configurations */
+ public Set getConfigurationNames() {
+ return cfgs.keySet();
+ }
+
+ /** Returns a specific configuration */
+ public TestConfiguration getConfiguration(String name) {
+ return (TestConfiguration) cfgs.get(name);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/Testbed.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/Testbed.java
new file mode 100755
index 000000000..dd445f688
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/conf/Testbed.java
@@ -0,0 +1,168 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * Davide Marchignoli
+ * </copyright>
+ *
+ * $Id: Testbed.java,v 1.9 2010/02/06 20:50:51 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.conf;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.teneo.samples.SamplesSource;
+import org.eclipse.emf.teneo.test.AbstractTest;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestDBAdapters;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * The test bed encapsulates the environment of a test action. It has 2 functions: 1) to encapsulate the possible
+ * configurations/dbadapters, and 2) to keep the current running configuration.
+ *
+ * @author Davide Marchignoli
+ * @author Martin Taal
+ * @version $Revision: 1.9 $
+ */
+public abstract class Testbed {
+ /** The logger */
+// private static Log log = LogFactory.getLog(Testbed.class);
+
+ /** The testbed instance */
+ private static Testbed testBed = null;
+
+ /** Return an instance of the testbed */
+ public static Testbed instance() {
+ return testBed;
+ }
+
+ /** Set the testbed */
+ public static void setTestBed(Testbed setTestBed) {
+ testBed = setTestBed;
+ }
+
+ /** Default naming of the current properties */
+ public static final String DBADAPTERS_PROP_RESOURCE = "/dbadapters.properties";
+
+ public static final String TEST_CFG_PROP_RESOURCE = "/test.properties";
+
+ /** loaded dbAdapters and test configs */
+ private TestDBAdapters dbAdapters;
+
+ /** The list of configs (different test settings) which will be run */
+ private TestConfigurations testConfigs;
+
+ /** current configuration */
+ private TestConfiguration currentCfg;
+
+ /**
+ * Constructor, the constructor assumes that the test and db properties are located in the same location as the
+ * non-abstract subclass
+ */
+ protected Testbed() {
+ dbAdapters = new TestDBAdapters();
+ try {
+ dbAdapters.addDBAdapters(this.getClass().getResourceAsStream(DBADAPTERS_PROP_RESOURCE));
+ testConfigs = new TestConfigurations(dbAdapters);
+ testConfigs.addConfigurations(getClass().getResourceAsStream(TEST_CFG_PROP_RESOURCE));
+ currentCfg = (TestConfiguration) testConfigs.getConfigurations().iterator().next();
+ } catch (IOException e) {
+ throw new StoreTestException("Unable to initialize TestSetting", e);
+ }
+ }
+
+ /**
+ * Constructor, the constructor assumes that the test and db properties are located in the same location as the
+ * non-abstract subclass
+ */
+ protected Testbed(String configPropertiesFile) {
+ dbAdapters = new TestDBAdapters();
+ try {
+ dbAdapters.addDBAdapters(this.getClass().getResourceAsStream(DBADAPTERS_PROP_RESOURCE));
+ testConfigs = new TestConfigurations(dbAdapters);
+ testConfigs.addConfigurations(getClass().getResourceAsStream(configPropertiesFile));
+ currentCfg = (TestConfiguration) testConfigs.getConfigurations().iterator().next();
+ } catch (IOException e) {
+ throw new StoreTestException("Unable to initialize TestSetting", e);
+ }
+ }
+
+ /**
+ * Request a store for the given configuration. No other store can be requested until this one is tear down.
+ */
+ public abstract TestStore createStore(AbstractTest testCase);
+
+ /** Returns the database name */
+ protected String getDbName(AbstractTest testCase, TestConfiguration cfg) {
+ // TODO maybe should shorten the name?
+ // first try in that direction, the testname is a classname
+ final String className = testCase.getName();
+ return className.substring(className.lastIndexOf('.') + 1) + "_" + cfg.getName();
+ }
+
+ /** Returns the sourcelocations for the given epackages */
+ protected String[] getSourceLocations(EPackage[] usedEPackages) throws FileNotFoundException {
+ String[] sourceLocations;
+ sourceLocations = new String[usedEPackages.length];
+ for (int i = 0; i < usedEPackages.length; i++)
+ sourceLocations[i] = SamplesSource.getSourceDirectory(usedEPackages[i]).getAbsolutePath();
+ return sourceLocations;
+ }
+
+ /** Collects source files from a certain sourcedirectory and further */
+ private void collectSourceFiles(ArrayList sourceFiles, File file) {
+ if (file.isDirectory()) {
+ collectSourceFiles(sourceFiles, file.listFiles());
+ }
+ if (file.getName().endsWith(".java")) {
+ sourceFiles.add(file.getAbsolutePath());
+ }
+ }
+
+ /** Collects source files from the given sourcedirectories and further */
+ private void collectSourceFiles(ArrayList sourceFiles, File[] dirs) {
+ for (int i = 0; i < dirs.length; i++)
+ collectSourceFiles(sourceFiles, dirs[i]);
+ }
+
+ /**
+ * Deletes the current binary files private void deleteFiles(File directory) { File[] files = directory.listFiles();
+ * for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteFiles(files[i]); } if
+ * (files[i].getName().endsWith(".class") || files[i].getName().endsWith(".jdo")) files[i].delete(); } }
+ */
+
+ /** Get the current configuration, for which the current test is run */
+ public TestConfiguration getActiveConfiguration() {
+ return currentCfg;
+ }
+
+ /** And set the current configuration */
+ public void setActiveConfiguration(TestConfiguration newConfiguration) {
+ if (!testConfigs.getConfigurations().contains(newConfiguration))
+ throw new IllegalArgumentException("Cannot to switch to not configuration " + newConfiguration);
+ this.currentCfg = newConfiguration;
+ }
+
+ /** Return the test configurations */
+ public TestConfigurations getConfigurations() {
+ return testConfigs;
+ }
+
+ /** Get the db Adapters */
+ public TestDBAdapters getDBAdapters() {
+ return dbAdapters;
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.java
new file mode 100755
index 000000000..cbb1911cb
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.java
@@ -0,0 +1,162 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal</copyright>
+ * $Id: AssociationOverrideAction.java,v 1.11 2010/02/06 18:25:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.Address;
+import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.AssociationoverrideFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.AssociationoverridePackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.Employee;
+import org.eclipse.emf.teneo.samples.emf.annotations.associationoverride.Student;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Simple test for AssociationOverride.
+ */
+public class AssociationOverrideAction extends AbstractTestAction {
+ private static final String EMPLOYEE_DEPARTMENT = "R&D";
+
+ private static final String EMPLOYEE_NAME = "Piet Pietersen";
+
+ private static final String EMPLOYEE_VERIFICATION_QUERY =
+ "SELECT COUNT(*) FROM EMPLOYEE A INNER JOIN ADDRESS B ON A.EMPLOYEE_ADDRESS_ID = B.MYID".toLowerCase();
+
+ private static final AssociationoverrideFactory FACTORY = AssociationoverrideFactory.eINSTANCE;
+
+ private static final Address DEFAULT_ADDRESS = FACTORY.createAddress();
+
+ private static final String STUDENT_FACULTY = "Biology";
+ private static final String STUDENT_NAME = "Jan Janssen";
+
+ private static final String STUDENT_VERIFICATION_QUERY =
+ "SELECT COUNT(*) FROM STUDENT A INNER JOIN ADDRESS B ON A.ADDRESS_ADDRESS_E_ID = B.MYID".toLowerCase();
+
+ static {
+ DEFAULT_ADDRESS.setStreet("Amsterdamseweg 123");
+ DEFAULT_ADDRESS.setPostalCode("1234 AZ");
+ }
+
+ public AssociationOverrideAction() {
+ super(AssociationoverridePackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ storeStudent(store);
+ storeEmployee(store);
+ testStudent(store);
+ testEmployee(store);
+ testTables(store);
+ }
+
+ private Address getAddress() {
+ final Address address = FACTORY.createAddress();
+ address.setStreet(DEFAULT_ADDRESS.getStreet());
+ address.setPostalCode(DEFAULT_ADDRESS.getPostalCode());
+ return address;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.put(PersistenceOptions.ID_COLUMN_NAME, "myid");
+ return props;
+ }
+
+ private void storeEmployee(TestStore store) {
+ store.beginTransaction();
+ final Employee employee = FACTORY.createEmployee();
+ employee.setName(EMPLOYEE_NAME);
+ employee.setDepartment(EMPLOYEE_DEPARTMENT);
+ employee.setAddress(getAddress());
+ store.store(employee);
+ store.commitTransaction();
+ }
+
+ private void storeStudent(TestStore store) {
+ store.beginTransaction();
+ final Student student = FACTORY.createStudent();
+ student.setName(STUDENT_NAME);
+ student.setAddress(getAddress());
+ student.setFaculty(STUDENT_FACULTY);
+ store.store(student);
+ store.commitTransaction();
+ }
+
+ private void testAddress(Address address) {
+ assertEquals(DEFAULT_ADDRESS.getStreet(), address.getStreet());
+ assertEquals(DEFAULT_ADDRESS.getPostalCode(), address.getPostalCode());
+ }
+
+ private void testEmployee(TestStore store) {
+ store.beginTransaction();
+ final List<?> results = store.query("select e from Employee e");
+ assertEquals(1, results.size());
+ final Employee employee = (Employee) results.get(0);
+ assertEquals(EMPLOYEE_NAME, employee.getName());
+ assertEquals(EMPLOYEE_DEPARTMENT, employee.getDepartment());
+ testAddress(employee.getAddress());
+ store.commitTransaction();
+ }
+
+ private void testStudent(TestStore store) {
+ store.beginTransaction();
+ final List<?> results = store.query("select s from Student s");
+ assertEquals(1, results.size());
+ final Student student = (Student) results.get(0);
+ assertEquals(STUDENT_NAME, student.getName());
+ assertEquals(STUDENT_FACULTY, student.getFaculty());
+ testAddress(student.getAddress());
+ store.commitTransaction();
+ }
+
+ private void testTables(TestStore store) {
+ final Connection conn = store.getConnection();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery(STUDENT_VERIFICATION_QUERY);
+ rs.next();
+ assertEquals(1, rs.getInt(1));
+ rs.close();
+ rs = stmt.executeQuery(EMPLOYEE_VERIFICATION_QUERY);
+ rs.next();
+ assertEquals(1, rs.getInt(1));
+ } catch (final SQLException e) {
+ assertTrue(e.getMessage(), false);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (final SQLException e) {
+ }
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ } catch (final SQLException e) {
+ }
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.persistence.xml
new file mode 100755
index 000000000..ffe805777
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AssociationOverrideAction.persistence.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/associationoverride">
+
+ <eclass name="Person">
+ <mapped-superclass />
+ <property name="id">
+ <id />
+ </property>
+ <property name="address">
+ <many-to-one />
+ </property>
+ </eclass>
+
+ <eclass name="Employee">
+ <association-override name="address">
+ <join-column name="employee_address_id"/>
+ </association-override>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AttributeOverridesAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AttributeOverridesAction.java
new file mode 100755
index 000000000..9526931db
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/AttributeOverridesAction.java
@@ -0,0 +1,60 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: AttributeOverridesAction.java,v 1.5 2008/05/27 07:42:12 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.AttributeoverridesFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.AttributeoverridesPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.City;
+import org.eclipse.emf.teneo.samples.emf.annotations.attributeoverrides.Person;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class AttributeOverridesAction extends AbstractTestAction {
+ /**
+ * Constructor
+ */
+ public AttributeOverridesAction() {
+ super(AttributeoverridesPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final AttributeoverridesFactory factory = AttributeoverridesFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final City bornIn = factory.createCity();
+ bornIn.setCountry("Singapore");
+ bornIn.setName("Singapore");
+ final City livesIn = factory.createCity();
+ livesIn.setCountry("Netherlands");
+ livesIn.setName("Doorn");
+ final Person person = factory.createPerson();
+ person.setName("Martin");
+ person.setBornIn(bornIn);
+ person.setLivesIn(livesIn);
+ store.store(person);
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BasicAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BasicAction.java
new file mode 100755
index 000000000..ed08c8a39
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BasicAction.java
@@ -0,0 +1,63 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: BasicAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $
+ */
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.basic.Basic;
+import org.eclipse.emf.teneo.samples.emf.annotations.basic.BasicFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.basic.BasicPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+ */
+public class BasicAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ * @param arg0
+ */
+ public BasicAction() {
+ super(BasicPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final BasicFactory factory = BasicFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+
+ final Basic basic = factory.createBasic();
+ // do not set optional as it is optional
+ // basic.setMyOptionalBasic("optional");
+ basic.setMyTransient("transient");
+ basic.setMyVersion(100);
+ store.store(basic);
+ store.commitTransaction();
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ final Basic basic = (Basic) store.getObject(Basic.class);
+ assertTrue("Transient field should not be set", basic.getMyTransient() == null);
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BookAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BookAction.java
new file mode 100755
index 000000000..61c0bddc2
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/BookAction.java
@@ -0,0 +1,136 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: BookAction.java,v 1.12 2008/05/27 07:42:12 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.column.Book;
+import org.eclipse.emf.teneo.samples.emf.annotations.column.ColumnFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.column.ColumnPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.12 $
+ */
+public class BookAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public BookAction() {
+ super(ColumnPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final BigDecimal testDbl = new BigDecimal("12456677.90123");
+ final ColumnFactory factory = ColumnFactory.eINSTANCE;
+ try {
+ store.beginTransaction();
+ final Book book = factory.createBook();
+ book.setAuthor("martin");
+ book.setTitle("012345678901234567890123456789");
+ book.setPages(1000);
+ book.setWeight(new BigDecimal("12456677.90123"));
+ store.store(book);
+ store.commitTransaction();
+ } catch (final Exception e) {
+ // in this case the constraint checking fails directly stop with this
+ return;
+ }
+
+ // check unique constraint on title column
+ {
+ try {
+ store.beginTransaction();
+ final Book book = factory.createBook();
+ book.setAuthor("martin");
+ book.setTitle("012345678901234567890123456789");
+ book.setPages(1000);
+ book.setWeight(new BigDecimal("12456677.90123"));
+ store.store(book);
+ store.commitTransaction();
+ fail("The unique constraint on title is violated");
+ } catch (final Exception e) {
+ // no fail, this good
+ store.rollbackTransaction();
+ }
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ final Book book = store.getObject(Book.class);
+ // hsqldb does not support column length, at least not in in-mem mode
+ if (!(store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter)) {
+ assertTrue("The length of the booktitle should not be more than 25: " + book.getTitle().length(), book
+ .getTitle().length() <= 25);
+ assertTrue("Only a precision of 5 is defined, so weight is not correctly stored as it has more digits",
+ Math.abs(testDbl.subtract(book.getWeight()).doubleValue()) > 1.0);
+ }
+ book.setWeight(new BigDecimal("25.5"));
+ store.store(book);
+ store.commitTransaction();
+ }
+
+ // check if the column names have landed
+ {
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ final ResultSet rs = stmt.executeQuery("SELECT * FROM mybooktable WHERE titel='' AND gewicht IS NULL");
+ assertTrue(rs != null); // dummy to get rid of warning
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ }
+ }
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ final Book book = store.getObject(Book.class);
+ assertTrue(255 == (int) (book.getWeight().doubleValue() * 10));
+ store.store(book);
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.java
new file mode 100755
index 000000000..5cb13975f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.java
@@ -0,0 +1,231 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: CascadeNotallAction.java,v 1.11 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.Book;
+import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.CascadenotallFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.CascadenotallPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.Library;
+import org.eclipse.emf.teneo.samples.emf.annotations.cascadenotall.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example without orphan delete or dependent element
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.11 $
+ */
+public class CascadeNotallAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public CascadeNotallAction() {
+ super(CascadenotallPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty("org.jpox.deletionPolicy", "JDO2");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final CascadenotallFactory factory = CascadenotallFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship of the Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(500);
+ book2.setTitle("The Hobbit");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ // sorry george making a mistake here, will correct this below
+ final Book book3 = factory.createBook();
+ book3.setAuthor(writer);
+ book3.setPages(500);
+ book3.setTitle("1984");
+ book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.setName("Science Fiction");
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getBooks().add(book3);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ res.save(null);
+ res.save(null);
+ res.unload();
+ }
+
+ // walk through the structure starting from the library
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+
+ final Library lib = (Library) res.getContents().get(0);
+
+ final Writer tolkien = lib.getWriters().get(0);
+
+ /*
+ * final Object[] obj = ((StoreResource)res).getCrossReferencers(tolkien); for (int
+ * i = 0; i < obj.length; i++) {
+ */
+
+ /*
+ * assertEquals(3, tolkien.getBooks().size());
+ *
+ * assertEquals(0 , tolkien.getName().compareTo("JRR Tolkien")); Book wBook =
+ * (Book)tolkien.getBooks().get(0); Book lBook = (Book)lib.getBooks().get(0);
+ * assertTrue("Book is contained in the library", wBook.eContainer() == lib);
+ * assertTrue("Book is contained in the library", lBook.eContainer() == lib);
+ *
+ * assertTrue(lBook.getAuthor() == tolkien);
+ * assertTrue(tolkien.getBooks().contains(lBook));
+ * assertTrue(tolkien.getBooks().contains(wBook)); // ordering is the same
+ * assertTrue(wBook.getTitle().compareTo(lBook.getTitle()) == 0);
+ * assertTrue(wBook.getPages() == lBook.getPages()); assertTrue(wBook.getCategory()
+ * instanceof BookCategory); assertTrue(wBook.getCategory() ==
+ * BookCategory.SCIENCE_FICTION_LITERAL);
+ */
+ // correct the mistake we made
+ final Book orwellsBook = tolkien.getBooks().get(2);
+ assertTrue(orwellsBook.getTitle().compareTo("1984") == 0);
+
+ // add orwell as a writer
+ final Writer george = factory.createWriter();
+ george.setName("George Orwell");
+ orwellsBook.setAuthor(george);
+
+ // and put george in our library
+ lib.getWriters().add(george);
+
+ assertEquals(2, tolkien.getBooks().size());
+
+ // and save it all
+ res.save(null);
+ res.save(null);
+
+ george.setName("G. Orwell"); // there was a bug in which this failed, reported by
+ // Georgi Manev
+ res.save(null);
+ res.save(null);
+ res.unload();
+ }
+
+ // TODO put in JPOX specific test code
+ // // now retrieve the writer using a simple query
+ // if (store instanceof JPOXTestStore)
+ // {
+ // store.beginTransaction();
+ // Writer george = (Writer)store.query("SELECT FROM " +
+ // JPOXHelper.INSTANCE.getInstanceClassName(Writer.class) +
+ // " WHERE name == \"G. Orwell\"", 1).get(0);
+ // assertTrue(george.getBooks().size() == 1);
+ // Book georgesBook = (Book)george.getBooks().get(0);
+ // assertTrue(georgesBook.getAuthor() == george);
+ // store.commitTransaction();
+ // }
+ } catch (final IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+
+ try {
+ final Resource res = store.getResource();
+ res.load(null);
+
+ final Library lib = (Library) res.getContents().get(0);
+
+ final Writer writer = lib.getWriters().get(0);
+
+ final Library newLib = factory.createLibrary();
+ newLib.setName("tstlib");
+ res.getContents().add(newLib);
+
+ // this save was required to get the entitymanager working
+ // because if not there then newLib would not have been saved and
+ // the persistent writer would through its econtainer relation point
+ // to a non-saved newLib resulting in transient errors.
+ res.save(null);
+ assertTrue(lib.getBooks().size() > 0); // force load of books to prevent dangling error
+ // in jpox
+ lib.getWriters().remove(writer);
+ newLib.getWriters().add(writer);
+ res.save(null);
+ res.unload();
+
+ } catch (final IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+
+ // and check if cascade delete works!
+
+ try {
+ final Resource res = store.getResource();
+ res.load(null);
+
+ final Library lib = (Library) res.getContents().get(0);
+
+ assertTrue(lib.getName() != null); // get rid of warning
+
+ // delete both libraries
+ res.getContents().remove(0);
+ res.getContents().remove(0);
+ res.save(null);
+ res.unload();
+ } catch (final IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+
+ store.beginTransaction();
+ store.checkNumber(Writer.class, 0);
+ store.checkNumber(Book.class, 0);
+ store.checkNumber(Library.class, 0);
+ store.commitTransaction();
+ }
+
+ protected boolean hibernateEnabled() {
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.persistence.xml
new file mode 100755
index 000000000..6f6d3153c
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CascadeNotallAction.persistence.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- Template for TestAction persistence mapping. -->
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/cascadenotall">
+
+ <eclass name="Writer">
+ <property name="books">
+ <one-to-many target-entity="Book" mapped-by="author">
+ <cascade>MERGE</cascade>
+ <cascade>PERSIST</cascade>
+ </one-to-many>
+ </property>
+ </eclass>
+
+ <eclass name="Library">
+ <property name="writers">
+ <one-to-many>
+ <cascade>MERGE</cascade>
+ <cascade>PERSIST</cascade>
+ <cascade>REFRESH</cascade>
+ <cascade>REMOVE</cascade>
+ </one-to-many>
+ </property>
+ <property name="books">
+ <one-to-many>
+ <cascade>MERGE</cascade>
+ <cascade>PERSIST</cascade>
+ <cascade>REFRESH</cascade>
+ <cascade>REMOVE</cascade>
+ </one-to-many>
+ </property>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CompositeIdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CompositeIdAction.java
new file mode 100755
index 000000000..cd2b8fdba
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/CompositeIdAction.java
@@ -0,0 +1,64 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * CompositeIdAction.java,v 1.2 2007/02/01 12:35:36 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.Child;
+import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.CompositeidFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.CompositeidPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.compositeid.Parent;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class CompositeIdAction extends AbstractTestAction {
+ /**
+ * Constructor
+ */
+ public CompositeIdAction() {
+ super(CompositeidPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final CompositeidFactory factory = CompositeidFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final Parent parent = factory.createParent();
+ parent.setFirstName("John");
+ parent.setLastName("Smith");
+ final Child child1 = factory.createChild();
+ child1.setFirstName("Johnny");
+ child1.setLastName("Smith");
+ parent.getChildren().add(child1);
+ final Child child2 = factory.createChild();
+ child2.setFirstName("Jane");
+ child2.setLastName("Smith");
+ parent.getChildren().add(child2);
+ store.store(parent.getChildren());
+ store.store(parent);
+ store.commitTransaction();
+ }
+
+ // read again
+ {
+ store.beginTransaction();
+ final Parent parent = (Parent) store.getObject(Parent.class);
+ assertEquals(2, parent.getChildren().size());
+ assertEquals("Johnny", parent.getChildren().get(0).getFirstName());
+ assertEquals("Jane", parent.getChildren().get(1).getFirstName());
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/DuplicatesAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/DuplicatesAction.java
new file mode 100755
index 000000000..2e82d6123
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/DuplicatesAction.java
@@ -0,0 +1,66 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * DuplicatesAction.java,v 1.3 2007/02/05 15:35:34 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.ChildItem;
+import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.DuplicatesFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.DuplicatesPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.duplicates.Item;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class DuplicatesAction extends AbstractTestAction {
+ /** No of childitems */
+ private static final int NO_CHILDS = 5;
+
+ /**
+ * Constructor
+ */
+ public DuplicatesAction() {
+ super(DuplicatesPackage.eINSTANCE);
+ }
+
+ /** Test */
+ @Override
+ public void doAction(TestStore store) {
+ final DuplicatesFactory factory = DuplicatesFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Item item = factory.createItem();
+ final ChildItem ci = factory.createChildItem();
+ ci.setName("mychild");
+ for (int i = 0; i < NO_CHILDS; i++) {
+ item.getChildItem().add(ci);
+ }
+
+ item.setName("myitem");
+ store.store(item);
+ store.commitTransaction();
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ final Item item = (Item) store.getObject(Item.class);
+ // assertEquals(NO_CHILDS, item.getChildItem().size());
+ for (int i = 0; i < item.getChildItem().size(); i++) {
+ assertTrue(item.getChildItem().get(i) == item.getChildItem().get(0));
+ }
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.java
new file mode 100755
index 000000000..cede45ad8
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.java
@@ -0,0 +1,136 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: EDataTypeAction.java,v 1.9 2008/07/13 13:13:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.edatatypeColumn.Book;
+import org.eclipse.emf.teneo.samples.emf.annotations.edatatypeColumn.EdatatypeColumnFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.edatatypeColumn.EdatatypeColumnPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.9 $
+ */
+public class EDataTypeAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public EDataTypeAction() {
+ super(EdatatypeColumnPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final BigDecimal testDbl = new BigDecimal("12456677.90123");
+ final EdatatypeColumnFactory factory = EdatatypeColumnFactory.eINSTANCE;
+ try {
+ store.beginTransaction();
+ final Book book = factory.createBook();
+ book.setAuthor("martin");
+ book.setTitle("012345678901234567890123456789");
+ book.setPages(1000);
+ book.setWeight(new BigDecimal("12456677.90123"));
+ store.store(book);
+ store.commitTransaction();
+ } catch (final Exception e) {
+ // in this case the constraint checking fails directly stop with this
+ return;
+ }
+
+ // check unique constraint on title column
+ {
+ try {
+ store.beginTransaction();
+ final Book book = factory.createBook();
+ book.setAuthor("martin");
+ book.setTitle("012345678901234567890123456789");
+ book.setPages(1000);
+ book.setWeight(new BigDecimal("12456677.90123"));
+ store.store(book);
+ store.commitTransaction();
+ fail("The unique constraint on title is violated");
+ } catch (final Exception e) {
+ // no fail, this good
+ store.rollbackTransaction();
+ }
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ final Book book = store.getObject(Book.class);
+ // hsqldb does not support column length, at least not in in-mem mode
+ if (!(store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter)) {
+ assertTrue("The length of the booktitle should not be more than 25: " + book.getTitle().length(), book
+ .getTitle().length() <= 25);
+ assertTrue("Only a precision of 5 is defined, so weight is not correctly stored as it has more digits",
+ Math.abs(testDbl.subtract(book.getWeight()).doubleValue()) > 1.0);
+ }
+ book.setWeight(new BigDecimal("25.5"));
+ store.store(book);
+ store.commitTransaction();
+ }
+
+ // check if the column names have landed
+ {
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ final ResultSet rs = stmt.executeQuery("SELECT * FROM mybooktable WHERE titel='' AND gewicht IS NULL");
+ assertTrue(rs != null); // dummy to get rid of warning
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ }
+ }
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ final Book book = store.getObject(Book.class);
+ assertTrue(255 == (int) (book.getWeight().doubleValue() * 10));
+ store.store(book);
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.persistence.xml
new file mode 100755
index 000000000..9f25cf029
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EDataTypeAction.persistence.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/edatatype_column">
+
+ <eclass name="Book">
+ <table name="mybooktable"/>
+ <property name="title">
+ <column name="titel" unique="true" length="25"/>
+ </property>
+ </eclass>
+
+ <edatatype name="TitleType">
+ <column name="mytitle" unique="false" length="50"/>
+ </edatatype>
+ <edatatype name="PagesType">
+ <column updatable="false" insertable="false"/>
+ </edatatype>
+ <edatatype name="WeightType">
+ <column name="gewicht" nullable="true" precision="5" scale="2"/>
+ </edatatype>
+
+ </epackage>
+</persistence-mapping>
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedAction.java
new file mode 100755
index 000000000..10d18e99d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedAction.java
@@ -0,0 +1,156 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: EmbeddedAction.java,v 1.8 2010/04/23 08:52:55 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.AOneToMany;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.AlsoEmbeddable;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.AnotherEmbeddable;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.Embeddable;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.EmbeddedFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.EmbeddedPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.Embedder;
+import org.eclipse.emf.teneo.samples.emf.annotations.embedded.NestedEmbeddable;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class EmbeddedAction extends AbstractTestAction {
+ /**
+ * Constructor
+ *
+ * @param arg0
+ */
+ public EmbeddedAction() {
+ super(EmbeddedPackage.eINSTANCE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.MAP_EMBEDDABLE_AS_EMBEDDED, "true");
+ return props;
+ }
+
+ /** Just create and store an embedded and see if it all worked without column name clashes */
+ @Override
+ public void doAction(TestStore store) {
+ final EmbeddedFactory factory = EmbeddedFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final Embedder embedder = factory.createEmbedder();
+ {
+ final Embeddable ea = factory.createEmbeddable();
+ ea.setMyInteger(1);
+ ea.setMyString("string");
+ embedder.setFirstEmbedded(ea);
+ }
+
+ {
+ final Embeddable ea = factory.createEmbeddable();
+ ea.setMyInteger(2);
+ ea.setMyString("string");
+ embedder.setSecondEmbedded(ea);
+ }
+
+ {
+ final Embeddable ea = factory.createEmbeddable();
+ ea.setMyInteger(3);
+ ea.setMyString("string");
+ embedder.setThirdEmbedded(ea);
+ }
+
+ {
+ final Embeddable ea = factory.createEmbeddable();
+ ea.setMyInteger(4);
+ ea.setMyString("string");
+ embedder.getFourthEmbedded().add(ea);
+
+ final Embeddable ea2 = factory.createEmbeddable();
+ ea2.setMyInteger(5);
+ ea2.setMyString("string5");
+ embedder.getFourthEmbedded().add(ea2);
+ }
+
+ {
+ final Embeddable ea = factory.createEmbeddable();
+ ea.setMyInteger(6);
+ ea.setMyString("fifthstring");
+ embedder.setFifthEmbedded(ea);
+ }
+
+ final AnotherEmbeddable anotherEmbeddable = factory.createAnotherEmbeddable();
+ anotherEmbeddable.setName("name");
+ anotherEmbeddable.setAnotherName("anotherName");
+
+ final AOneToMany aOneToMany1 = factory.createAOneToMany();
+ aOneToMany1.setName("1");
+ anotherEmbeddable.getAOneToMany().add(aOneToMany1);
+
+ final AOneToMany aOneToMany2 = factory.createAOneToMany();
+ aOneToMany2.setName("2");
+ anotherEmbeddable.getAOneToMany().add(aOneToMany2);
+
+ final NestedEmbeddable nestedEmbeddable = factory.createNestedEmbeddable();
+ nestedEmbeddable.setNestedName("nestName");
+ anotherEmbeddable.setNestedEmbedded(nestedEmbeddable);
+
+ embedder.setAnotherEmbedded(anotherEmbeddable);
+
+ final AlsoEmbeddable ae = factory.createAlsoEmbeddable();
+ ae.setName("me");
+ embedder.setAlsoEmbeddable(ae);
+
+ store.store(embedder);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ final Embedder embedder = store.getObject(Embedder.class);
+ assertEquals(1, embedder.getFirstEmbedded().getMyInteger());
+ assertEquals(2, embedder.getSecondEmbedded().getMyInteger());
+ assertEquals(3, embedder.getThirdEmbedded().getMyInteger());
+ assertEquals(4, (embedder.getFourthEmbedded().get(0)).getMyInteger());
+ assertEquals(5, (embedder.getFourthEmbedded().get(1)).getMyInteger());
+ assertEquals(6, embedder.getFifthEmbedded().getMyInteger());
+ assertEquals("me", embedder.getAlsoEmbeddable().getName());
+
+ final AnotherEmbeddable ae = embedder.getAnotherEmbedded();
+ assertEquals("anotherName", ae.getAnotherName());
+ assertEquals("name", ae.getName());
+ assertEquals(2, ae.getAOneToMany().size());
+ assertEquals("1", ae.getAOneToMany().get(0).getName());
+ assertEquals("2", ae.getAOneToMany().get(1).getName());
+ assertNotNull(ae.getNestedEmbedded());
+ assertEquals("nestName", ae.getNestedEmbedded().getNestedName());
+
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.java
new file mode 100755
index 000000000..650b9f614
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.java
@@ -0,0 +1,59 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * EmbeddedIdAction.java,v 1.3 2007/03/20 23:33:38 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.EmbeddedidFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.EmbeddedidPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.Name;
+import org.eclipse.emf.teneo.samples.emf.annotations.embeddedid.Person;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+public class EmbeddedIdAction extends AbstractTestAction {
+
+ private static final String ADDRESS = "Amsterdamseweg 123, 4567AZ Amsterdam";
+ private static final String FIRST_NAME = "Jan";
+ private static final String LAST_NAME = "Janssen";
+
+ public EmbeddedIdAction() {
+ super(EmbeddedidPackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ storePerson(store);
+ testPerson(store);
+ }
+
+ private void storePerson(TestStore store) {
+ final Person person = EmbeddedidFactory.eINSTANCE.createPerson();
+ final Name name = EmbeddedidFactory.eINSTANCE.createName();
+ name.setFirstName(FIRST_NAME);
+ name.setLastName(LAST_NAME);
+ person.setName(name);
+ person.setAddress(ADDRESS);
+ store.beginTransaction();
+ store.store(person);
+ store.commitTransaction();
+ }
+
+ private void testPerson(TestStore store) {
+ store.beginTransaction();
+ final List<?> persons = store.query("select p from Person p");
+ assertEquals(1, persons.size());
+ final Person person = (Person) persons.get(0);
+ assertEquals(FIRST_NAME, person.getName().getFirstName());
+ assertEquals(LAST_NAME, person.getName().getLastName());
+ assertEquals(ADDRESS, person.getAddress());
+ store.commitTransaction();
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.persistence.xml
new file mode 100755
index 000000000..c27dbc6dd
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EmbeddedIdAction.persistence.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/embeddedid">
+
+ <eclass name="Person">
+ <property name="name">
+ <embedded-id />
+ </property>
+ <property name="address">
+ <lob />
+ </property>
+ </eclass>
+
+ <eclass name="Name">
+ <embeddable />
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EntityAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EntityAction.java
new file mode 100755
index 000000000..53d3f724a
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/EntityAction.java
@@ -0,0 +1,112 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * LazyLibraryAction.java,v 1.9 2007/03/29 15:00:32 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.entity.Book;
+import org.eclipse.emf.teneo.samples.emf.annotations.entity.EntityFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.entity.EntityPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.entity.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests extra lazy fetch strategy.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class EntityAction extends AbstractTestAction {
+
+ private static final String CHECK_QUERY = "SELECT COUNT(*) FROM BOEK".toLowerCase();
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public EntityAction() {
+ super(EntityPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final EntityFactory factory = EntityFactory.eINSTANCE;
+ {
+ Book b1 = factory.createBook();
+ b1.setTitle("b1");
+ Book b2 = factory.createBook();
+ b2.setTitle("b2");
+ Writer w1 = factory.createWriter();
+ w1.setName("w1");
+ Writer w2 = factory.createWriter();
+ w2.setName("w2");
+ store.beginTransaction();
+ store.store(b1);
+ store.store(b2);
+ store.store(w1);
+ store.store(w2);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ List<?> l = store.query("select b from Boek as b order by b.title");
+ int i = 1;
+ for (Object o : l) {
+ Book b = (Book) o;
+ assertEquals(b.getTitle(), "b" + i++);
+ }
+
+ l = store.query("select w from Schrijver as w order by w.name");
+ i = 1;
+ for (Object o : l) {
+ Writer w = (Writer) o;
+ assertEquals(w.getName(), "w" + i++);
+ }
+ store.deleteObject(l.get(0));
+ store.commitTransaction();
+ }
+ testTable(store);
+ }
+
+ private void testTable(TestStore store) {
+ final Connection conn = store.getConnection();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery(CHECK_QUERY);
+ rs.next();
+ assertEquals(2, rs.getInt(1));
+ rs.close();
+ } catch (final SQLException e) {
+ assertTrue(e.getMessage(), false);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (final SQLException e) {
+ }
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ } catch (final SQLException e) {
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ExternalAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ExternalAction.java
new file mode 100755
index 000000000..a246f2f74
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ExternalAction.java
@@ -0,0 +1,137 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ExternalAction.java,v 1.2 2011/02/27 20:10:33 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.Collections;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.eclipse.emf.teneo.TeneoException;
+import org.eclipse.emf.teneo.samples.emf.annotations.external.ExternalFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.external.ExternalPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.external.ExternalTest;
+import org.eclipse.emf.teneo.samples.emf.sample.play.ActType;
+import org.eclipse.emf.teneo.samples.emf.sample.play.FmType;
+import org.eclipse.emf.teneo.samples.emf.sample.play.PersonaeType;
+import org.eclipse.emf.teneo.samples.emf.sample.play.PlayPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.play.PlayType;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class ExternalAction extends AbstractTestAction {
+ public ExternalAction() {
+ // touch the play package
+ super(ExternalPackage.eINSTANCE);
+ if (PlayPackage.eINSTANCE != null) {
+ // initialized
+ }
+
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ final ExternalFactory factory = ExternalFactory.eINSTANCE;
+
+ EObject o1;
+ EObject o2;
+ EObject o3;
+ try {
+ // a file handle to the current class
+ // the play.xml is in the model directory
+ final URI uri = URI.createURI(this.getClass()
+ .getResource("small_play.xml").toString());
+ final Resource resource = new XMLResourceImpl(uri);
+ resource.load(Collections.EMPTY_MAP);
+ PlayType play = (PlayType) resource.getContents().get(0);
+ o1 = play.getAct().get(0);
+ o2 = play.getPersonae();
+ o3 = play.getFm();
+
+ // resource.unload();
+ } catch (Exception e) {
+ throw new TeneoException(e.getMessage(), e);
+ }
+
+ {
+ store.beginTransaction();
+ final ExternalTest et1 = factory.createExternalTest();
+ et1.setName("et1");
+ et1.setEObject(o1);
+ et1.getEObjects().add(o3);
+ et1.getEObjects().add(o1);
+ et1.getEObjects().add(o2);
+ et1.setEClass(ExternalPackage.eINSTANCE.getExternalTest());
+ store.store(et1);
+ final ExternalTest et2 = factory.createExternalTest();
+ et2.setName("et2");
+ et2.setEObject(o2);
+ et2.setEClass(ExternalPackage.eINSTANCE.getExternalTest());
+ store.store(et2);
+ store.commitTransaction();
+
+ EcoreUtil.resolveAll(et2);
+ }
+
+ try {
+ final Resource res = store.getResource();
+ final ResourceSet rs = new ResourceSetImpl();
+ rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
+ .put("xml", new XMLResourceFactoryImpl());
+ rs.getResources().add(res);
+ res.load(Collections.EMPTY_MAP);
+
+ for (EObject eobj : res.getContents()) {
+ final ExternalTest et = (ExternalTest) eobj;
+ if (et.getName().equals("et1")) {
+ assertTrue(et.getEObject() instanceof ActType);
+ int cnt = 0;
+ assertEquals(3, et.getEObjects().size());
+ for (EObject eo : et.getEObjects()) {
+ if (cnt == 0) {
+ assertTrue(eo instanceof FmType);
+ }
+ if (cnt == 1) {
+ assertTrue(eo instanceof ActType);
+ }
+ if (cnt == 2) {
+ assertTrue(eo instanceof PersonaeType);
+ }
+ cnt++;
+ }
+ } else {
+ assertTrue(et.getEObject() instanceof PersonaeType);
+ }
+ assertEquals(et.getEClass(),
+ ExternalPackage.eINSTANCE.getExternalTest());
+ }
+ } catch (Exception e) {
+ throw new TeneoException(e.getMessage(), e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ForcedIdBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ForcedIdBagAction.java
new file mode 100755
index 000000000..c75e8201c
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ForcedIdBagAction.java
@@ -0,0 +1,114 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * ForcedIdBagAction.java,v 1.1 2007/03/21 15:45:24 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.ForcedidbagFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.ForcedidbagPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.Role;
+import org.eclipse.emf.teneo.samples.emf.annotations.forcedidbag.User;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+public class ForcedIdBagAction extends AbstractTestAction {
+
+ private static final String NAME = "Loeki";
+
+ private static final String ROLE1 = "admin";
+
+ private static final String ROLE2 = "developer";
+
+ public ForcedIdBagAction() {
+ super(ForcedidbagPackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ storeUser(store);
+ testUser(store);
+ testPrimaryKey(store);
+ }
+
+ /** Add an option to force to use an idbag */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.MAP_ALL_LISTS_AS_IDBAG, "true");
+ props.setProperty(PersistenceOptions.IDBAG_ID_COLUMN_NAME, "idbag_id");
+ props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true");
+ return props;
+ }
+
+ private void storeUser(TestStore store) {
+ store.beginTransaction();
+ final User user = ForcedidbagFactory.eINSTANCE.createUser();
+ user.setName(NAME);
+ final Role role1 = ForcedidbagFactory.eINSTANCE.createRole();
+ role1.setName(ROLE1);
+ final Role role2 = ForcedidbagFactory.eINSTANCE.createRole();
+ role2.setName(ROLE2);
+ user.getRoles().add(role1);
+ user.getRoles().add(role2);
+ store.store(user.getRoles());
+ store.store(user);
+ store.commitTransaction();
+ }
+
+ private void testPrimaryKey(TestStore store) {
+ // apparently not enough metadata can be read for hsqldb
+ if (store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter) {
+ return;
+ }
+
+ // Verify that we have a primary key "ID" in the "roles" table.
+ ResultSet resultSet = null;
+ ResultSet resultSet2 = null;
+ try {
+ final DatabaseMetaData metaData = store.getConnection().getMetaData();
+
+ // apparently hibernate core creates different tables than running with
+ // hibernate entitymanager, need to check!
+ resultSet = metaData.getPrimaryKeys(null, null, "myjoin");
+ resultSet.next();
+ assertTrue("Primary key column should be named \"idbag_id\"", "idbag_id".equalsIgnoreCase(resultSet
+ .getString("COLUMN_NAME")));
+ assertFalse("Found more than one primary key.", resultSet.next());
+ } catch (final SQLException e) {
+ assertFalse(e.getMessage(), true);
+ } finally {
+ try {
+ if (resultSet != null) {
+ resultSet.close();
+ if (resultSet2 != null) {
+ resultSet2.close();
+ }
+ }
+ } catch (final SQLException e) {
+ }
+ }
+ }
+
+ private void testUser(TestStore store) {
+ final List<?> results = store.query("select u from User u");
+ assertEquals(1, results.size());
+ final User user = (User) results.get(0);
+ assertEquals(NAME, user.getName());
+ assertEquals(2, user.getRoles().size());
+ assertTrue(user.getRoles().get(0).getName().equals(ROLE1));
+ assertTrue(user.getRoles().get(1).getName().equals(ROLE2));
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/HbMapKeysAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/HbMapKeysAction.java
new file mode 100755
index 000000000..fb760de62
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/HbMapKeysAction.java
@@ -0,0 +1,110 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: HbMapKeysAction.java,v 1.2 2010/04/03 12:55:13 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.Book;
+import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.City;
+import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.HbmapkeysFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.HbmapkeysPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.hbmapkeys.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests HbMapKey and MapKeyManyToMany annotations
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class HbMapKeysAction extends AbstractTestAction {
+ public HbMapKeysAction() {
+ super(HbmapkeysPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+// props.put(PersistenceOptions.EMAP_AS_TRUE_MAP, "true");
+ return props;
+ }
+
+ /**
+ * Check test set, note a where clause has been set on the relation Only writers with name
+ * martin are returned
+ */
+ private void checkTestSet(Book bk) {
+ // final String prefix = bk.getTitle();
+ for (final Object element : bk.getWritersByName().keySet()) {
+ final String key = (String) element;
+ final Writer w = bk.getWritersByName().get(key);
+ assertEquals(key, w.getName());
+ assertTrue(key.startsWith(bk.getTitle()));
+ }
+ for (final Object element : bk.getCityByWriter().keySet()) {
+ final Writer key = (Writer) element;
+ final City c = bk.getCityByWriter().get(key);
+ assertEquals(key, c.getCityWriter());
+ }
+ }
+
+ /** Create test set */
+ private Book createTestSet(String prefix) {
+ final HbmapkeysFactory factory = HbmapkeysFactory.eINSTANCE;
+ final Writer w1 = factory.createWriter();
+ w1.setName(prefix + "martin");
+ final Writer w2 = factory.createWriter();
+ w2.setName(prefix + "martin2");
+ final Book bk = factory.createBook();
+ bk.setTitle(prefix);
+ bk.getWritersByName().put(w1.getName(), w1);
+ bk.getWritersByName().put(w2.getName(), w2);
+ final City ct1 = factory.createCity();
+ ct1.setName(prefix + "CityOne");
+ ct1.setCityWriter(w1);
+ bk.getCityByWriter().put(w1, ct1);
+ final City ct2 = factory.createCity();
+ ct2.setName(prefix + "CityTwo");
+ ct2.setCityWriter(w2);
+ bk.getCityByWriter().put(w2, ct2);
+ return bk;
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ {
+ store.beginTransaction();
+ store.store(createTestSet(""));
+ store.store(createTestSet("prefix2"));
+ store.commitTransaction();
+ }
+
+ try {
+ store.beginTransaction();
+ final List<?> lst = store.getObjects(Book.class);
+ for (Object name : lst) {
+ checkTestSet((Book) name);
+ }
+ store.commitTransaction();
+ } catch (final Exception e) {
+ throw new StoreTestException("Exception when testing with resource", e);
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdAction.java
new file mode 100755
index 000000000..3b1ff14a5
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdAction.java
@@ -0,0 +1,111 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * IdAction.java,v 1.4 2007/03/20 23:33:38 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.id.AutoID;
+import org.eclipse.emf.teneo.samples.emf.annotations.id.IdFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.id.IdPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.id.IdentityID;
+import org.eclipse.emf.teneo.samples.emf.annotations.id.SimpleID;
+import org.eclipse.emf.teneo.samples.emf.annotations.id.TableGeneratorID;
+import org.eclipse.emf.teneo.samples.emf.annotations.id.TableID;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class IdAction extends AbstractTestAction {
+ /** How many test objects are created */
+ private static final int NO_TEST_OBJECTS = 10;
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public IdAction() {
+ super(IdPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final IdFactory factory = IdFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ for (int i = 0; i < NO_TEST_OBJECTS; i++) {
+ store.store(factory.createIdentityID());
+ store.store(factory.createTableID());
+ store.store(factory.createSimpleID());
+ store.store(factory.createTableGeneratorID());
+
+ final AutoID aid = factory.createAutoID();
+ aid.setName("autoid" + i);
+ store.store(aid);
+
+ }
+ store.commitTransaction();
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ // test if we saved them all
+ List<?> list = store.getObjects(IdentityID.class);
+ HashMap<Long, Object> testMap = new HashMap<Long, Object>();
+ for (final Object element : list) {
+ final IdentityID iid = (IdentityID) element;
+ testMap.put(new Long(iid.getMyid()), iid);
+ }
+ assertEquals(NO_TEST_OBJECTS, testMap.size());
+
+ list = store.getObjects(TableID.class);
+ testMap = new HashMap<Long, Object>();
+ for (final Object element : list) {
+ final TableID sid = (TableID) element;
+ testMap.put(new Long(sid.getMyid()), sid);
+ }
+ assertEquals(NO_TEST_OBJECTS, testMap.size());
+
+ list = store.getObjects(SimpleID.class);
+ testMap = new HashMap<Long, Object>();
+ for (final Object element : list) {
+ final SimpleID sid = (SimpleID) element;
+ testMap.put(new Long(sid.getAutoID()), sid);
+ }
+ assertEquals(NO_TEST_OBJECTS, testMap.size());
+
+ list = store.getObjects(TableGeneratorID.class);
+ testMap = new HashMap<Long, Object>();
+ for (final Object element : list) {
+ final TableGeneratorID sid = (TableGeneratorID) element;
+ testMap.put(new Long(sid.getMyid()), sid);
+ }
+ assertEquals(NO_TEST_OBJECTS, testMap.size());
+
+ list = store.getObjects(AutoID.class);
+ testMap = new HashMap<Long, Object>();
+ int i = 0;
+ for (final Object element : list) {
+ final AutoID aid = (AutoID) element;
+ assertEquals("autoid" + (i++), aid.getName());
+ testMap.put(new Long(aid.getAutoID()), aid);
+ }
+ assertEquals(NO_TEST_OBJECTS, testMap.size());
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.java
new file mode 100755
index 000000000..a4ed93b8c
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.java
@@ -0,0 +1,116 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * IdBagAction.java,v 1.5 2007/03/20 23:33:38 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.idbag.IdbagFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.idbag.IdbagPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.idbag.User;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+public class IdBagAction extends AbstractTestAction {
+
+ private static final String NAME = "Loeki";
+
+ private static final String ROLE1 = "admin";
+
+ private static final String ROLE2 = "developer";
+
+ public IdBagAction() {
+ super(IdbagPackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ storeUser(store);
+ testUser(store);
+ testPrimaryKey(store);
+ }
+
+ private void storeUser(TestStore store) {
+ store.beginTransaction();
+ final User user = IdbagFactory.eINSTANCE.createUser();
+ user.setName(NAME);
+ user.getRoles().add(ROLE1);
+ user.getRoles().add(ROLE2);
+ store.store(user);
+ store.commitTransaction();
+ }
+
+ private void testPrimaryKey(TestStore store) {
+ // apparently not enough metadata can be read for hsqldb
+ if (store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter) {
+ return;
+ }
+
+ // Verify that we have a primary key "ID" in the "roles" table.
+ ResultSet resultSet = null;
+ ResultSet resultSet2 = null;
+ try {
+ final DatabaseMetaData metaData = store.getConnection().getMetaData();
+
+ // apparently hibernate core creates different tables than running with
+ // hibernate entitymanager, need to check!
+ boolean rsTrue = false;
+ try {
+ resultSet = metaData.getPrimaryKeys(null, null, "user_roles");
+ rsTrue = resultSet.next();
+ } catch (final SQLException e) {
+ // ignore, hope for the next one
+ }
+ boolean rs2True = false;
+ try {
+ resultSet2 = metaData.getPrimaryKeys(null, null, "roles");
+ rs2True = resultSet2.next();
+ } catch (final SQLException e) {
+ assertTrue(rsTrue);
+ // ignore hope for the first one
+ }
+ assertTrue("No primary key found for \"roles\" table.", rsTrue || rs2True);
+ if (rsTrue) {
+ assertTrue("Primary key column should be named \"ID\"", "ID".equalsIgnoreCase(resultSet
+ .getString("COLUMN_NAME")));
+ assertFalse("Found more than one primary key.", resultSet.next());
+ } else {
+ assertTrue("Primary key column should be named \"ID\"", "ID".equalsIgnoreCase(resultSet2
+ .getString("COLUMN_NAME")));
+ assertFalse("Found more than one primary key.", resultSet2.next());
+ }
+ } catch (final SQLException e) {
+ assertFalse(e.getMessage(), true);
+ } finally {
+ try {
+ if (resultSet != null) {
+ resultSet.close();
+ if (resultSet2 != null) {
+ resultSet2.close();
+ }
+ }
+ } catch (final SQLException e) {
+ }
+ }
+ }
+
+ private void testUser(TestStore store) {
+ final List<?> results = store.query("select u from User u");
+ assertEquals(1, results.size());
+ final User user = (User) results.get(0);
+ assertEquals(NAME, user.getName());
+ assertEquals(2, user.getRoles().size());
+ assertTrue(user.getRoles().contains(ROLE1));
+ assertTrue(user.getRoles().contains(ROLE2));
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.persistence.xml
new file mode 100755
index 000000000..d8abe2794
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IdBagAction.persistence.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- Template for TestAction persistence mapping. -->
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/idbag">
+
+ <eclass name="User">
+ <property name="roles">
+ <!-- IdBag not yet supported. -->
+ <id-bag />
+ </property>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.java
new file mode 100755
index 000000000..ca2977364
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.java
@@ -0,0 +1,207 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * InheritanceAnnotationAction.java,v 1.6 2007/03/20 23:33:38 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+
+import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Address;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.ContentList;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.DistrictUKAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InternationalPrice;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Price;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.UKAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USState;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.DistrictUKAddressImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.InternationalPriceImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.UKAddressImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.USAddressImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests annotations to direct the inheritance mapping.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.14 $
+ */
+public class InheritanceAnnotationAction extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public InheritanceAnnotationAction() {
+ super(InheritancemappingPackage.eINSTANCE);
+ }
+
+ /** Checks that the address types occur in the passed list */
+ private void checkAddressList(Iterator<?> it) {
+ int cntus = 0;
+ int cntuk = 0;
+ int cntdistrict = 0;
+ while (it.hasNext()) {
+ final Address address = (Address) it.next();
+ if (address instanceof DistrictUKAddress) {
+ cntdistrict++;
+ } else if (address instanceof UKAddress) {
+ cntuk++;
+ if (address.getName().compareTo("Primeminister") == 0) {
+ assertTrue(address instanceof UKAddress);
+ }
+ } else if (address instanceof USAddress) {
+ cntus++;
+
+ if (address.getName().compareTo("empty") == 0) {
+ // assertFalse(((USAddress) address).isSetState());
+ } else {
+ assertTrue(((USAddress) address).isSetState());
+ }
+ }
+ }
+ assertTrue(cntus == 2);
+ assertTrue(cntuk == 1);
+ assertTrue(cntdistrict == 1);
+ }
+
+ /** Creates simple types and tests against */
+ @Override
+ public void doAction(TestStore store) {
+ // test a simple type
+ final InheritancemappingFactory factory = InheritancemappingFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+
+ final USAddress usaddress = factory.createUSAddress();
+ usaddress.setName("Montgomery");
+ usaddress.setCity("Montgomery");
+ usaddress.setState(USState.AL_LITERAL);
+ usaddress.setZip(new BigInteger("36101"));
+ usaddress.setStreet("Montgomery street");
+ store.store(usaddress);
+
+ // test nullable fields
+ final USAddress emptyaddress = factory.createUSAddress();
+ emptyaddress.setName("empty");
+ emptyaddress.setCity("empty");
+ emptyaddress.setStreet("empty");
+ emptyaddress.setState(USState.AK_LITERAL);
+ emptyaddress.setZip(new BigInteger("1231"));
+
+ store.store(usaddress);
+ store.store(emptyaddress);
+
+ // create a uk address and a uk district address
+ final UKAddress ukaddress = factory.createUKAddress();
+ ukaddress.setCity("London");
+ ukaddress.setStreet("Downingstreet 10");
+ ukaddress.setName("Primeminister");
+ ukaddress.setPostcode("0000");
+ store.store(ukaddress);
+
+ final DistrictUKAddress districtaddress = factory.createDistrictUKAddress();
+ districtaddress.setCity("district");
+ districtaddress.setDistrict("district1");
+ districtaddress.setName("My districtaddress");
+ districtaddress.setPostcode("postcode1");
+ districtaddress.setStreet("street1");
+ store.store(districtaddress);
+
+ final ContentList contentlist = factory.createContentList();
+ contentlist.setName("testme");
+ contentlist.getAddress().add(usaddress);
+ contentlist.getAddress().add(emptyaddress);
+ contentlist.getAddress().add(ukaddress);
+ contentlist.getAddress().add(districtaddress);
+ store.store(contentlist);
+
+ final InternationalPrice intprice = factory.createInternationalPrice();
+ intprice.setName("euro");
+ intprice.setCurrency("EUR");
+ intprice.setValue(new BigDecimal("100.50"));
+ contentlist.getPrice().add(intprice);
+
+ final Price price = factory.createPrice();
+ price.setName("mycurrency");
+ price.setValue(new BigDecimal("99.30"));
+ contentlist.getPrice().add(price);
+
+ contentlist.getPrice().add(intprice);
+
+ store.store(contentlist.getAddress());
+ store.store(contentlist.getPrice());
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final ContentList contentList = store.getObject(ContentList.class);
+ checkAddressList(contentList.getAddress().iterator());
+
+ assertTrue(contentList.getPrice().get(0) instanceof InternationalPrice);
+ assertTrue(((InternationalPrice) contentList.getPrice().get(0)).getName().compareTo("euro") == 0);
+ assertTrue(contentList.getPrice().get(1) instanceof Price);
+ assertTrue(contentList.getPrice().get(1).getName().compareTo("mycurrency") == 0);
+
+ store.commitTransaction();
+ }
+
+ // eventhough at global level one inheritance strategy is used this should differ for
+ // individual
+ // class hierarchies as enforced by the annotations
+ assertTrue(store.isInheritanceStrategy(InternationalPriceImpl.class, InheritanceType.SINGLE_TABLE));
+ assertTrue(store.isInheritanceStrategy(UKAddressImpl.class, InheritanceType.JOINED));
+ assertTrue(store.isInheritanceStrategy(USAddressImpl.class, InheritanceType.JOINED));
+ assertTrue(store.isInheritanceStrategy(DistrictUKAddressImpl.class, InheritanceType.JOINED));
+
+ // do some sql queries to check if the discriminator has landed
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("select * from myprice where discriminator='myPrice'");
+ int cnt = 0;
+ while (rs.next()) {
+ cnt++;
+ }
+ rs.close();
+ assertEquals(1, cnt);
+
+ rs = stmt.executeQuery("select * from myprice where discriminator='myInternationalPrice'");
+ cnt = 0;
+ while (rs.next()) {
+ cnt++;
+ }
+ assertEquals(1, cnt);
+ } finally {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ } catch (final SQLException e) {
+ throw new StoreTestException("Sql exception when retrieving objects based on discriminator values", e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.persistence.xml
new file mode 100755
index 000000000..bf95c48c7
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationAction.persistence.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- Template for TestAction persistence mapping. -->
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/inheritancemapping">
+
+ <eclass name="ContentList">
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ <eclass name="ChildOne">
+ <entity extends="ParentTwo"/>
+ </eclass>
+
+ <eclass name="Price">
+ <table name="myprice" />
+ <inheritance>SINGLE_TABLE</inheritance>
+ <discriminator-column name="DISCRIMINATOR" discriminator-type="STRING" />
+ <discriminator-value>myPrice</discriminator-value>
+ </eclass>
+
+ <eclass name="InternationalPrice">
+ <discriminator-value>myInternationalPrice</discriminator-value>
+ </eclass>
+
+ <eclass name="Address">
+ <inheritance>JOINED</inheritance>
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ <eclass name="USAddress">
+ <table name="UNITEDSTATESADDRESS"/>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java
new file mode 100755
index 000000000..4115068ef
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.java
@@ -0,0 +1,224 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * InheritanceAnnotationTablePerClassAction.java,v 1.3 2007/03/20 23:33:38 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Address;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.ContentList;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.DistrictUKAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InheritancemappingPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.InternationalPrice;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.Price;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.UKAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USAddress;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.USState;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.DistrictUKAddressImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.InternationalPriceImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.UKAddressImpl;
+import org.eclipse.emf.teneo.samples.emf.annotations.inheritancemapping.impl.USAddressImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests annotations to direct the inheritance mapping.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.9 $
+ */
+public class InheritanceAnnotationTablePerClassAction extends AbstractTestAction {
+
+ /** UGLY, at least ensure that at least one of the three tests is run */
+ private static int ignored_tests = 0;
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public InheritanceAnnotationTablePerClassAction() {
+ super(InheritancemappingPackage.eINSTANCE);
+ }
+
+ /** Checks that the address types occur in the passed list */
+ private void checkAddressList(Iterator<?> it) {
+ int cntus = 0;
+ int cntuk = 0;
+ int cntdistrict = 0;
+ while (it.hasNext()) {
+ final Address address = (Address) it.next();
+ if (address instanceof DistrictUKAddress) {
+ cntdistrict++;
+ } else if (address instanceof UKAddress) {
+ cntuk++;
+ if (address.getName().compareTo("Primeminister") == 0) {
+ assertTrue(address instanceof UKAddress);
+ }
+ } else if (address instanceof USAddress) {
+ cntus++;
+
+ if (address.getName().compareTo("empty") == 0) {
+ assertFalse(((USAddress) address).isSetState());
+ } else {
+ assertTrue(((USAddress) address).isSetState());
+ assertTrue(((USAddress) address).isSetZip());
+ }
+ }
+ }
+ assertTrue(cntus == 2);
+ assertTrue(cntuk == 1);
+ assertTrue(cntdistrict == 1);
+ }
+
+ /** Creates simple types and tests against */
+ @Override
+ public void doAction(TestStore store) {
+ if (store.isInheritanceStrategy(InternationalPriceImpl.class, InheritanceType.SINGLE_TABLE)) {
+ ignored_tests++;
+ assertTrue(ignored_tests < 5);
+ return; // not the correct test, should only run xml tests, need to change the whole
+ // test framework to do this
+ }
+
+ // test a simple type
+ final InheritancemappingFactory factory = InheritancemappingFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final USAddress usaddress = factory.createUSAddress();
+ usaddress.setName("Montgomery");
+ usaddress.setCity("Montgomery");
+ usaddress.setState(USState.AL_LITERAL);
+ usaddress.setZip(new BigInteger("36101"));
+ usaddress.setStreet("Montgomery street");
+ store.store(usaddress);
+
+ // test nullable fields
+ final USAddress emptyaddress = factory.createUSAddress();
+ emptyaddress.setName("empty");
+ emptyaddress.setCity("empty");
+ emptyaddress.setStreet("empty");
+ emptyaddress.setZip(new BigInteger("123"));
+ emptyaddress.setState(USState.AK_LITERAL);
+
+ store.store(usaddress);
+ store.store(emptyaddress);
+
+ // create a uk address and a uk district address
+ final UKAddress ukaddress = factory.createUKAddress();
+ ukaddress.setCity("London");
+ ukaddress.setStreet("Downingstreet 10");
+ ukaddress.setName("Primeminister");
+ ukaddress.setPostcode("0000");
+ store.store(ukaddress);
+
+ final DistrictUKAddress districtaddress = factory.createDistrictUKAddress();
+ districtaddress.setCity("district");
+ districtaddress.setDistrict("district1");
+ districtaddress.setName("My districtaddress");
+ districtaddress.setPostcode("postcode1");
+ districtaddress.setStreet("street1");
+ store.store(districtaddress);
+ final ContentList contentlist = factory.createContentList();
+ contentlist.setName("testme");
+ contentlist.getAddress().add(usaddress);
+ contentlist.getAddress().add(emptyaddress);
+ contentlist.getAddress().add(ukaddress);
+ contentlist.getAddress().add(districtaddress);
+ store.store(contentlist);
+
+ final InternationalPrice intprice = factory.createInternationalPrice();
+ intprice.setName("euro");
+ intprice.setCurrency("EUR");
+ intprice.setValue(new BigDecimal("100.50"));
+
+ final Price price = factory.createPrice();
+ price.setName("mycurrency");
+ price.setValue(new BigDecimal("99.30"));
+ store.store(price);
+ store.store(intprice);
+
+ store.store(contentlist);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final ContentList contentList = store.getObject(ContentList.class);
+ checkAddressList(contentList.getAddress().iterator());
+
+ final List<?> prices = store.getObjects(Price.class);
+ assertEquals(2, prices.size());
+ InternationalPrice ip;
+ Price p;
+ if (prices.get(0) instanceof InternationalPrice) {
+ ip = (InternationalPrice) prices.get(0);
+ p = (Price) prices.get(1);
+ } else {
+ ip = (InternationalPrice) prices.get(1);
+ p = (Price) prices.get(0);
+ }
+ assertTrue(ip.getName().compareTo("euro") == 0);
+ assertTrue(p.getName().compareTo("mycurrency") == 0);
+
+ store.commitTransaction();
+ }
+
+ // eventhough at global level one inheritance strategy is used this should differ for
+ // individual
+ // class hierarchies as enforced by the annotations
+ assertTrue(store.isInheritanceStrategy(InternationalPriceImpl.class, InheritanceType.TABLE_PER_CLASS));
+ assertTrue(store.isInheritanceStrategy(UKAddressImpl.class, InheritanceType.JOINED));
+ assertTrue(store.isInheritanceStrategy(USAddressImpl.class, InheritanceType.JOINED));
+ assertTrue(store.isInheritanceStrategy(DistrictUKAddressImpl.class, InheritanceType.JOINED));
+
+ // do some sql queries to check if the name column is present in the subclass
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("select * from internationalprice where name='euro'");
+ int cnt = 0;
+ while (rs.next()) {
+ cnt++;
+ }
+ rs.close();
+
+ assertEquals(1, cnt);
+ rs = stmt.executeQuery("select * from myprice where name='mycurrency'");
+ cnt = 0;
+ while (rs.next()) {
+ cnt++;
+ }
+ rs.close();
+ assertEquals(1, cnt);
+ } finally {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ } catch (final SQLException e) {
+ throw new StoreTestException("Sql exception when retrieving objects based on discriminator values", e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml
new file mode 100755
index 000000000..01451cbe4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/InheritanceAnnotationTablePerClassAction.persistence.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- Template for TestAction persistence mapping. -->
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/inheritancemapping">
+
+ <eclass name="ContentList">
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ <eclass name="Price">
+ <table name="myprice" />
+ <inheritance>TABLE_PER_CLASS</inheritance>
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ <eclass name="Address">
+ <inheritance>JOINED</inheritance>
+ <property name="name">
+ <id />
+ </property>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IntegerDiscriminatorAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IntegerDiscriminatorAction.java
new file mode 100755
index 000000000..67472eab9
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/IntegerDiscriminatorAction.java
@@ -0,0 +1,100 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: IntegerDiscriminatorAction.java,v 1.3 2008/06/10 09:41:19 mtaal Exp $
+ */
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.IntegerdiscriminatorFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.IntegerdiscriminatorPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.OtherSub;
+import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.Sub;
+import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.SubFormula;
+import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.Super;
+import org.eclipse.emf.teneo.samples.emf.annotations.integerdiscriminator.SuperFormula;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase for integer discriminator, see bugzilla:
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=235945
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class IntegerDiscriminatorAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public IntegerDiscriminatorAction() {
+ super(IntegerdiscriminatorPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final IntegerdiscriminatorFactory factory = IntegerdiscriminatorFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+
+ final Super sup1 = factory.createSuper();
+ sup1.setName("test1");
+ final Super sup2 = factory.createSuper();
+ sup2.setName("test2");
+ final Sub sub = factory.createSub();
+ sub.setName("sub");
+ final OtherSub oSub = factory.createOtherSub();
+ oSub.setName("osub");
+ store.store(sup1);
+ store.store(sup2);
+ store.store(sub);
+ store.store(oSub);
+
+ final SuperFormula superFormula = factory.createSuperFormula();
+ superFormula.setName("GTEST");
+ store.store(superFormula);
+
+ final SubFormula subFormula = factory.createSubFormula();
+ subFormula.setName("RTEST");
+ store.store(subFormula);
+
+ store.commitTransaction();
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ // note 4 because polymorphic so the Sub and OtherSub count as a Sup
+ store.checkNumber(Super.class, 4);
+ store.checkNumber(Sub.class, 1);
+ store.checkNumber(OtherSub.class, 1);
+
+ final List<?> l = store.getObjects(SuperFormula.class);
+ assertEquals(2, l.size());
+ for (Object o : l) {
+ if (o instanceof SubFormula) {
+ assertEquals("RTEST", ((SuperFormula) o).getName());
+ } else if (o instanceof SuperFormula) {
+ assertEquals("GTEST", ((SuperFormula) o).getName());
+ } else {
+ fail("Unknown class " + o.getClass().getName());
+ }
+ }
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/JoinColumnsAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/JoinColumnsAction.java
new file mode 100755
index 000000000..264e428ae
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/JoinColumnsAction.java
@@ -0,0 +1,163 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * JoinColumnsAction.java,v 1.4 2007/02/01 12:35:36 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
+import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.Child;
+import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.House;
+import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.JoincolumnsFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.JoincolumnsPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.Parent;
+import org.eclipse.emf.teneo.samples.emf.annotations.joincolumns.Person;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.11 $
+ */
+public class JoinColumnsAction extends AbstractTestAction {
+ /**
+ * Constructor
+ */
+ public JoinColumnsAction() {
+ super(JoincolumnsPackage.eINSTANCE);
+ }
+
+ /** Checks the version column */
+ protected void checkVersion(TestStore store) {
+ }
+
+ /**
+ * Can be overridden by subclass returns properties which control the or layer. Such as setting
+ * of eager loading.
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.VERSION_COLUMN_NAME, "myversion");
+ props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final JoincolumnsFactory factory = JoincolumnsFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final Parent parent = factory.createParent();
+ parent.setFirstName("John");
+ parent.setLastName("Smith");
+ final Child child1 = factory.createChild();
+ child1.setFirstName("Johnny");
+ child1.setLastName("Smith");
+ parent.getChildren().add(child1);
+ final Child child2 = factory.createChild();
+ child2.setFirstName("Jane");
+ child2.setLastName("Smith");
+ parent.getChildren().add(child2);
+ store.store(parent.getChildren());
+ store.store(parent);
+
+ House h = factory.createHouse();
+ h.setOwner(parent);
+ h.getVisitors().add(parent);
+ h.getVisitors().add(child2);
+ store.store(h);
+
+ // now create some friends
+ Person f1 = factory.createPerson();
+ f1.setFirstName("friend");
+ f1.setLastName("one");
+ Person f2 = factory.createPerson();
+ f2.setFirstName("friend");
+ f2.setLastName("two");
+ Person f3 = factory.createPerson();
+ f3.setFirstName("friend");
+ f3.setLastName("three");
+ Person f4 = factory.createPerson();
+ f4.setFirstName("friend");
+ f4.setLastName("four");
+
+ f1.getFriends().add(f2);
+ f1.getFriends().add(f3);
+ f1.getFriends().add(f4);
+
+ f2.getFriends().add(f3);
+ f2.getFriends().add(f4);
+
+ f4.getFriends().add(f1);
+ f4.getFriends().add(f2);
+ f4.getFriends().add(f3);
+
+ f3.getFriends().add(f2);
+ f3.getFriends().add(f4);
+
+ store.store(f1);
+ store.commitTransaction();
+ }
+
+ // read again
+ {
+ store.beginTransaction();
+ final Parent parent = store.getObject(Parent.class);
+ assertEquals(2, parent.getChildren().size());
+ assertEquals("Johnny", parent.getChildren().get(0).getFirstName());
+ assertEquals("Jane", parent.getChildren().get(1).getFirstName());
+ final House h = store.getObject(House.class);
+ assertEquals(parent, h.getOwner());
+ assertTrue(h.getVisitors().contains(parent));
+ assertEquals(2, h.getVisitors().size());
+ assertTrue(h.getVisitors().contains(parent.getChildren().get(1)));
+ store.commitTransaction();
+ }
+
+ // check version column and foreign keys
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+
+ checkVersion(store);
+
+ // depending on the inheritance strategy the foreign key is stored in different
+ // table
+ if (store.getInheritanceType() == InheritanceType.SINGLE_TABLE) {
+ final ResultSet rs = stmt.executeQuery("select myParentFirstName from person");
+ assertTrue(rs.next());
+ } else {
+ final ResultSet rs = stmt.executeQuery("select myParentFirstName from child");
+ assertTrue(rs.next());
+ }
+ } finally {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ } catch (final SQLException e) {
+ throw new StoreTestException("Sql exception when checking db schema", e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LazyLibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LazyLibraryAction.java
new file mode 100755
index 000000000..450312935
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LazyLibraryAction.java
@@ -0,0 +1,224 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * LazyLibraryAction.java,v 1.9 2007/03/29 15:00:32 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.mapping.elist.PersistableEList;
+import org.eclipse.emf.teneo.resource.StoreResource;
+import org.eclipse.emf.teneo.samples.emf.annotations.lazy.Book;
+import org.eclipse.emf.teneo.samples.emf.annotations.lazy.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.annotations.lazy.LazyFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.lazy.LazyPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.lazy.Library;
+import org.eclipse.emf.teneo.samples.emf.annotations.lazy.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests non-resolving behavior of containment references. Main test is that setTrackingModification
+ * does not result in loaded containment elists.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.14 $
+ */
+public class LazyLibraryAction extends AbstractTestAction {
+ /** Small adapter test */
+ private class LibraryAdapter extends AdapterImpl {
+ /** Counts the number of changes */
+ private int countNotifications = 0;
+
+ /** Returns the number of notifications */
+ public int getCountNotifications() {
+ return countNotifications;
+ }
+
+ /**
+ * Returns <code>false</code>
+ *
+ * @param type
+ * the type.
+ * @return <code>false</code>
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type instanceof Writer;
+ }
+
+ /**
+ * Does nothing; clients may override so that it does something.
+ */
+ @Override
+ public void notifyChanged(Notification msg) {
+ countNotifications++;
+ }
+ }
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LazyLibraryAction() {
+ super(LazyPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final LazyFactory factory = LazyFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship of the Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(500);
+ book2.setTitle("The Hobbit");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ // sorry george making a mistake here, will correct this below
+ final Book book3 = factory.createBook();
+ book3.setAuthor(writer);
+ book3.setPages(500);
+ book3.setTitle("1984");
+ book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.setName("Science Fiction");
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getBooks().add(book3);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ res.save(null);
+ res.unload();
+ }
+
+ // test settrackingmodification before load
+ {
+ final Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.setTrackingModification(true);
+ res.load(null);
+ testResolving(res);
+ }
+
+ // test settrackingmodification after load
+ {
+ final Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.load(null);
+ res.setTrackingModification(true);
+ testResolving(res);
+ }
+
+ // test with resolving
+ {
+ final Resource res = store.getResource();
+ // default is false
+ res.load(null);
+ res.setTrackingModification(true);
+ testResolving(res);
+ }
+
+ // simple test without setTrackingModification
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+
+ final Library lib = (Library) res.getContents().get(0);
+ final PersistableEList<?> writers = (PersistableEList<?>) lib.getWriters();
+ assertTrue("Elist should be loaded", writers.isLoaded());
+ assertTrue(lib.getWriters().get(0).eContainer() == lib);
+ assertTrue(lib.getBooks().get(0).eContainer() == lib);
+ res.unload();
+ }
+
+ {
+ store.beginTransaction();
+ final Library lib = store.getObject(Library.class);
+ assertTrue(lib.getWriters().get(0).eContainer() == lib);
+ assertTrue(lib.getBooks().get(0).eContainer() == lib);
+ store.commitTransaction();
+ }
+ } catch (final IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPPING, "true");
+ return props;
+ }
+
+ /** Check adapters and lazy loading of nonresolving */
+ private void testResolving(Resource res) {
+ final LibraryAdapter libraryAdapter = new LibraryAdapter();
+ res.eAdapters().add(libraryAdapter);
+
+ final Library lib = (Library) res.getContents().get(0);
+ final PersistableEList<?> books = (PersistableEList<?>) lib.getBooks();
+ final PersistableEList<?> writers = (PersistableEList<?>) lib.getWriters();
+ assertTrue("Elist is not loaded while the fetch is eager", writers.isLoaded());
+ assertTrue("Elist is not loaded while the fetch is eager", books.isLoaded());
+ assertTrue("BasicIterator should have next true", books.basicIterator().hasNext());
+ assertTrue("BasicListIterator should have next true", books.basicListIterator().hasNext());
+ assertTrue("BasicIterator should have next true", writers.basicIterator().hasNext());
+ assertTrue("BasicListIterator should have next true", writers.basicListIterator().hasNext());
+ final Book book = (Book) books.get(0);
+ assertTrue(book.getAuthor().getName() != null);
+
+ final Writer writer = (Writer) writers.get(0);
+ final PersistableEList<?> writerBooks = (PersistableEList<?>) writer.getBooks();
+ assertTrue("Books of writers should not be loaded is lazy, but it seems to be eager", !writerBooks.isLoaded());
+
+ lib.setName("test" + lib.getName());
+
+ // change the first book
+ book.setTitle("test" + book.getTitle());
+
+ assertEquals(2, libraryAdapter.getCountNotifications());
+
+ boolean fndLibrary = false;
+ boolean fndBook = false;
+ for (final EObject element : ((StoreResource) res).getModifiedEObjects()) {
+ fndLibrary = fndLibrary || element == lib;
+ fndBook = fndBook || element == book;
+ }
+ assertTrue("Library should be a modified object", fndLibrary);
+ assertTrue("Book should be a modified object", fndBook);
+ assertEquals(2, ((StoreResource) res).getModifiedEObjects().size());
+ res.unload();
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.java
new file mode 100755
index 000000000..f97173d6d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.java
@@ -0,0 +1,81 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LobAction.java,v 1.8 2009/05/06 16:01:34 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.Random;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.lob.LobFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.lob.LobPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.lob.Person;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Simple test for Lob.
+ */
+public class LobAction extends AbstractTestAction {
+ private static final String ADDRESS = "Amsterdamseweg 123, 4567AZ Amsterdam";
+
+ private static final long ID = 1;
+
+ private static final String NAME = "Jan Janssen";
+
+ private static final byte[] PHOTO = new byte[64 * 1024];
+
+ static {
+ // Populate PHOTO with random bytes.
+ new Random().nextBytes(PHOTO);
+ }
+
+ public LobAction() {
+ super(LobPackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ storePerson(store);
+ testPerson(store);
+ }
+
+ private void storePerson(TestStore store) {
+ store.beginTransaction();
+
+ final Person person = LobFactory.eINSTANCE.createPerson();
+ person.setId(ID);
+ person.setName(NAME);
+ person.setAddress(ADDRESS);
+ person.setPhoto(PHOTO);
+ store.store(person);
+ store.commitTransaction();
+ }
+
+ private void testPerson(TestStore store) {
+ store.beginTransaction();
+
+ final Person person = store.getObject(Person.class);
+ assertEquals(ID, person.getId());
+ assertEquals(NAME, person.getName());
+ assertEquals(ADDRESS, person.getAddress());
+ final byte[] photo = person.getPhoto();
+ assertEquals(PHOTO.length, photo.length);
+ for (int i = 0; i < photo.length; i++) {
+ assertEquals(PHOTO[i], photo[i]);
+ }
+
+ store.commitTransaction();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.persistence.xml
new file mode 100755
index 000000000..733fcf705
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/LobAction.persistence.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/lob">
+
+ <eclass name="Person">
+ <property name="address">
+ <lob />
+ </property>
+ <property name="photo">
+ <lob />
+ <column length="1000000" />
+ </property>
+ </eclass>
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ManyToManyAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ManyToManyAction.java
new file mode 100755
index 000000000..5af0dc15e
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ManyToManyAction.java
@@ -0,0 +1,149 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ManyToManyAction.java,v 1.6 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.teneo.mapping.elist.PersistableEList;
+import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.Cntr;
+import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.Lft;
+import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.ManytomanyFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.ManytomanyPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.manytomany.Rght;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class ManyToManyAction extends AbstractTestAction {
+ /** How many test objects are created */
+ private static final int NO_TEST_OBJECTS = 10;
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public ManyToManyAction() {
+ super(ManytomanyPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final ManytomanyFactory factory = ManytomanyFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final ArrayList<Cntr> centers = new ArrayList<Cntr>();
+ final ArrayList<Lft> lefts = new ArrayList<Lft>();
+ final ArrayList<Rght> rights = new ArrayList<Rght>();
+ for (int i = 0; i < NO_TEST_OBJECTS; i++) {
+ centers.add(factory.createCntr());
+ lefts.add(factory.createLft());
+ rights.add(factory.createRght());
+ }
+ for (int i = 0; i < NO_TEST_OBJECTS; i++) {
+ final Cntr c = centers.get(i);
+ c.getLft().addAll(lefts);
+ c.getRght().addAll(rights);
+ store.store(c);
+ }
+ store.commitTransaction();
+ }
+
+ // do some counts
+ store.checkNumber(Cntr.class, NO_TEST_OBJECTS);
+ store.checkNumber(Lft.class, NO_TEST_OBJECTS);
+ store.checkNumber(Rght.class, NO_TEST_OBJECTS);
+
+ // check lazy versus eager loading
+ {
+ store.beginTransaction();
+ final List<?> lefts = store.getObjects(Lft.class);
+ assertEquals(NO_TEST_OBJECTS, lefts.size());
+ for (int i = 0; i < lefts.size(); i++) {
+ final Lft left = (Lft) lefts.get(i);
+ final PersistableEList<?> elist = (PersistableEList<?>) left.getCntr();
+ assertTrue("Lft's center elist should be lazy loaded", !elist.isLoaded());
+ assertEquals(NO_TEST_OBJECTS, left.getCntr().size());
+ }
+
+ // take one left and check the centers
+ final List<?> centers = ((Lft) lefts.get(0)).getCntr();
+ for (int i = 0; i < centers.size(); i++) {
+ final Cntr c = (Cntr) centers.get(i);
+ final PersistableEList<?> elist = (PersistableEList<?>) c.getRght();
+ assertTrue("Cntr's right elist should be eager loaded", elist.isLoaded());
+ assertEquals(NO_TEST_OBJECTS, c.getRght().size());
+ }
+
+ store.commitTransaction();
+ }
+
+ // now test noncascading delete
+ {
+ store.beginTransaction();
+ final List<?> rights = store.getObjects(Rght.class);
+ assertEquals(NO_TEST_OBJECTS, rights.size());
+ for (int i = 0; i < rights.size(); i++) {
+ final Rght right = (Rght) rights.get(i);
+ right.getCntr().clear();
+ store.store(right);
+ }
+ store.commitTransaction();
+ }
+
+ // check lazy versus eager loading
+ {
+ store.beginTransaction();
+ final List<?> lefts = store.getObjects(Lft.class);
+ assertEquals(NO_TEST_OBJECTS, lefts.size());
+ for (int i = 0; i < lefts.size(); i++) {
+ final Lft left = (Lft) lefts.get(i);
+ left.getCntr().clear();
+ store.store(left);
+ }
+ store.commitTransaction();
+ }
+
+ // do some counts
+ store.checkNumber(Cntr.class, NO_TEST_OBJECTS);
+ store.checkNumber(Lft.class, NO_TEST_OBJECTS);
+ store.checkNumber(Rght.class, NO_TEST_OBJECTS);
+
+ // now delete some
+ {
+ store.beginTransaction();
+ final List<?> lefts = store.getObjects(Lft.class);
+ assertEquals(NO_TEST_OBJECTS, lefts.size());
+ for (int i = 0; i < lefts.size(); i++) {
+ final Lft left = (Lft) lefts.get(i);
+ store.deleteObject(left);
+ }
+ store.commitTransaction();
+ }
+
+ store.checkNumber(Cntr.class, NO_TEST_OBJECTS);
+ store.checkNumber(Lft.class, 0);
+ store.checkNumber(Rght.class, NO_TEST_OBJECTS);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MapKeyAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MapKeyAction.java
new file mode 100755
index 000000000..7deb48f62
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MapKeyAction.java
@@ -0,0 +1,199 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: MapKeyAction.java,v 1.7 2009/03/15 08:09:27 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.emf.common.util.EMap;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.mapping.elist.PersistableDelegateList;
+import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.Book;
+import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.MapkeyFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.MapkeyPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.mapkey.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+import org.eclipse.emf.teneo.type.PersistentStoreAdapter;
+import org.eclipse.emf.teneo.util.StoreUtil;
+
+/**
+ * Tests support for emaps.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.7 $
+ */
+public class MapKeyAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public MapKeyAction() {
+ super(MapkeyPackage.eINSTANCE);
+ }
+
+ // set the table/column names to uppercase otherwise this testcase will fail
+ // with hsqldb because hibernate does not escape the order by clause in a
+ // query.
+ // Caused by: java.sql.SQLException: Column not found: ITEM0_.NAME in
+ // statement [select item0_."item_itemlist_e_id" as item4_1_,
+ // item0_.e_id as e1_1_, item0_.e_id as e1_575_0_, item0_.e_version as
+ // e2_575_0_, item0_."name" as name3_575_0_, item0_."item_itemlist_e_id"
+ // as item4_575_0_ from "testset_item" item0_ where
+ // item0_."item_itemlist_e_id"=?
+ // order by item0_.name desc]
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase");
+ props.put(PersistenceOptions.EMAP_AS_TRUE_MAP, "true");
+ return props;
+ }
+
+ /**
+ * Check test set, note a where clause has been set on the relation Only
+ * writers with name martin are returned
+ */
+ private void checkTestSet(Book bk) {
+ // final String prefix = bk.getTitle();
+ final ArrayList<Writer> writers = new ArrayList<Writer>();
+ for (final Object element : bk.getWriters().keySet()) {
+ final String key = (String) element;
+ final Writer w = bk.getWriters().get(key);
+ assertEquals(key, w.getName());
+ assertTrue(key.startsWith(bk.getTitle()));
+ writers.add(w);
+ }
+ if (bk.getTitle().length() == 0) {
+ assertEquals(1, writers.size());
+ final Writer writerOne = writers.get(0);
+ assertEquals(writerOne.getName(), "martin");
+ } else {
+ assertEquals(0, writers.size());
+ }
+ }
+
+ /** Create test set */
+ private Book createTestSet(String prefix) {
+ final MapkeyFactory factory = MapkeyFactory.eINSTANCE;
+ final Writer w1 = factory.createWriter();
+ w1.setName(prefix + "martin");
+ final Writer w2 = factory.createWriter();
+ w2.setName(prefix + "martin2");
+ final Book bk = factory.createBook();
+ bk.setTitle(prefix);
+ bk.getWriters().put(w1.getName(), w1);
+ bk.getWriters().put(w2.getName(), w2);
+ return bk;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ {
+ store.beginTransaction();
+ store.store(createTestSet(""));
+ store.store(createTestSet("prefix2"));
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final List<?> lst = store.getObjects(Book.class);
+ for (Object name : lst) {
+ checkTestSet((Book) name);
+ }
+ store.commitTransaction();
+ }
+
+ try {
+ final Resource res = store.getResource();
+ res.load(null);
+ final ArrayList<Book> bks = new ArrayList<Book>();
+ final ArrayList<Object> ws = new ArrayList<Object>();
+ for (final Object obj : res.getContents()) {
+ if (obj instanceof Book) {
+ final Book bk = (Book) obj;
+ if (bk.getWriters() instanceof PersistableDelegateList) {
+ // check lazy load
+ // assertTrue(!((PersistableDelegateList)bk.getWriters()).isLoaded());
+ // now load
+ if (bk.getTitle().length() == 0) {
+ assertEquals(1, bk.getWriters().size());
+ } else {
+ assertEquals(0, bk.getWriters().size());
+ }
+
+ // disabled as hibernate and jpox differ here
+ assertTrue(!((PersistableDelegateList<?>) bk
+ .getWriters()).isLoaded());
+ } else {
+ fail("Type not supported "
+ + bk.getWriters().getClass().getName());
+ }
+ bks.add(bk);
+ } else {
+ ws.add(obj);
+ }
+ }
+ assertTrue(bks.size() == 2);
+ assertTrue(ws.size() == 4);
+ res.save(Collections.EMPTY_MAP);
+ res.save(Collections.EMPTY_MAP);
+ res.unload();
+ } catch (final Exception e) {
+ throw new StoreTestException(
+ "Exception when testing with resource", e);
+ }
+
+ // test PersistentStoreAdapter
+ {
+ store.beginTransaction();
+ final Book bk = createTestSet("PSA");
+ store.store(bk);
+ store.commitTransaction();
+ final Writer w = MapkeyFactory.eINSTANCE.createWriter();
+ w.setName("PSAmartin2");
+ bk.getWriters().put(w.getName(), w);
+
+ PersistentStoreAdapter adapter = StoreUtil
+ .getPersistentStoreAdapter(bk);
+ final Object value = adapter
+ .getStoreCollection(MapkeyPackage.eINSTANCE
+ .getBook_Writers());
+ compareMaps((Map<?, ?>) value, bk.getWriters());
+ }
+ }
+
+ // compare maps
+ private void compareMaps(Map<?, ?> m1, EMap<?, ?> m2) {
+ assertTrue(m1 != m2);
+ assertEquals(m1.size(), m2.size());
+ for (Object key1 : m1.keySet()) {
+ final Object v2 = m2.get(key1);
+ final Object v1 = m1.get(key1);
+ assertTrue(v1 == v2);
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MappedSuperClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MappedSuperClassAction.java
new file mode 100755
index 000000000..4c6f4a9c5
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/MappedSuperClassAction.java
@@ -0,0 +1,149 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: MappedSuperClassAction.java,v 1.8 2008/04/06 13:44:01 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.MappedsuperclassFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.MappedsuperclassPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.mappedsuperclass.SpecificDocument;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class MappedSuperClassAction extends AbstractTestAction {
+ /**
+ * Constructor
+ */
+ public MappedSuperClassAction() {
+ super(MappedsuperclassPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE");
+ props.setProperty(PersistenceOptions.SET_ENTITY_AUTOMATICALLY, "false");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final MappedsuperclassFactory factory = MappedsuperclassFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final SpecificDocument sd = factory.createSpecificDocument();
+ sd.setMyName("TEST IT");
+ sd.setMyGenericInfo("GENERIC INFO");
+ sd.setMySpecificInfo("SPECIFIC INFO");
+ store.store(sd);
+ store.commitTransaction();
+ }
+
+ // query for the specific table
+ {
+ Connection conn = null;
+ try {
+ conn = store.getConnection();
+ final Statement stmt = conn.createStatement();
+ // the following should not fail for all inheritance strategies
+ final ResultSet rs = stmt.executeQuery("SELECT * FROM specificdocument");
+ assertTrue(rs.next());
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQLException while checking existence of table", s);
+ } finally {
+ try {
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQLException while checking existence of table", s);
+ }
+ }
+ }
+
+ // query for the mapped superclass table, should always fail!
+ {
+ Connection conn = null;
+ try {
+ conn = store.getConnection();
+ final Statement stmt = conn.createStatement();
+ // the following should not fail for all inheritance strategies
+ final ResultSet rs = stmt.executeQuery("SELECT * FROM document");
+ assertTrue(rs != null); // dummy test to get rid of warning
+ fail("The DOCUMENT table should not exist as it is a mapped superclass");
+ } catch (final SQLException s) {
+ // this is correct
+ } catch (final Exception e) {
+ throw new StoreTestException("Exception while checking existence of table", e);
+ } finally {
+ try {
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQLException while checking existence of table", s);
+ }
+ }
+ }
+
+ {
+ Connection conn = null;
+ try {
+ conn = store.getConnection();
+ final Statement stmt = conn.createStatement();
+ // the following should not fail for all inheritance strategies
+ final ResultSet rs = stmt.executeQuery("SELECT * FROM parentdocument");
+ assertTrue(rs != null); // dummy to get rid of warning
+ fail("The PARENTDOCUMENT table should not exist as it is a mapped superclass");
+ } catch (final SQLException s) {
+ // this is correct
+ } catch (final Exception e) {
+ throw new StoreTestException("Exception while checking existence of table", e);
+ } finally {
+ try {
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (final SQLException s) {
+ throw new StoreTestException("SQLException while checking existence of table", s);
+ }
+ }
+ }
+ {
+ store.beginTransaction();
+ final SpecificDocument sd = store.getObject(SpecificDocument.class);
+ assertEquals(sd.getMyName(), "TEST IT");
+ assertEquals(sd.getMyGenericInfo(), "GENERIC INFO");
+ assertEquals(sd.getMySpecificInfo(), "SPECIFIC INFO");
+ store.commitTransaction();
+ }
+
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/NaturalIdAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/NaturalIdAction.java
new file mode 100755
index 000000000..c663dae66
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/NaturalIdAction.java
@@ -0,0 +1,168 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: NaturalIdAction.java,v 1.2 2008/06/29 20:08:59 mtaal Exp $
+ */
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.Family;
+import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.NaturalIdFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.NaturalIdPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.naturalId.Person;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase for naturalid
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class NaturalIdAction extends AbstractTestAction {
+ public NaturalIdAction() {
+ super(NaturalIdPackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ final NaturalIdFactory factory = NaturalIdFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ {
+ final Family fam = factory.createFamily();
+ fam.setName("Jansen");
+ fam.setAge(100);
+ store.store(fam);
+ final Person p1 = factory.createPerson();
+ p1.setFirstName("Jan");
+ p1.setLastName("Jansen");
+ p1.setAge(35);
+ p1.setCallName("Jan");
+ p1.setFamily(fam);
+ store.store(p1);
+ final Person p2 = factory.createPerson();
+ p2.setFirstName("Piet");
+ p2.setLastName("Jansen");
+ p2.setAge(35);
+ p2.setCallName("Piet");
+ p2.setFamily(fam);
+ store.store(p2);
+ }
+ {
+ final Family fam = factory.createFamily();
+ fam.setName("Smit");
+ fam.setAge(100);
+ store.store(fam);
+ final Person p1 = factory.createPerson();
+ p1.setFirstName("Jan");
+ p1.setLastName("Smit");
+ p1.setAge(35);
+ p1.setCallName("Jan");
+ p1.setFamily(fam);
+ store.store(p1);
+ final Person p2 = factory.createPerson();
+ p2.setFirstName("Piet");
+ p2.setLastName("Smit");
+ p2.setAge(35);
+ p2.setCallName("Piet");
+ p2.setFamily(fam);
+ store.store(p2);
+ }
+ store.commitTransaction();
+ }
+
+ // now create the Jansen family again, this should fail
+ {
+ store.beginTransaction();
+ final Family fam = factory.createFamily();
+ fam.setName("Jansen");
+ fam.setAge(100);
+ try {
+ store.store(fam);
+ store.commitTransaction();
+ fail();
+ } catch (Exception e) {
+ // successfull unique key constraint check
+ store.rollbackTransaction();
+ }
+ }
+
+ {
+ store.beginTransaction();
+ Person p = null;
+ for (Object o : store.getObjects(Family.class)) {
+ final Family f = (Family) o;
+ if (f.getName().compareTo("Jansen") == 0) {
+ p = factory.createPerson();
+ p.setFirstName("Jan");
+ p.setLastName("Jansen");
+ p.setAge(35);
+ p.setCallName("Jan");
+ p.setFamily(f);
+ break;
+ }
+ }
+ try {
+ store.store(p);
+ store.commitTransaction();
+ fail();
+ } catch (Exception e) {
+ // successfull unique key constraint check
+ store.rollbackTransaction();
+ }
+ }
+
+ // create a new person with a different firstname, should work
+ {
+ store.beginTransaction();
+ Person p = null;
+ for (Object o : store.getObjects(Family.class)) {
+ final Family f = (Family) o;
+ if (f.getName().compareTo("Jansen") == 0) {
+ p = factory.createPerson();
+ p.setFirstName("Jannetje");
+ p.setLastName("Jansen");
+ p.setAge(35);
+ p.setCallName("Jan");
+ p.setFamily(f);
+ break;
+ }
+ }
+ store.store(p);
+ store.commitTransaction();
+ }
+
+ // create a new family and a person with the same name but a different
+ // family this should work
+ {
+ // now create the Jansen family again, this should fail
+ {
+ store.beginTransaction();
+ final Family fam = factory.createFamily();
+ fam.setName("Timmermans");
+ fam.setAge(100);
+ store.store(fam);
+ Person p = factory.createPerson();
+ p.setFirstName("Jan");
+ p.setLastName("Jansen");
+ p.setAge(35);
+ p.setCallName("Jan");
+ p.setFamily(fam);
+ store.store(p);
+ store.commitTransaction();
+ }
+
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OnetoonePKAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OnetoonePKAction.java
new file mode 100755
index 000000000..96ec4a616
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OnetoonePKAction.java
@@ -0,0 +1,66 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: OnetoonePKAction.java,v 1.1 2008/06/29 20:08:59 mtaal Exp $
+ */
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.otopk.Employee;
+import org.eclipse.emf.teneo.samples.emf.annotations.otopk.EmployeeInfo;
+import org.eclipse.emf.teneo.samples.emf.annotations.otopk.OtopkFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.otopk.OtopkPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase for a one-to-one with a pk
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+public class OnetoonePKAction extends AbstractTestAction {
+ public OnetoonePKAction() {
+ super(OtopkPackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ final OtopkFactory factory = OtopkFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final EmployeeInfo ei = factory.createEmployeeInfo();
+ final Employee e = factory.createEmployee();
+ e.setEmployeeInfo(ei);
+ store.store(ei);
+ store.store(e);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ final EmployeeInfo ei = factory.createEmployeeInfo();
+ final Employee e = factory.createEmployee();
+ e.setEmployeeInfo(ei);
+ store.store(ei);
+ store.store(e);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ for (Object o : store.getObjects(Employee.class)) {
+ final Employee e = (Employee) o;
+ assertEquals(e.getId(), e.getEmployeeInfo().getId());
+ }
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OverrideSecondaryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OverrideSecondaryAction.java
new file mode 100755
index 000000000..1e69befc7
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/OverrideSecondaryAction.java
@@ -0,0 +1,116 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal</copyright>
+ * $Id: OverrideSecondaryAction.java,v 1.2 2010/02/06 18:25:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Address;
+import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.AttroverridesecondarytableFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.AttroverridesecondarytablePackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Country;
+import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.Employee;
+import org.eclipse.emf.teneo.samples.emf.annotations.attroverridesecondarytable.NonEmployee;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * See bugzilla 239800
+ *
+ * @author mtaal@elver.org
+ */
+public class OverrideSecondaryAction extends AbstractTestAction {
+
+ private static final String VERIFICATION_QUERY1 = "select count(*) from secondary_table where emp_num is not null";
+ private static final String VERIFICATION_QUERY2 =
+ "select count(*) from secondary_table where other_name is not null";
+
+ public OverrideSecondaryAction() {
+ super(AttroverridesecondarytablePackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ {
+ store.beginTransaction();
+ final AttroverridesecondarytableFactory factory = AttroverridesecondarytableFactory.eINSTANCE;
+ final Employee e = factory.createEmployee();
+ String prefix = "abc";
+ e.setName(prefix + "_name");
+ e.setAddress(createAddress(prefix));
+ e.setEmployeeNumber(prefix);
+ store.store(e);
+ final NonEmployee ne = factory.createNonEmployee();
+ prefix = "def";
+ ne.setName(prefix + "_name");
+ ne.setAddress(createAddress(prefix));
+ store.store(ne);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final Employee e = store.getObject(Employee.class);
+ assertTrue(e.getName().startsWith("abc"));
+ assertTrue(e.getAddress().getCity().startsWith("abc"));
+ final NonEmployee ne = store.getObject(NonEmployee.class);
+ assertTrue(ne.getName().startsWith("def"));
+ assertTrue(ne.getAddress().getStreet().startsWith("def"));
+ store.commitTransaction();
+ }
+
+ testTable(store);
+ }
+
+ private Address createAddress(String prefix) {
+ final AttroverridesecondarytableFactory factory = AttroverridesecondarytableFactory.eINSTANCE;
+ final Address address = factory.createAddress();
+ address.setName(prefix + "_name");
+ address.setStreet(prefix + "_street");
+ address.setCity(prefix + "_city");
+ final Country c = factory.createCountry();
+ c.setName(prefix);
+ address.setCountry(c);
+ return address;
+ }
+
+ private void testTable(TestStore store) {
+ final Connection conn = store.getConnection();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery(VERIFICATION_QUERY1);
+ rs.next();
+ assertEquals(1, rs.getInt(1));
+ rs.close();
+ rs = stmt.executeQuery(VERIFICATION_QUERY2);
+ rs.next();
+ assertEquals(1, rs.getInt(1));
+ rs.close();
+ } catch (final SQLException e) {
+ assertTrue(e.getMessage(), false);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (final SQLException e) {
+ }
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ } catch (final SQLException e) {
+ }
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/PKeyJoinAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/PKeyJoinAction.java
new file mode 100755
index 000000000..60e6fcc59
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/PKeyJoinAction.java
@@ -0,0 +1,89 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: PKeyJoinAction.java,v 1.6 2008/07/06 16:23:25 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.Body;
+import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.Head;
+import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.PrimarykeyjoinFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.primarykeyjoin.PrimarykeyjoinPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class PKeyJoinAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public PKeyJoinAction() {
+ super(PrimarykeyjoinPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final PrimarykeyjoinFactory factory = PrimarykeyjoinFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final Body bd = factory.createBody();
+ bd.setTheID(5);
+ final Head hd = factory.createHead();
+ hd.setMyID(5);
+ bd.setHead(hd);
+ store.store(bd);
+ store.store(hd);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ final Body bd = store.getObject(Body.class);
+ assertEquals(5, bd.getHead().getMyID());
+ assertEquals(5, bd.getTheID());
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final Body bd = factory.createBody();
+ bd.setTheID(6);
+ final Head hd = factory.createHead();
+ hd.setMyID(7);
+ bd.setHead(hd);
+ store.store(bd);
+ store.store(hd);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ final List<?> bds = store.getObjects(Body.class);
+ for (Object o : bds) {
+ final Body b = (Body) o;
+ assertTrue(b.getTheID() == 5 || b.getTheID() == 7);
+ }
+ store.commitTransaction();
+ }
+
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondaryTableActionJDO.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondaryTableActionJDO.java
new file mode 100755
index 000000000..52d77b6dd
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondaryTableActionJDO.java
@@ -0,0 +1,98 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: SecondaryTableActionJDO.java,v 1.5 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.secondarytable.Printer;
+import org.eclipse.emf.teneo.samples.emf.annotations.secondarytable.SecondarytableFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.secondarytable.SecondarytablePackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests annotations for SecondaryTable
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class SecondaryTableActionJDO extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ * @param arg0
+ */
+ public SecondaryTableActionJDO() {
+ super(SecondarytablePackage.eINSTANCE);
+ }
+
+ /** Creates simple types and tests against */
+ @Override
+ public void doAction(TestStore store) {
+ // test a simple type
+ final SecondarytableFactory factory = SecondarytableFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final Printer p = factory.createPrinter();
+ p.setMake("HP");
+ p.setModel("officejet 2500");
+ p.setTonerMake("hp");
+ p.setTonerModel("56");
+ store.store(p);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final Printer p = (Printer) store.getObject(Printer.class);
+ assertTrue(p.getMake().compareTo("HP") == 0);
+ assertTrue(p.getModel().compareTo("officejet 2500") == 0);
+ assertTrue(p.getTonerMake().compareTo("hp") == 0);
+ store.commitTransaction();
+ }
+
+ // do a sql query to detect that the second table was created
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ final ResultSet rs = stmt.executeQuery("select * from thetoner");
+ int cnt = 0;
+ while (rs.next()) {
+ cnt++;
+ }
+ rs.close();
+ assertEquals(1, cnt);
+ } finally {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ } catch (final SQLException e) {
+ throw new StoreTestException("Sql exception when retrieving objects", e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.java
new file mode 100755
index 000000000..32857e26f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.java
@@ -0,0 +1,140 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: SecondarytableHibernateAction.java,v 1.10 2010/02/06 18:25:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.annotations.secondarytablehibernate.Person;
+import org.eclipse.emf.teneo.samples.emf.annotations.secondarytablehibernate.SecondarytablehibernateFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.secondarytablehibernate.SecondarytablehibernatePackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Simple test for Secondary table.
+ */
+public class SecondarytableHibernateAction extends AbstractTestAction {
+
+ private static final String ADDRESS = "Amsterdamseweg 123, 4567AZ Amsterdam";
+
+ private static final long ID = 1;
+
+ private static final String NAME = "Jan Janssen";
+
+ private static final byte[] PHOTO = new byte[64 * 1024];
+
+ private static final String VERIFICATION_QUERY =
+ "SELECT * FROM PERSON as A INNER JOIN PERSON_ADDRESS as B ON A.ID = B.ID "
+ + "INNER JOIN PERSON_PHOTO as C ON A.ID = C.ID";
+
+ public SecondarytableHibernateAction() {
+ super(SecondarytablehibernatePackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ storePerson(store);
+ testPerson(store);
+ testSecondaryTables(store);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase");
+ return props;
+ }
+
+ /**
+ * Stores a Person in the database.
+ */
+ private void storePerson(TestStore store) {
+ store.beginTransaction();
+
+ final Person person = SecondarytablehibernateFactory.eINSTANCE.createPerson();
+ person.setId(ID);
+ person.setName(NAME);
+ person.setAddress(ADDRESS);
+ person.setPhoto(PHOTO);
+ store.store(person);
+
+ store.commitTransaction();
+ }
+
+ /**
+ * Retrieves the previously stored Person from the database and checks its attributes.
+ */
+ private void testPerson(TestStore store) {
+ store.beginTransaction();
+
+ final List<?> results = store.query(Person.class, "id", String.valueOf(ID), 1);
+ assertEquals(1, results.size());
+ final Person person = (Person) results.get(0);
+ assertEquals(ID, person.getId());
+ assertEquals(NAME, person.getName());
+ assertEquals(ADDRESS, person.getAddress());
+ final byte[] photo = person.getPhoto();
+ assertEquals(PHOTO.length, photo.length);
+ for (int i = 0; i < photo.length; i++) {
+ assertEquals(PHOTO[i], photo[i]);
+ }
+
+ store.commitTransaction();
+ }
+
+ /**
+ * Executes a query to verify the existence of the secondary tables.
+ */
+ private void testSecondaryTables(TestStore store) {
+ final Connection conn = store.getConnection();
+ Statement statement = null;
+ ResultSet resultSet = null;
+ try {
+ statement = conn.createStatement();
+ resultSet = statement.executeQuery(VERIFICATION_QUERY);
+ } catch (final SQLException e) {
+ throw new StoreTestException(e.getMessage(), e);
+ } finally {
+ try {
+ if (resultSet != null) {
+ resultSet.close();
+ }
+ } catch (final SQLException e) {
+ }
+ try {
+ if (statement != null) {
+ statement.close();
+ }
+ } catch (final SQLException e) {
+ }
+ }
+
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.persistence.xml
new file mode 100755
index 000000000..34911d945
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SecondarytableHibernateAction.persistence.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/secondarytablehibernate">
+
+ <eclass name="Person">
+ <secondary-table name="person_address"/>
+ <secondary-table name="person_photo"/>
+ <property name="id">
+ <id/>
+ </property>
+ <property name="address">
+ <lob />
+ <column table="person_address"/>
+ </property>
+ <property name="photo">
+ <lob />
+ <column table="person_photo" length="1000000"/>
+ </property>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetNMAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetNMAction.java
new file mode 100755
index 000000000..7511ec47e
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetNMAction.java
@@ -0,0 +1,95 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: SetNMAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.nmset.MyItem;
+import org.eclipse.emf.teneo.samples.emf.annotations.nmset.NmsetFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.nmset.NmsetPackage;
+import org.eclipse.emf.teneo.samples.emf.annotations.nmset.YourItem;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests an nm relation using sets on both sides.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+ */
+public class SetNMAction extends AbstractTestAction {
+ /** The number of testitems created */
+ private static int NO_ITEMS = 10;
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ * @param arg0
+ */
+ public SetNMAction() {
+ super(NmsetPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final NmsetFactory factory = NmsetFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final ArrayList<MyItem> myItems = new ArrayList<MyItem>();
+ for (int i = 0; i < NO_ITEMS; i++) {
+ final MyItem myitem = factory.createMyItem();
+ myitem.setName("myname_" + i);
+ myItems.add(myitem);
+ store.store(myitem);
+ }
+ for (int i = 0; i < NO_ITEMS; i++) {
+ final YourItem youritem = factory.createYourItem();
+ youritem.setName("yourname_" + i);
+ youritem.getMyItem().addAll(myItems);
+ store.store(youritem);
+ }
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final List<?> list = store.getObjects(MyItem.class);
+ assertTrue(list.size() == NO_ITEMS);
+ for (int i = 0; i < list.size(); i++) {
+ assertEquals(NO_ITEMS, ((MyItem) list.get(i)).getYourItem().size());
+ ((MyItem) list.get(i)).getYourItem().remove(i);
+ }
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final List<?> list = store.getObjects(MyItem.class);
+ assertTrue(list.size() == NO_ITEMS);
+ for (int i = 0; i < list.size(); i++) {
+ assertEquals(NO_ITEMS - 1, ((MyItem) list.get(i)).getYourItem().size());
+ if (i < list.size() - 1) {
+ assertEquals("yourname_" + (i + 1), (((MyItem) list.get(i)).getYourItem().get(i)).getName());
+ }
+ }
+ store.commitTransaction();
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetResourceAction.java
new file mode 100755
index 000000000..739a1ea8a
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/SetResourceAction.java
@@ -0,0 +1,199 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * SetResourceAction.java,v 1.4 2007/02/08 23:11:22 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.annotations.set.ContainedItem;
+import org.eclipse.emf.teneo.samples.emf.annotations.set.Item;
+import org.eclipse.emf.teneo.samples.emf.annotations.set.ItemList;
+import org.eclipse.emf.teneo.samples.emf.annotations.set.SetFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.set.SetPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd using a resource. Actually tests bidirectional references
+ * using resources. Most other aspects of resources are handled in the Catalog example.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class SetResourceAction extends AbstractTestAction {
+ /** The number of testitems created */
+ private static int NO_ITEMS = 10;
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public SetResourceAction() {
+ super(SetPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final SetFactory factory = SetFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ final ArrayList<String> names = new ArrayList<String>();
+ final ArrayList<String> cnames = new ArrayList<String>();
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+
+ final ItemList list = factory.createItemList();
+ list.setName("name");
+
+ for (int i = 0; i < NO_ITEMS; i++) {
+ final Item item = factory.createItem();
+ item.setName("name_" + i);
+ names.add("name_" + i);
+ list.getItem().add(item);
+
+ final ContainedItem citem = factory.createContainedItem();
+ citem.setName("cname_" + i);
+ cnames.add("cname_" + i);
+ list.getContainedItem().add(citem);
+
+ final Item joinedItem = factory.createItem();
+ joinedItem.setName("joinedname_" + i);
+ list.getJoinedItem().add(joinedItem);
+ }
+
+ res.getContents().add(list);
+ res.save(null);
+ res.unload();
+ }
+
+ // remove(i), removeAll, move
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+ ItemList list = null;
+ for (int i = 0; i < res.getContents().size(); i++) {
+ if (res.getContents().get(i) instanceof ItemList) {
+ list = (ItemList) res.getContents().get(i);
+ }
+ }
+
+ assert (list != null);
+ assertEquals(NO_ITEMS, list.getItem().size());
+ assertEquals(NO_ITEMS, list.getContainedItem().size());
+ assertEquals(NO_ITEMS, list.getJoinedItem().size());
+
+ // do some actions
+ // remove from a certain position
+ for (int i = 0; i < list.getContainedItem().size(); i++) {
+ assertEquals(list, ((InternalEObject) list.getContainedItem().get(i)).eContainer());
+ if (i % 2 == 0) {
+ final ContainedItem citem = list.getContainedItem().get(i);
+ cnames.remove(citem.getName()); // remove from here to check later
+ list.getContainedItem().remove(i);
+ }
+ }
+
+ // test removeall
+ final ArrayList<Item> tobeDeleted = new ArrayList<Item>();
+ for (int i = 0; i < NO_ITEMS; i++) {
+ assertTrue(list == list.getItem().get(i).getItemList());
+ if (i % 2 == 0) {
+ tobeDeleted.add(list.getItem().get(i));
+ names.remove(list.getItem().get(i).getName());
+ }
+ }
+ for (final Object o : tobeDeleted) {
+ list.getItem().remove(o);
+ }
+ assertEquals(names.size(), list.getItem().size());
+
+ // test move (should not really change anything)
+ final Object obj = list.getItem().get(3);
+ list.getItem().move(1, 3);
+ assertEquals(1, list.getItem().indexOf(obj));
+
+ res.save(null);
+ res.unload();
+ }
+
+ int newCount = 0;
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+ ItemList list = null;
+ for (int i = 0; i < res.getContents().size(); i++) {
+ if (res.getContents().get(i) instanceof ItemList) {
+ list = (ItemList) res.getContents().get(i);
+ }
+ }
+
+ assert (list != null);
+
+ final ArrayList<String> checkNames = new ArrayList<String>(names);
+ for (int i = 0; i < list.getItem().size(); i++) {
+ assertTrue(checkNames.remove(list.getItem().get(i).getName()));
+ }
+ assertEquals(0, checkNames.size());
+
+ final ArrayList<String> checkCNames = new ArrayList<String>(cnames);
+ for (int i = 0; i < list.getContainedItem().size(); i++) {
+ assertTrue(checkCNames.remove(list.getContainedItem().get(i).getName()));
+ }
+ assertEquals(0, checkCNames.size());
+
+ final ArrayList<Item> newList = new ArrayList<Item>();
+ newCount = list.getItem().size();
+ for (int i = 0; i < NO_ITEMS; i++) {
+ final Item item = SetFactory.eINSTANCE.createItem();
+ item.setName("do " + i);
+ newList.add(item);
+ newCount++;
+ }
+ final EList<Item> myList = list.getItem();
+ myList.addAll(newList);
+ res.save(null);
+ res.unload();
+ }
+
+ {
+ final Resource res = store.getResource();
+ res.load(null);
+ ItemList list = null;
+ for (int i = 0; i < res.getContents().size(); i++) {
+ if (res.getContents().get(i) instanceof ItemList) {
+ list = (ItemList) res.getContents().get(i);
+ }
+ }
+ assert (list != null);
+ assertEquals(newCount, list.getItem().size());
+ res.save(null);
+ res.unload();
+ }
+ } catch (final IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.java
new file mode 100755
index 000000000..e94ceabd2
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.java
@@ -0,0 +1,80 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ToOneAction.java,v 1.6 2008/06/28 22:41:29 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.toone.Address;
+import org.eclipse.emf.teneo.samples.emf.annotations.toone.Arm;
+import org.eclipse.emf.teneo.samples.emf.annotations.toone.Head;
+import org.eclipse.emf.teneo.samples.emf.annotations.toone.Person;
+import org.eclipse.emf.teneo.samples.emf.annotations.toone.TooneFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.toone.ToonePackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class ToOneAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public ToOneAction() {
+ super(ToonePackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final TooneFactory factory = TooneFactory.eINSTANCE;
+
+ {
+ store.beginTransaction();
+ final Arm arm = factory.createArm();
+ arm.setLength(50);
+ final Address a = factory.createAddress();
+ a.setCity("Amersfoort");
+ final Person p = factory.createPerson();
+ final Head h = factory.createHead();
+ h.setHairColor("braun");
+
+ p.setAddress(a);
+ p.setHead(h);
+ p.setLeftArm(arm);
+ store.store(arm);
+ store.store(p);
+ store.commitTransaction();
+ }
+
+ // read back and check it
+ {
+ store.beginTransaction();
+ final Person p = store.getObject(Person.class);
+ store.deleteObject(p);
+ store.commitTransaction();
+ }
+
+ store.checkNumber(Person.class, 0);
+ store.checkNumber(Head.class, 0);
+ store.checkNumber(Address.class, 1);
+ store.checkNumber(Arm.class, 1);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.persistence.xml
new file mode 100755
index 000000000..b4ba5e0bb
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/ToOneAction.persistence.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- Template for TestAction persistence mapping. -->
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/toone">
+
+ <eclass name="Head">
+ <property name="person">
+ <one-to-one target-entity="Person" optional="false" mapped-by="head" fetch="EAGER">
+ <cascade>MERGE</cascade>
+ <cascade>PERSIST</cascade>
+ <cascade>REFRESH</cascade>
+ </one-to-one>
+ </property>
+ </eclass>
+
+ <eclass name="Person">
+ <property name="address">
+ <many-to-one fetch="EAGER" target-entity="Address" optional="true">
+ <cascade>MERGE</cascade>
+ <cascade>PERSIST</cascade>
+ <cascade>REFRESH</cascade>
+ </many-to-one>
+ </property>
+ <property name="head">
+ <one-to-one fetch="EAGER" target-entity="Head" optional="true" cascade="ALL" />
+ </property>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.java
new file mode 100755
index 000000000..2ffb5be68
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.java
@@ -0,0 +1,69 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * TransientAction.java,v 1.3 2007/02/01 12:35:37 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.transent.Body;
+import org.eclipse.emf.teneo.samples.emf.annotations.transent.Head;
+import org.eclipse.emf.teneo.samples.emf.annotations.transent.TransentFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.transent.TransentPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Test transient eclass
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class TransientAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public TransientAction() {
+ super(TransentPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final TransentFactory factory = TransentFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final Body bd = factory.createBody();
+ bd.setTheID(5);
+ final Head hd = factory.createHead();
+ hd.setMyID(5);
+ bd.setHead(hd);
+ store.store(bd);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ final Body bd = (Body) store.getObject(Body.class);
+ assertEquals(null, bd.getHead());
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ try {
+ final List<?> list = store.getObjects(Head.class);
+ assertTrue(list != null);// dummy to get rid of warning
+ store.commitTransaction();
+ fail("head is not mapped!");
+ } catch (final Throwable t) {
+ // success
+ }
+ }
+
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.persistence.xml
new file mode 100755
index 000000000..6bb9b660b
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/TransientAction.persistence.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/transent">
+
+ <eclass name="Body">
+ <property name="theID">
+ <id/>
+ </property>
+ </eclass>
+
+ <eclass name="Head">
+ <transient/>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.java
new file mode 100755
index 000000000..92ea05278
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.java
@@ -0,0 +1,85 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * UniqueConstraintsAction.java,v 1.3 2007/02/11 21:52:19 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.Item;
+import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.Project;
+import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.UniqueconstraintsFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.uniqueconstraints.UniqueconstraintsPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class UniqueConstraintsAction extends AbstractTestAction {
+ /**
+ * Constructor
+ */
+ public UniqueConstraintsAction() {
+ super(UniqueconstraintsPackage.eINSTANCE);
+ }
+
+ /** Test */
+ @Override
+ public void doAction(TestStore store) {
+ final UniqueconstraintsFactory factory = UniqueconstraintsFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+ final Project project = factory.createProject();
+ project.setName("project_name");
+ store.store(project);
+ final Item item = factory.createItem();
+ item.setAge(5);
+ item.setName("name");
+ item.setProject(project);
+ store.store(item);
+ store.commitTransaction();
+ }
+
+ try {
+ store.beginTransaction();
+ final Project p = store.getObject(Project.class);
+ final Item item = factory.createItem();
+ item.setAge(5);
+ item.setName("name");
+ item.setProject(p);
+ store.store(item);
+ store.commitTransaction();
+ fail("The uniqueconstraint has not been applied");
+ } catch (final Exception s) {
+ // this is correct behavior
+ store.rollbackTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final Item item = factory.createItem();
+ item.setAge(5);
+ item.setName("otherName");
+ store.store(item);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final Item item = factory.createItem();
+ item.setAge(6);
+ item.setName("name");
+ store.store(item);
+ store.commitTransaction();
+ }
+
+ store.checkNumber(Item.class, 3);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.persistence.xml
new file mode 100755
index 000000000..1189a6938
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/UniqueConstraintsAction.persistence.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/emf/teneo/samples/emf/annotations/uniqueconstraints">
+
+ <eclass name="Item">
+ <table>
+ <unique-constraint>MYSTR,MYINT,MYPROJECT</unique-constraint>
+ </table>
+ <property name="name">
+ <column name="MYSTR" />
+ </property>
+ <property name="project">
+ <join-column name="MYPROJECT" />
+ </property>
+ <property name="age">
+ <column name="MYINT" />
+ </property>
+
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/VariousAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/VariousAction.java
new file mode 100755
index 000000000..c05ee4008
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/VariousAction.java
@@ -0,0 +1,117 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: VariousAction.java,v 1.3 2009/03/15 09:26:09 mtaal Exp $
+ */
+package org.eclipse.emf.teneo.test.emf.annotations;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.annotations.various.Child;
+import org.eclipse.emf.teneo.samples.emf.annotations.various.ImmutableCity;
+import org.eclipse.emf.teneo.samples.emf.annotations.various.Parent;
+import org.eclipse.emf.teneo.samples.emf.annotations.various.VariousFactory;
+import org.eclipse.emf.teneo.samples.emf.annotations.various.VariousPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Testcase for bz 239757, 239802, 239756
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class VariousAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public VariousAction() {
+ super(VariousPackage.eINSTANCE);
+ }
+
+ /** Add an option to force to use an idbag */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(
+ PersistenceOptions.SQL_DISCRIMINATOR_VERSION_IMMUTABLE_ECLASS,
+ "false");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final VariousFactory factory = VariousFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final ImmutableCity c = factory.createImmutableCity();
+ c.setName("test");
+ final Parent p1 = createParent();
+ store.store(p1);
+ c.getParents().add(p1);
+ final Parent p2 = createParent();
+ store.store(p2);
+ c.getParents().add(p2);
+ store.store(c);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final ImmutableCity c = store.getObject(ImmutableCity.class);
+ c.setName("test2");
+ store.store(c);
+ store.commitTransaction();
+ }
+ // name should not have changed
+ {
+ store.beginTransaction();
+ final ImmutableCity c = store.getObject(ImmutableCity.class);
+ assertEquals("test", c.getName());
+ store.store(c);
+ for (Parent p : c.getParents()) {
+ // 2 parents and 10 children
+ assertEquals(12, p.getTotalPeople());
+ }
+
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ final ImmutableCity c = store.getObject(ImmutableCity.class);
+ c.getParents().remove(1);
+ store.store(c);
+ try {
+ // collection change is not allowed
+ store.commitTransaction();
+ fail();
+ } catch (Exception e) {
+ store.rollbackTransaction();
+ }
+ }
+ }
+
+ private Parent createParent() {
+ final VariousFactory factory = VariousFactory.eINSTANCE;
+ final Parent p = factory.createParent();
+ for (int i = 0; i < 5; i++) {
+ final Child c = factory.createChild();
+ p.getChildren().add(c);
+ }
+ return p;
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/_template.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/_template.persistence.xml
new file mode 100755
index 000000000..3b078bc35
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/_template.persistence.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <!-- Template for TestAction persistence mapping. -->
+
+ <epackage namespace-uri="[NAMESPACEURI]">
+
+ <eclass name="[NAME]">
+
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/small_play.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/small_play.xml
new file mode 100755
index 000000000..84f4dd1b1
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/annotations/small_play.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="ASCII"?>
+<play:PlayType xmlns:play="http://www.eclipse.org/emf/teneo/samples/emf/sample/play" title="A Midsummer Night's Dream" sceneDescription="SCENE Athens, and a wood near it." playSubTitle="A MIDSUMMER NIGHT'S DREAM">
+ <fm>
+ <p>Text placed in the public domain by Moby Lexical Tools, 1992.</p>
+ <p>SGML markup by Jon Bosak, 1992-1994.</p>
+ <p>XML version by Jon Bosak, 1996-1998.</p>
+ <p>Altered slightly by Bryan Dollery, 2003, for inclusion in an article on XML parsing in Java. Published in DevX (www.devx.com) in February 2003</p>
+ <p>This work may be freely copied and distributed worldwide.</p>
+ </fm>
+ <personae>
+ <title>Dramatis Personae</title>
+ <persona>THESEUS, Duke of Athens.</persona>
+ <persona>EGEUS, father to Hermia.</persona>
+ <personaGroup groupDescription="in love with Hermia.">
+ <persona>LYSANDER</persona>
+ <persona>DEMETRIUS</persona>
+ </personaGroup>
+ <persona>PHILOSTRATE, master of the revels to Theseus.</persona>
+ <persona>QUINCE, a carpenter.</persona>
+ <persona>SNUG, a joiner.</persona>
+ <persona>BOTTOM, a weaver.</persona>
+ <persona>FLUTE, a bellows-mender.</persona>
+ <persona>SNOUT, a tinker.</persona>
+ <persona>STARVELING, a tailor.</persona>
+ <persona>HIPPOLYTA, queen of the Amazons, betrothed to Theseus.</persona>
+ <persona>HERMIA, daughter to Egeus, in love with Lysander.</persona>
+ <persona>HELENA, in love with Demetrius.</persona>
+ <persona>OBERON, king of the fairies.</persona>
+ <persona>TITANIA, queen of the fairies.</persona>
+ <persona>PUCK, or Robin Goodfellow.</persona>
+ <personaGroup groupDescription="fairies.">
+ <persona>PEASEBLOSSOM</persona>
+ <persona>COBWEB</persona>
+ <persona>MOTH</persona>
+ <persona>MUSTARDSEED</persona>
+ </personaGroup>
+ <persona>Other fairies attending their King and Queen.</persona>
+ <persona>Attendants on Theseus and Hippolyta.</persona>
+ </personae>
+ <act pindex="1" title="I">
+ <scene pindex="1" title="SCENE I. Athens. The palace of THESEUS.">
+ <stageDirections>Enter THESEUS, HIPPOLYTA, PHILOSTRATE, and Attendants</stageDirections>
+ <speech>
+ <speaker>THESEUS</speaker>
+ <line>Now, fair Hippolyta, our nuptial hour</line>
+ </speech>
+ </scene>
+ </act>
+</play:PlayType>
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachAction.java
new file mode 100755
index 000000000..ba3e98762
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachAction.java
@@ -0,0 +1,217 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: DetachAction.java,v 1.10 2008/06/02 07:15:40 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.detach;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.samples.emf.detach.detachtest.DetachtestFactory;
+import org.eclipse.emf.teneo.samples.emf.detach.detachtest.DetachtestPackage;
+import org.eclipse.emf.teneo.samples.emf.detach.detachtest.TestA;
+import org.eclipse.emf.teneo.samples.emf.detach.detachtest.TestB;
+import org.eclipse.emf.teneo.samples.emf.detach.detachtest.TestC;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Is a test case to test basic detach functionality in the dao resource; Specifically for JPOX/JDO
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.10 $
+ */
+public abstract class DetachAction extends AbstractTestAction {
+
+ /** Constructor */
+ public DetachAction() {
+ super(DetachtestPackage.eINSTANCE);
+ }
+
+ /** Stores a TopModel Object */
+ @Override
+ public void doAction(TestStore store) {
+ try {
+ DetachtestFactory factory = DetachtestFactory.eINSTANCE;
+ // Create objects
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ TestB testb = factory.createTestB();
+ testb.setCode("testb");
+
+ TestA testa = factory.createTestA();
+ testa.setCode("testa");
+ testa.setTestB(testb);
+
+ TestB testb2 = factory.createTestB();
+ testb2.setCode("testb2");
+ TestB testb3 = factory.createTestB();
+ testb3.setCode("testb3");
+
+ TestC testc = factory.createTestC();
+ testc.setCode("testc");
+ testc.setMyDate((XMLGregorianCalendar) store.getDate(new Date()));
+ testc.getTestB().add(testb2);
+ testc.getTestB().add(testb3);
+
+ res.getContents().add(testc);
+ res.getContents().add(testa);
+
+ res.save(null);
+
+ // check the state of some of the objects
+ // MT: in the new version objects are not detached anymore
+ // checkDetached(testa);
+ // checkDetached(testb);
+ // checkDetached(testb2);
+ // checkDetached(testb3);
+ // checkDetached(testc);
+
+ // check some fields
+ if (testa.getTestB() == null || testa.getCode() == null) {
+ throw new Error("Values are lost in detached objects!");
+ }
+
+ // check some fields
+ if (testc.getTestB() == null || testc.getCode() == null) {
+ throw new Error("Values are lost in detached objects!");
+ }
+ res.unload();
+ }
+
+ // Now retrieve TestA and TestC and detach them also
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ Iterator<?> it = res.getContents().iterator();
+ TestA testa = null;
+ TestC testc = null;
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (obj instanceof TestA) {
+ assertTrue(testa == null);
+ testa = (TestA) obj;
+ }
+ if (obj instanceof TestC) {
+ assertTrue(testc == null);
+ testc = (TestC) obj;
+ }
+ }
+
+ assert (testc != null);
+ assert (testa != null);
+
+ // get testb to force a load
+ if (testc.getTestB().size() != 2 || (testc.getTestB().get(0)).getCode().compareTo("testb2") != 0) {
+ throw new Error("Where is testb?");
+ }
+
+ // now save and detach
+ res.save(null);
+
+ // MT: in the new version objects are not detached anymore
+ // checkDetached(testa);
+ // checkDetached((EObject) testc.getTestB().get(0));
+ // checkDetached(testc);
+
+ if (testc.getMyDate() == null) {
+ throw new Error("This should not be possible");
+ }
+ // now change the code of one, delete one testb from testc and add one
+ testa.setCode("detached");
+
+ TestB testb = factory.createTestB();
+ testb.setCode("testb4");
+
+ testc.getTestB().remove(0);
+ testc.getTestB().add(testb);
+
+ // reattach again!
+ res.save(null);
+ res.unload();
+ }
+
+ // Now retrieve TestA and TestC and detach them also
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ Iterator<EObject> it = res.getContents().iterator();
+ TestA testa = null;
+ TestC testc = null;
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (obj instanceof TestA) {
+ assertTrue(testa == null);
+ testa = (TestA) obj;
+ }
+ if (obj instanceof TestC) {
+ assertTrue(testc == null);
+ testc = (TestC) obj;
+ }
+ }
+
+ assert (testa != null);
+ assert (testc != null);
+
+ if (testa.getCode().compareTo("detached") != 0) {
+ throw new StoreTestException("The code of testa was not set!");
+ }
+
+ if ((testc.getTestB().get(0)).getCode().compareTo("testb3") != 0 ||
+ (testc.getTestB().get(1)).getCode().compareTo("testb4") != 0) {
+ throw new StoreTestException("TestB was not set");
+ }
+
+ // get testb to force a load
+ if (testc.getTestB().size() != 2) {
+ throw new Error("Testb should have 2 children!");
+ }
+ res.save(null);
+ res.unload();
+
+ // do some final tests
+ // MT: in the new version objects are not detached anymore
+ // checkDetached(testa);
+ // checkDetached((EObject) testc.getTestB().get(0));
+ // checkDetached((EObject) testc.getTestB().get(1));
+ // checkDetached(testc);
+ }
+ } catch (IOException e) {
+ throw new StoreTestException("IOException in resource detach test", e);
+ }
+ }
+
+ /** Checks if a certain object is really detached */
+ protected abstract void checkDetached(EObject eObject);
+ // TODO specialize for hibernate/JPOX
+ // if (eObject instanceof PersistenceCapable) {
+ // PersistenceCapable pc = (PersistenceCapable) eObject;
+ // if (!pc.jdoIsDetached())
+ // fail("The object with class: " + pc.getClass().getName() + " is not detached");
+ //
+ // if (pc.jdoGetObjectId() == null)
+ // fail("The object with class: " + pc.getClass().getName() + " has no id!");
+ // }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachEListAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachEListAction.java
new file mode 100755
index 000000000..9923d1b01
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachEListAction.java
@@ -0,0 +1,241 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * DetachEListAction.java,v 1.3 2007/02/01 12:35:37 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.detach;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.detach.detachelist.Contacts;
+import org.eclipse.emf.teneo.samples.emf.detach.detachelist.DetachelistFactory;
+import org.eclipse.emf.teneo.samples.emf.detach.detachelist.DetachelistPackage;
+import org.eclipse.emf.teneo.samples.emf.detach.detachelist.Person;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Is a test case to test detach functionality in the dao resource using an elist, checks insert,
+ * move, etc.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class DetachEListAction extends AbstractTestAction {
+
+ /** Constructor */
+ public DetachEListAction() {
+ super(DetachelistPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Stores a TopModel Object */
+ @Override
+ public void doAction(TestStore store) {
+ try {
+ DetachelistFactory factory = DetachelistFactory.eINSTANCE;
+
+ {
+ final Resource resource = store.getResource();
+
+ resource.load(Collections.EMPTY_MAP);
+ assertTrue(resource.getContents().size() == 0);
+
+ // add test data
+ Contacts contacts = factory.createContacts();
+ Person person1 = factory.createPerson();
+ person1.setName("001");
+ Person person2 = factory.createPerson();
+ person2.setName("002");
+
+ contacts.getPersons().add(person1);
+ contacts.getPersons().add(person2);
+ resource.getContents().add(contacts);
+ resource.getContents().add(person1);
+ resource.getContents().add(person2);
+
+ // this prevents a null constraint exc in hibernate
+ // assertEquals(0, contacts.getContainedPersons().size());
+ resource.save(Collections.EMPTY_MAP);
+
+ contacts = (Contacts) resource.getContents().get(0);
+ person1 = contacts.getPersons().get(0);
+ person2 = contacts.getPersons().get(1);
+
+ contacts.getPersons().clear();
+ contacts.getPersons().add(person1);
+ contacts.getPersons().add(person2);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ assertFalse(store.transactionActive());
+
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ Person person = contacts.getPersons().get(0);
+ assertEquals("001", person.getName());
+ person = contacts.getPersons().get(1);
+ assertEquals("002", person.getName());
+ resource.unload();
+ }
+
+ assertFalse(store.transactionActive());
+
+ // now move everything around
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ Person person1 = contacts.getPersons().get(0);
+ Person person2 = contacts.getPersons().get(1);
+ contacts.getPersons().clear();
+ contacts.getPersons().add(person2);
+ contacts.getPersons().add(person1);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ assertFalse(store.transactionActive());
+
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ Person person1 = contacts.getPersons().get(0);
+ Person person2 = contacts.getPersons().get(1);
+ assertTrue(person1.getName().compareTo("002") == 0);
+ assertTrue(person2.getName().compareTo("001") == 0);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ assertFalse(store.transactionActive());
+
+ // add two and delete 1
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ Person person3 = factory.createPerson();
+ person3.setName("003");
+ Person person4 = factory.createPerson();
+ person4.setName("004");
+
+ contacts.getPersons().add(person3);
+ contacts.getPersons().add(person4);
+ contacts.getPersons().remove(1); // remove person 001
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ assertFalse(store.transactionActive());
+
+ // check if this actually worked
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ assertEquals("002", (contacts.getPersons().get(0)).getName());
+ assertEquals("003", (contacts.getPersons().get(1)).getName());
+ assertEquals("004", (contacts.getPersons().get(2)).getName());
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ assertFalse(store.transactionActive());
+
+ // do a set and move
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ contacts.getPersons().move(0, 2); // order is now 004, 002, 003
+ Person person5 = factory.createPerson();
+ person5.setName("005");
+ contacts.getPersons().set(2, person5); // order is now 004, 002, 005
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ assertFalse(store.transactionActive());
+
+ // the order should be 004, 002, 005
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ assertEquals("004", (contacts.getPersons().get(0)).getName());
+ assertEquals("002", (contacts.getPersons().get(1)).getName());
+ assertEquals("005", (contacts.getPersons().get(2)).getName());
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ assertFalse(store.transactionActive());
+
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ Person person = factory.createPerson();
+ person.setName("c1");
+ contacts.getContainedPersons().add(person);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ assertFalse(store.transactionActive());
+
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = getContacts(resource);
+ Person c1 = contacts.getContainedPersons().get(0);
+ Person person004_1 = factory.createPerson();
+ person004_1.setName("004.1");
+ c1.getChildren().add(person004_1);
+ resource.save(Collections.EMPTY_MAP);
+ contacts.getContainedPersons().remove(0);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ {
+ // check that the previous step actually deleted the persons
+ store.beginTransaction();
+ final List<?> list = store.getObjects(Person.class);
+ final Iterator<?> it = list.iterator();
+ while (it.hasNext()) {
+ final Person person = (Person) it.next();
+ assertTrue(person.getName().compareTo("c1") != 0 && person.getName().compareTo("004.1") != 0);
+ }
+ store.commitTransaction();
+ }
+ assertFalse(store.transactionActive());
+ } catch (Exception e) {
+ throw new StoreTestException("Exception during detach elist test", e);
+ }
+ }
+
+ /** Get the contacts object */
+ private Contacts getContacts(Resource resource) {
+ final Iterator<?> it = resource.getContents().iterator();
+ while (it.hasNext()) {
+ final Object obj = it.next();
+ if (obj instanceof Contacts) {
+ return (Contacts) obj;
+ }
+ }
+ return null;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachFeatureMapAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachFeatureMapAction.java
new file mode 100755
index 000000000..11ebdeb97
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/detach/DetachFeatureMapAction.java
@@ -0,0 +1,284 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: DetachFeatureMapAction.java,v 1.6 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.detach;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.common.command.BasicCommandStack;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.edit.command.CopyCommand;
+import org.eclipse.emf.edit.command.CopyCommand.Helper;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
+import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.Contacts;
+import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.DetachfeaturemapFactory;
+import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.DetachfeaturemapPackage;
+import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.Person;
+import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.SpecialPerson;
+import org.eclipse.emf.teneo.samples.emf.detach.detachfeaturemap.provider.DetachfeaturemapItemProviderAdapterFactory;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.resource.StoreResource;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Is a test case to test detach functionality for featuremap with different kinds of methods
+ * on the featuremap (move, set, etc).
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class DetachFeatureMapAction extends AbstractTestAction {
+
+ /** Constructor */
+ public DetachFeatureMapAction() {
+ super(DetachfeaturemapPackage.eINSTANCE);
+ }
+
+ /**
+ * Says to use the mapping file, actually only relevant for hibernate
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.put(PersistenceOptions.USE_MAPPING_FILE, "true");
+ return props;
+ }
+
+ /** Stores a TopModel Object */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ try {
+ DetachfeaturemapFactory factory = DetachfeaturemapFactory.eINSTANCE;
+
+ {
+ final Resource resource = store.getResource();
+
+ resource.load(Collections.EMPTY_MAP);
+ assertTrue(resource.getContents().size() == 0);
+
+ // add test data
+ Contacts contacts = factory.createContacts();
+ Person person = factory.createPerson();
+ person.setName("");
+ person.getMobile().add("001");
+ person.getMobile().add("002");
+
+ contacts.getPersons().add(person);
+
+ SpecialPerson specialPerson = factory.createSpecialPerson();
+ specialPerson.setName("");
+ specialPerson.getMobile().add("001");
+ specialPerson.getMobile().add("002");
+ contacts.getPersons().add(specialPerson);
+
+ resource.getContents().add(contacts);
+
+ resource.save(Collections.EMPTY_MAP);
+
+ contacts = (Contacts) resource.getContents().get(0);
+ person = (Person) contacts.getPersons().get(0);
+
+ assertEquals(2, person.getMobile().size());
+
+ EList<Object> mobiles = person.getMobile();
+
+ Object m1 = mobiles.get(0);
+ Object m2 = mobiles.get(1);
+
+ for (Object o : new ArrayList<Object>(mobiles)) {
+ mobiles.remove(o);
+ }
+ // mobiles.clear();
+
+ mobiles.add(m1);
+ mobiles.add(m2);
+
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+
+ assertEquals(2, person.getMobile().size());
+ resource.unload();
+ }
+
+ // now move everything around
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+
+ Object p0 = person.getPhones().get(0);
+ Object p1 = person.getPhones().get(1);
+ person.getPhones().clear();
+ person.getPhones().add((FeatureMap.Entry) p1);
+ person.getPhones().add((FeatureMap.Entry) p0);
+
+ assertEquals(2, person.getMobile().size());
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+ assertTrue(person.getMobile().get(0).toString().compareTo("002") == 0);
+ assertTrue(person.getMobile().get(1).toString().compareTo("001") == 0);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ // add two and delete 1
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+ person.getMobile().add("003");
+ person.getMobile().add("004");
+ person.getMobile().remove(1); // removes 001
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ // check if this actually worked
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+ assertTrue(person.getMobile().get(0).toString().compareTo("002") == 0);
+ assertTrue(person.getMobile().get(1).toString().compareTo("003") == 0);
+ assertTrue(person.getMobile().get(2).toString().compareTo("004") == 0);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ // do a set and move
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+ person.getPhones().move(0, 2); // order is now 004, 002, 003
+ person.getMobile().set(2, "005"); // order is now 004, 002, 005
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ // the order should be 004, 002, 005
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+ assertTrue(person.getMobile().get(0).toString().compareTo("004") == 0);
+ assertTrue(person.getMobile().get(1).toString().compareTo("002") == 0);
+ assertTrue(person.getMobile().get(2).toString().compareTo("005") == 0);
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ // test a specific feature related to copy action and then changing the changed object
+ {
+ List factories = new ArrayList();
+ factories.add(new ResourceItemProviderAdapterFactory());
+ factories.add(new DetachfeaturemapItemProviderAdapterFactory());
+ factories.add(new ReflectiveItemProviderAdapterFactory());
+
+ // create an editing domain
+ ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(factories);
+ BasicCommandStack commandStack = new BasicCommandStack();
+ EditingDomain editDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap());
+ ;
+
+ // get and load the resource
+ final String uriStr = getResourceUri(store);
+ final URI uri = URI.createURI(uriStr);
+ Resource resource = editDomain.getResourceSet().createResource(uri);
+ resource.load(Collections.EMPTY_MAP);
+
+ // get contacts and person
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+
+ // copy
+ CopyCommand cpcmd = new CopyCommand(editDomain, person, new Helper()); // (CopyCommand)CopyCommand.create(editDomain,
+ // person);
+ cpcmd.execute();
+
+ // get the copied person, change it and add it to the resource
+ Person cpPerson = (Person) cpcmd.getResult().iterator().next();
+ cpPerson.setName("copy");
+ contacts.getPersons().add(cpPerson);
+
+ // save it
+ resource.save(Collections.EMPTY_MAP);
+
+ // change the copy
+ cpPerson.setName("copy2");
+
+ // before the next save gave an error but now it works fine.
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+
+ // the order should be 004, 002, 005
+ {
+ Resource resource = store.getResource();
+ resource.load(Collections.EMPTY_MAP);
+ Contacts contacts = (Contacts) resource.getContents().get(0);
+ Person person = (Person) contacts.getPersons().get(0);
+ assertTrue(person.getName().compareTo("copy2") != 0);
+ assertTrue(person.getPhones().size() > 0);
+
+ person.getMobile().clear();
+
+ resource.save(Collections.EMPTY_MAP);
+ resource.unload();
+ }
+ } catch (Exception e) {
+ throw new StoreTestException("Need to catch the resource ioexception", e);
+ }
+ }
+
+ /** Returns the resource uri, jdo is default (for now) */
+ public String getResourceUri(TestStore store) {
+ return "jpoxdao://?" + StoreResource.DS_NAME_PARAM + "=" + store.getDatabaseAdapter().getDbName();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1to1Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1to1Action.java
new file mode 100755
index 000000000..2ed746471
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1to1Action.java
@@ -0,0 +1,260 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * Relation1to1Action.java,v 1.4 2007/02/01 12:35:37 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.relation;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.ContainedChildNR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.ContainedChildR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.Main;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildNR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildNRT;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildNRTNR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.NotContainedChildRTNR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.Relation1to1Factory;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.Relation1to1Package;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1to1.impl.MainImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests many different kinds of 1:1 relations
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class Relation1to1Action extends AbstractTestAction {
+ /**
+ * Constructor
+ *
+ * @param arg0
+ */
+ public Relation1to1Action() {
+ super(Relation1to1Package.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Tests cascading deletes, required relations, etc. for 1:1 relations */
+ @Override
+ public void doAction(TestStore store) {
+ // are not able to generate correct foreign key constraints in the generated sql, therefor
+ // this does
+ // not work.
+
+ final Relation1to1Factory factory = Relation1to1Factory.eINSTANCE;
+
+ {
+ store.beginTransaction();
+
+ Main main = factory.createMain();
+ main.setName("main");
+
+ // <element name="containedonewayrequired" type="this:ContainedChildR"/>
+ ContainedChildR containedChildR = factory.createContainedChildR();
+ containedChildR.setName("contained one way required");
+ main.setContainedonewayrequired(containedChildR);
+
+ // <element name="containedoneWaynotrequired" type="this:ContainedChildNR"
+ // minOccurs="0"/>
+ ContainedChildNR containedChildNR = factory.createContainedChildNR();
+ containedChildNR.setName("contained one way not required");
+ main.setContainedoneWaynotrequired(containedChildNR);
+
+ // <element name="notcontainedonewayrequired" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildR"/>
+ NotContainedChildR notContainedChildR = factory.createNotContainedChildR();
+ notContainedChildR.setName("not contained one way required");
+ main.setNotcontainedonewayrequired(notContainedChildR);
+
+ // <element name="notcontainedonewaynotrequired" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildNR" minOccurs="0"/>
+ NotContainedChildNR notContainedChildNR = factory.createNotContainedChildNR();
+ notContainedChildNR.setName("not contained one way not required");
+ main.setNotcontainedonewaynotrequired(notContainedChildNR);
+
+ // <element name="notcontainedtwowaynotrequired" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildNRT" minOccurs="0" ecore:opposite="main"/>
+ NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT();
+ notContainedChildNRT.setName("not contained two wat not required");
+ main.setNotcontainedtwowaynotrequired(notContainedChildNRT);
+
+ assertTrue(notContainedChildNRT.getMain() != null);
+
+ // <element name="notcontainedtwowayrequirednr" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildRTNR" ecore:opposite="main"/>
+ NotContainedChildRTNR notContainedChildRTNR = factory.createNotContainedChildRTNR();
+ notContainedChildRTNR.setName("not contained two way required - not required");
+ main.setNotcontainedtwowayrequirednr(notContainedChildRTNR);
+
+ // <element name="notcontainedtwowaynotrequirednr" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildNRTNR" minOccurs="0" ecore:opposite="main"/>
+ NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR();
+ notContainedChildNRTNR.setName("not contained two way not required - not required");
+ main.setNotcontainedtwowaynotrequirednr(notContainedChildNRTNR);
+
+ store.store(main);
+
+ store.commitTransaction();
+ }
+
+ // check that the main object can not be deleted
+ {
+ store.checkDeleteFails(Main.class);
+ }
+
+ // <element name="containedonewayrequired" type="this:ContainedChildR"/>
+ // 1) we should check here that this child can not be deleted separately
+ // 2) if the main object is deleted then this child should also be deleted!
+ // ContainedChildR containedChildR = factory.createContainedChildR();
+ {
+
+ // check 1
+ store.checkDeleteFails(ContainedChildR.class);
+ }
+
+ // <element name="containedoneWaynotrequired" type="this:ContainedChildNR" minOccurs="0"/>
+ // 3) Direct delete of the child should not be possible as the parent points to it
+ // 4) if the main object is deleted then this child should also be deleted automatically
+ // ContainedChildNR containedChildNR = factory.createContainedChildNR();
+ {
+ // check 3
+ store.checkDeleteFails(ContainedChildNR.class);
+
+ // restore again
+ store.beginTransaction();
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+
+ // check the econtainer
+ assertTrue("EContainer is null", main.getContainedoneWaynotrequired().eContainer() != null);
+ assertTrue("EContainer is null", main.getContainedonewayrequired().eContainer() != null);
+
+ ContainedChildNR containedChildNR = factory.createContainedChildNR();
+ containedChildNR.setName("test1");
+ main.setContainedoneWaynotrequired(containedChildNR);
+ store.commitTransaction();
+
+ // should be two now
+ store.beginTransaction();
+ store.checkNumber(ContainedChildNR.class, 2);
+ store.commitTransaction();
+ }
+
+ // <element name="notcontainedonewayrequired" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildR"/>
+ // 6) Child can not be deleted without first removing the reference from the parent
+ // 6b) Element has to be set when parent is saved
+ // 7) The main object can not be deleted
+ // NotContainedChildR notContainedChildR = factory.createNotContainedChildR();
+ {
+ // check 6
+ store.checkDeleteFails(NotContainedChildR.class);
+
+ // check 6b
+ store.beginTransaction();
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+ main.setNotcontainedonewayrequired(null);
+ try {
+ store.commitTransaction();
+ assertTrue(false);
+ } catch (Exception e) {
+ store.rollbackTransaction();
+ }
+ }
+
+ // <element name="notcontainedtwowaynotrequired" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildNRT" minOccurs="0" ecore:opposite="main"/>
+ // NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT();
+ // 11) The main object can not be deleted without removing the ref to the child
+ // 12) Reference to child can be set to nullable and child/main object can be deleted
+ {
+ store.beginTransaction();
+ // check 11 and 12
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+ NotContainedChildNRT delChild = main.getNotcontainedtwowaynotrequired();
+ main.setNotcontainedtwowaynotrequired(null);
+ store.deleteObject(delChild);
+ store.commitTransaction();
+ }
+
+ // <element name="notcontainedtwowayrequirednr" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildRTNR" ecore:opposite="main"/>
+ // NotContainedChildRTNR notContainedChildRTNR = factory.createNotContainedChildRTNR();
+ // 13) The main object can not be deleted without removing the ref to the child
+ // 14) The ref to the child can be replaced with a reference to another child
+ {
+ // check 14
+ store.checkDeleteFails(NotContainedChildRTNR.class);
+
+ // check 14
+ /*
+ * store.beginTransaction(); MainImpl main = (MainImpl)store.getObject(Main.class);
+ * NotContainedChildRTNR curChild = main.getNotcontainedtwowayrequirednr();
+ * NotContainedChildRTNR newChild = factory.createNotContainedChildRTNR();
+ * newChild.setName("test"); main.setNotcontainedtwowayrequirednr(newChild);
+ * store.deleteObject(curChild); store.commitTransaction();
+ */
+ }
+
+ // <element name="notcontainedtwowaynotrequirednr" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildNRTNR" minOccurs="0" ecore:opposite="main"/>
+ // NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR();
+ // 15) the child object can be deleted because all references are null
+ // 16) The child object can be unset from the main object
+ {
+ // check 14
+ store.beginTransaction();
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+ NotContainedChildNRTNR child = main.getNotcontainedtwowaynotrequirednr();
+ main.setNotcontainedtwowaynotrequirednr(null);
+ store.deleteObject(child);
+ store.commitTransaction();
+ }
+
+ // now make the main object deletable!
+ {
+ store.beginTransaction();
+
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+
+ main.setNotcontainedonewaynotrequired(null);
+
+ // is null so can not be deleted
+ // store.deleteObject(main.getNotcontainedtwowaynotrequired());
+
+ main.setNotcontainedtwowaynotrequirednr(null);
+ main.setNotcontainedtwowayrequirednr(null);
+
+ store.deleteObject(main);
+
+ store.commitTransaction();
+ }
+
+ // and do some counts
+ {
+ store.beginTransaction();
+ store.checkNumber(ContainedChildR.class, 0);
+ store.checkNumber(ContainedChildNR.class, 1);
+ store.checkNumber(NotContainedChildNR.class, 1);
+ store.checkNumber(NotContainedChildNRTNR.class, 0);
+ store.checkNumber(NotContainedChildRTNR.class, 1);
+ store.checkNumber(NotContainedChildNRT.class, 0);
+ store.checkNumber(NotContainedChildR.class, 1);
+ store.commitTransaction();
+
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1tonAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1tonAction.java
new file mode 100755
index 000000000..56d3d835a
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/Relation1tonAction.java
@@ -0,0 +1,276 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * Relation1tonAction.java,v 1.3 2007/02/01 12:35:37 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.relation;
+
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.Main;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneCN;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneCR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneNN;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.OneNR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.Relation1tonFactory;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.Relation1tonPackage;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoCN;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoCR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoNN;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.TwoNR;
+import org.eclipse.emf.teneo.samples.emf.relation.relation1ton.impl.MainImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests many different kinds of 1:n relations
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class Relation1tonAction extends AbstractTestAction {
+ /** value used to create multiple entries in a list */
+ private static final int ELEM_CNT = 10;
+
+ /**
+ * Constructor
+ *
+ * @param arg0
+ */
+ public Relation1tonAction() {
+ super(Relation1tonPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Tests cascading deletes, required relations, etc. for 1:1 relations */
+ @Override
+ public void doAction(TestStore store) {
+ // are not able to generate correct foreign key constraints in the generated sql, therefor
+ // this does
+ // not work.
+ final Relation1tonFactory factory = Relation1tonFactory.eINSTANCE;
+
+ {
+ store.beginTransaction();
+
+ Main main = factory.createMain();
+ main.setName("main");
+
+ OneCR oneCr1 = factory.createOneCR();
+ oneCr1.setName("onecr1");
+ main.getOnecr().add(oneCr1);
+ OneCR oneCr2 = factory.createOneCR();
+ oneCr2.setName("onecr2");
+ main.getOnecr().add(oneCr2);
+
+ OneCN oneCn1 = factory.createOneCN();
+ oneCn1.setName("onecn1");
+ main.getOnecn().add(oneCn1);
+ OneCN oneCn2 = factory.createOneCN();
+ oneCn2.setName("onecn2");
+ main.getOnecn().add(oneCn2);
+
+ OneNN oneNn1 = factory.createOneNN();
+ oneNn1.setName("onenn1");
+ main.getOnenn().add(oneNn1);
+ OneNN oneNn2 = factory.createOneNN();
+ oneNn2.setName("onenn2");
+ main.getOnenn().add(oneNn2);
+
+ OneNR oneNr1 = factory.createOneNR();
+ oneNr1.setName("onenr1");
+ main.getOnenr().add(oneNr1);
+ OneNR oneNr2 = factory.createOneNR();
+ oneNr2.setName("onenr2");
+ main.getOnenr().add(oneNr2);
+
+ TwoCR twoCr1 = factory.createTwoCR();
+ twoCr1.setName("twocr1");
+ main.getTwocr().add(twoCr1);
+ TwoCR twoCr2 = factory.createTwoCR();
+ twoCr2.setName("twocr2");
+ main.getTwocr().add(twoCr2);
+
+ for (int i = 0; i < ELEM_CNT; i++) {
+ TwoCN twoCn = factory.createTwoCN();
+ twoCn.setName("twocn" + i);
+ main.getTwocn().add(twoCn);
+ }
+
+ for (int i = 0; i < ELEM_CNT; i++) {
+ TwoNN twoNn = factory.createTwoNN();
+ twoNn.setName("twonn" + i);
+ main.getTwonn().add(twoNn);
+ }
+
+ TwoNR twoNr1 = factory.createTwoNR();
+ twoNr1.setName("twonr1");
+ main.getTwonr().add(twoNr1);
+ TwoNR twoNr2 = factory.createTwoNR();
+ twoNr2.setName("twonr2");
+ main.getTwonr().add(twoNr2);
+
+ store.store(main);
+ store.commitTransaction();
+ }
+
+ // check that the main object can not be deleted
+ {
+ // this test fails for hibernate because hibernate apparently does not support
+ // foreign key constraints checking when removing a parent. Apparently foreign keys
+ // are always nulled out. Imo this is incorrect for two way relations.
+ // store.checkDeleteFails(Main.class);
+ }
+
+ // <element name="containedonewayrequired" type="this:ContainedChildR"/>
+ // 1) we should check here that this child can not be deleted separately
+ {
+ // childs of 1:n relations can be deleted directly!
+ // check 1
+ // store.checkDeleteFails(OneNR.class);
+ }
+
+ // <element name="containedoneWaynotrequired" type="this:ContainedChildNR" minOccurs="0"/>
+ // 3) Direct delete of the child should not be possible as the parent points to it
+ // 4) if the main object is deleted then this child should also be deleted automatically
+ // ContainedChildNR containedChildNR = factory.createContainedChildNR();
+ {
+ // childs in 1:n relations can be deleted directly!
+ // check 3
+ // store.checkDeleteFails(OneNR.class);
+
+ // restore again
+ store.beginTransaction();
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+
+ // check the econtainer
+ assertEquals(2, main.getOnecr().size());
+ assertEquals(2, main.getOnecn().size());
+ assertEquals(2, main.getOnenr().size());
+ assertEquals(2, main.getOnenn().size());
+ assertEquals(2, main.getTwocr().size());
+ assertEquals(ELEM_CNT, main.getTwocn().size());
+ assertEquals(2, main.getTwonr().size());
+ assertEquals(ELEM_CNT, main.getTwonn().size());
+
+ assertTrue("EContainer is not null", ((EObject) main.getOnecn().get(0)).eContainer() != null);
+ assertTrue("EContainer is not null", ((EObject) main.getOnecr().get(1)).eContainer() != null);
+ assertTrue("EContainer is null", ((EObject) main.getTwonn().get(1)).eContainer() == null);
+ assertTrue("EContainer is null", ((EObject) main.getTwonr().get(1)).eContainer() == null);
+
+ OneCR onecr = factory.createOneCR();
+ onecr.setName("onecr3");
+ main.getOnecr().add(onecr);
+ main.getOnecr().remove(0);
+ store.commitTransaction();
+
+ // should be two now (no cascading delete yet!)
+ store.beginTransaction();
+ store.checkNumber(OneCR.class, 2);
+ store.commitTransaction();
+ }
+
+ // <element name="notcontainedonewayrequired" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildR"/>
+ // 6b) Element has to be set when parent is saved
+ {
+ // check 6
+ // childs in 1:n relations can be deleted if there is no join table!
+ // store.checkDeleteFails(OneNR.class);
+ }
+
+ // <element name="notcontainedtwowaynotrequired" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildNRT" minOccurs="0"
+ // ecore:opposite="main"/>
+ // NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT();
+ // 11) The main object can not be deleted without removing the ref to the child
+ // 12) Reference to child can be set to nullable and child/main object can be deleted
+ {
+ store.beginTransaction();
+ // check 11 and 12
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+ OneCN delChild = main.getOnecn().get(0);
+ main.getOnecn().remove(0);
+
+ assertTrue(((EObject) main.getTwocr().get(0)).eContainer() == main);
+ assertTrue((main.getTwocr().get(0)).getMain() == main);
+
+ store.deleteObject(delChild);
+ store.commitTransaction();
+ }
+
+ // <element name="notcontainedtwowaynotrequirednr" type="xsd:IDREF"
+ // ecore:reference="this:NotContainedChildNRTNR" minOccurs="0"
+ // ecore:opposite="main"/>
+ // NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR();
+ // 15) the child object can be deleted because all references are null
+ // 16) The child object can be unset from the main object
+ {
+ // check 14
+ store.beginTransaction();
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+ OneNN child = main.getOnenn().get(0);
+ main.getOnenn().remove(0);
+ store.deleteObject(child);
+ store.commitTransaction();
+ }
+
+ // and do some counts
+ {
+ store.beginTransaction();
+ store.checkNumber(OneCN.class, 1); // 0
+ store.checkNumber(OneCR.class, 2); // 0
+ store.checkNumber(OneNN.class, 1);
+ store.checkNumber(OneNR.class, 2);
+ store.checkNumber(TwoCR.class, 2); // 0
+ store.checkNumber(TwoCN.class, ELEM_CNT); // 0
+ store.checkNumber(TwoNR.class, 2);
+ store.checkNumber(TwoNN.class, ELEM_CNT);
+ store.commitTransaction();
+
+ }
+
+ // now make the main object deletable!
+ {
+ store.beginTransaction();
+
+ MainImpl main = (MainImpl) store.getObject(Main.class);
+
+ main.getOnenn().clear();
+ main.getOnenr().clear();
+
+ main.getTwonn().clear();
+ main.getTwonr().clear();
+
+ store.deleteObject(main);
+
+ store.commitTransaction();
+ }
+
+ // and do some counts
+ {
+ store.beginTransaction();
+ store.checkNumber(OneCN.class, 0);
+ store.checkNumber(OneCR.class, 0);
+ store.checkNumber(OneNN.class, 1);
+ store.checkNumber(OneNR.class, 2);
+ store.checkNumber(TwoCR.class, 0);
+ store.checkNumber(TwoCN.class, 0);
+ store.checkNumber(TwoNR.class, 2);
+ store.checkNumber(TwoNN.class, ELEM_CNT);
+ store.commitTransaction();
+
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/RelationntomAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/RelationntomAction.java
new file mode 100755
index 000000000..768873f57
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/relation/RelationntomAction.java
@@ -0,0 +1,196 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others All rights
+ * reserved. This program and the accompanying materials are made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html Contributors: Martin Taal </copyright> $Id:
+ * RelationntomAction.java,v 1.3 2007/02/08 23:11:22 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.relation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.relation.relationntom.Main;
+import org.eclipse.emf.teneo.samples.emf.relation.relationntom.MultiNN;
+import org.eclipse.emf.teneo.samples.emf.relation.relationntom.MultiNR;
+import org.eclipse.emf.teneo.samples.emf.relation.relationntom.MultiRN;
+import org.eclipse.emf.teneo.samples.emf.relation.relationntom.RelationntomFactory;
+import org.eclipse.emf.teneo.samples.emf.relation.relationntom.RelationntomPackage;
+import org.eclipse.emf.teneo.samples.emf.relation.relationntom.impl.MainImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests many different kinds of 1:n relations
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class RelationntomAction extends AbstractTestAction {
+ /** test constants */
+ private static int NO_MAINS = 2;
+ private static int NO_MULTIS = 2;
+
+ /**
+ * Constructor
+ *
+ * @param arg0
+ */
+ public RelationntomAction() {
+ super(RelationntomPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Tests cascading deletes, required relations, etc. for 1:1 relations */
+ @Override
+ public void doAction(TestStore store) {
+ // are not able to generate correct foreign key constraints in the generated sql, therefor
+ // this does
+ // not work.
+ final RelationntomFactory factory = RelationntomFactory.eINSTANCE;
+
+ {
+ store.beginTransaction();
+
+ final ArrayList<MultiNN> multinns = new ArrayList<MultiNN>();
+ for (int i = 0; i < NO_MULTIS; i++) {
+ MultiNN multinn = factory.createMultiNN();
+ multinn.setName(" multinn " + i);
+ multinns.add(multinn);
+ store.store(multinn);
+ }
+
+ final ArrayList<MultiNR> multinrs = new ArrayList<MultiNR>();
+ for (int i = 0; i < NO_MULTIS; i++) {
+ MultiNR multi = factory.createMultiNR();
+ multi.setName(" multinr " + i);
+ multinrs.add(multi);
+ }
+
+ final ArrayList<MultiRN> multirns = new ArrayList<MultiRN>();
+ for (int i = 0; i < NO_MULTIS; i++) {
+ MultiRN multi = factory.createMultiRN();
+ multi.setName(" multirn " + i);
+ multirns.add(multi);
+ }
+
+ for (int m = 0; m < NO_MAINS; m++) {
+ Main main = factory.createMain();
+ main.setName("main");
+
+ main.getMultirn().addAll(multirns);
+ for (int i = 0; i < multinns.size(); i++) {
+ main.getMultinn().add(multinns.get(i));
+ }
+
+ main.getMultinr().addAll(multinrs);
+ store.store(main);
+ }
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+
+ final List<?> mains = store.getObjects(Main.class);
+ assertTrue(mains.size() == NO_MAINS);
+ for (int i = 0; i < mains.size(); i++) {
+ final MainImpl main = (MainImpl) mains.get(i);
+ assertEquals(NO_MULTIS, main.getMultinn().size());
+ assertEquals(NO_MULTIS, main.getMultirn().size());
+ assertEquals(NO_MULTIS, main.getMultinr().size());
+
+ for (int k = 0; k < main.getMultinn().size(); k++) {
+ MultiNN multinn = main.getMultinn().get(k);
+ assertEquals(NO_MAINS, multinn.getMain().size());
+ assertTrue(mains.containsAll(multinn.getMain()));
+ }
+ for (int k = 0; k < main.getMultinr().size(); k++) {
+ MultiNR multinr = main.getMultinr().get(k);
+ assertEquals(NO_MAINS, multinr.getMain().size());
+ assertTrue(mains.containsAll(multinr.getMain()));
+ }
+ for (int k = 0; k < main.getMultirn().size(); k++) {
+ MultiRN multirn = main.getMultirn().get(k);
+ assertEquals(NO_MAINS, multirn.getMain().size());
+ assertTrue(mains.containsAll(multirn.getMain()));
+ }
+ }
+
+ // prod = (ProductType)store.query("SELECT FROM
+ // org.eclipse.emf.teneo.test.emf.catalog.gen.impl.ProductTypeImpl WHERE
+ // remark.contains(rem) && rem.value == \"remarka\" VARIABLES
+ // org.eclipse.emf.teneo.test.emf.catalog.gen.impl.StringTypeImpl rem", 1).get(0);
+ store.commitTransaction();
+ }
+
+ /*
+ * // check that the main object can not be deleted { store.checkDeleteFails(Main.class); } //
+ * <element name="containedonewayrequired" type="this:ContainedChildR"/> // 1) we should
+ * check here that this child can not be deleted separately { // check 1
+ * store.checkDeleteFails(OneNR.class); } //<element name="containedoneWaynotrequired"
+ * type="this:ContainedChildNR" minOccurs="0"/> // 3) Direct delete of the child should not
+ * be possible as the parent points to it // 4) if the main object is deleted then this
+ * child should also be deleted automatically //ContainedChildNR containedChildNR =
+ * factory.createContainedChildNR(); { // check 3 store.checkDeleteFails(OneNR.class); //
+ * restore again store.beginTransaction(); MainImpl main =
+ * (MainImpl)store.getObject(Main.class); // check the econtainer assertTrue("Size of all
+ * collections is 2", main.getOnecr().size() == 2); assertTrue("Size of all collections is
+ * 2", main.getOnecn().size() == 2); assertTrue("Size of all collections is 2",
+ * main.getOnenr().size() == 2); assertTrue("Size of all collections is 2",
+ * main.getOnenn().size() == 2); assertTrue("Size of all collections is 2",
+ * main.getTwocr().size() == 2); assertTrue("Size of all collections is 2",
+ * main.getTwocn().size() == 100); assertTrue("Size of all collections is 2",
+ * main.getTwonr().size() == 2); assertTrue("Size of all collections is 2",
+ * main.getTwonn().size() == 100); assertTrue("EContainer is null",
+ * ((EObject)main.getOnecn().get(0)).eContainer() != null); assertTrue("EContainer is null",
+ * ((EObject)main.getOnecr().get(1)).eContainer() != null); assertTrue("EContainer is null",
+ * ((EObject)main.getTwonn().get(1)).eContainer() == null); assertTrue("EContainer is null",
+ * ((EObject)main.getTwonr().get(1)).eContainer() == null); OneCR onecr =
+ * factory.createOneCR(); onecr.setName("onecr3"); main.getOnecr().add(onecr);
+ * main.getOnecr().remove(0); store.commitTransaction(); // should be two now (no cascading
+ * delete yet!) store.beginTransaction(); store.checkNumber(OneCR.class, 2);
+ * store.commitTransaction(); } //<element name="notcontainedonewayrequired"
+ * type="xsd:IDREF" ecore:reference="this:NotContainedChildR"/> // 6b) Element has to be set
+ * when parent is saved { // check 6 store.checkDeleteFails(OneNR.class); } //<element
+ * name="notcontainedtwowaynotrequired" type="xsd:IDREF"
+ * ecore:reference="this:NotContainedChildNRT" minOccurs="0" ecore:opposite="main"/>
+ * //NotContainedChildNRT notContainedChildNRT = factory.createNotContainedChildNRT(); //
+ * 11) The main object can not be deleted without removing the ref to the child // 12)
+ * Reference to child can be set to nullable and child/main object can be deleted {
+ * store.beginTransaction(); // check 11 and 12 MainImpl main =
+ * (MainImpl)store.getObject(Main.class); OneCN delChild = (OneCN)main.getOnecn().get(0);
+ * main.getOnecn().remove(0); store.deleteObject(delChild); store.commitTransaction(); } //<element
+ * name="notcontainedtwowaynotrequirednr" type="xsd:IDREF"
+ * ecore:reference="this:NotContainedChildNRTNR" minOccurs="0" ecore:opposite="main"/>
+ * //NotContainedChildNRTNR notContainedChildNRTNR = factory.createNotContainedChildNRTNR(); //
+ * 15) the child object can be deleted because all references are null // 16) The child
+ * object can be unset from the main object { // check 14 store.beginTransaction(); MainImpl
+ * main = (MainImpl)store.getObject(Main.class); OneNN child =
+ * (OneNN)main.getOnenn().get(0); main.getOnenn().remove(0); store.deleteObject(child);
+ * store.commitTransaction(); } // and do some counts { store.beginTransaction();
+ * store.checkNumber(OneCN.class, 1); //0 store.checkNumber(OneCR.class, 2); //0
+ * store.checkNumber(OneNN.class, 1); store.checkNumber(OneNR.class, 2);
+ * store.checkNumber(TwoCR.class, 2); //0 store.checkNumber(TwoCN.class, 100); //0
+ * store.checkNumber(TwoNR.class, 2); store.checkNumber(TwoNN.class, 100);
+ * store.commitTransaction(); } // now make the main object deletable! {
+ * store.beginTransaction(); MainImpl main = (MainImpl)store.getObject(Main.class);
+ * main.getOnenn().clear(); main.getOnenr().clear(); main.getTwonn().clear();
+ * main.getTwonr().clear(); store.deleteObject(main); store.commitTransaction(); } // and do
+ * some counts { store.beginTransaction(); store.checkNumber(OneCN.class, 0);
+ * store.checkNumber(OneCR.class, 0); store.checkNumber(OneNN.class, 1);
+ * store.checkNumber(OneNR.class, 2); store.checkNumber(TwoCR.class, 0);
+ * store.checkNumber(TwoCN.class, 0); store.checkNumber(TwoNR.class, 2);
+ * store.checkNumber(TwoNN.class, 100); store.commitTransaction(); }
+ */
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/AccountingAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/AccountingAction.java
new file mode 100755
index 000000000..8b34ad32d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/AccountingAction.java
@@ -0,0 +1,81 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: AccountingAction.java,v 1.5 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.InputStream;
+
+import org.eclipse.emf.teneo.samples.emf.sample.accounting.Account;
+import org.eclipse.emf.teneo.samples.emf.sample.accounting.AccountGroup;
+import org.eclipse.emf.teneo.samples.emf.sample.accounting.Accounting;
+import org.eclipse.emf.teneo.samples.emf.sample.accounting.AccountingFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.accounting.AccountingPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.accounting.JournalGroup;
+import org.eclipse.emf.teneo.samples.emf.sample.accounting.Vat;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Performs a number of test actions on the catalog example. Create products, link a supplier,
+ * add to catalog, delete from catalog.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+*/
+public abstract class AccountingAction extends AbstractTestAction
+{
+ public AccountingAction()
+ {
+ super(AccountingPackage.eINSTANCE);
+ }
+
+ /** Creates a supplier, a product, relates then, saves and retrieves them again. */
+ public void doAction(TestStore store)
+ {
+ final AccountingFactory factory = AccountingFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+
+ Accounting all = factory.createAccounting();
+ all.setName("Accounting Data");
+
+ Vat vat = factory.createVat();
+ vat.setName("19%");
+ vat.setRate(0.19f);
+
+ Account account = factory.createBalanceAccount();
+ account.setName("Software Development Costs");
+
+ AccountGroup accGroup = factory.createAccountGroup();
+ accGroup.setName("Activa");
+ accGroup.getAccount().add(account);
+
+ JournalGroup yearJournal = factory.createJournalGroup();
+ yearJournal.setName("journalgroup");
+
+ all.getVat().add(vat);
+ all.getJournalGroup().add(yearJournal);
+ all.getAccountGroup().add(accGroup);
+
+ store.store(all);
+ store.commitTransaction();
+ }
+ imTestExport(AccountingPackage.class.getResourceAsStream("import.xmi"), store);
+ }
+
+ /** Import/export, from and to */
+ protected abstract void imTestExport(InputStream is, TestStore store);
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CapaAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CapaAction.java
new file mode 100755
index 000000000..4cfcad26e
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CapaAction.java
@@ -0,0 +1,110 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: CapaAction.java,v 1.5 2008/02/28 07:08:15 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.sample.capa.CapaFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.capa.CapaPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.capa.Machine;
+import org.eclipse.emf.teneo.samples.emf.sample.capa.MachineList;
+import org.eclipse.emf.teneo.samples.emf.sample.capa.WorkDay;
+import org.eclipse.emf.teneo.samples.emf.sample.capa.WorkWeek;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the capa, detach and update
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class CapaAction extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public CapaAction() {
+ super(CapaPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final CapaFactory factory = CapaFactory.eINSTANCE;
+ MachineList ml = factory.createMachineList();
+ {
+ store.beginTransaction();
+ Machine m = getNewMachine(factory, "id0");
+ WorkWeek ww = factory.createWorkWeek();
+ ww.getDays().add(factory.createWorkDay());
+ ww.getDays().add(factory.createWorkDay());
+ ww.getDays().add(factory.createWorkDay());
+ ww.getDays().add(factory.createWorkDay());
+ ww.getDays().add(factory.createWorkDay());
+ ww.getDays().add(factory.createWorkDay());
+ ww.getDays().add(factory.createWorkDay());
+ m.setWorkWeek(ww);
+ ml.getMachines().add(m);
+ store.store(ml);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ ml = (MachineList) store.getObject(MachineList.class);
+ store.commitTransaction();
+ }
+
+ checkReAttach(factory, store, ml);
+ }
+
+ /** Creates a machine */
+ @SuppressWarnings("unchecked")
+ protected Machine getNewMachine(CapaFactory factory, String id) {
+ final Machine m = factory.createMachine();
+ final WorkWeek wk = factory.createWorkWeek();
+ wk.getDays().addAll(getWorkDays(factory));
+ m.setWorkWeek(wk);
+ m.setMachineId(id);
+ // m.setMachineSearchString("search");
+ // m.setTaskSearchString("tss");
+ return m;
+ }
+
+ /** Returns a list of workdays */
+ private List<WorkDay> getWorkDays(CapaFactory factory) {
+ final ArrayList<WorkDay> list = new ArrayList<WorkDay>();
+ for (int i = 1; i < 8; i++) {
+ final WorkDay wd = factory.createWorkDay();
+ // wd.setDayOfWeek(i);
+ // wd.setDuration(8);
+ // wd.setStartTime(8);
+ list.add(wd);
+ }
+ return list;
+ }
+
+ /** Reattach machinelist and check */
+ protected void checkReAttach(CapaFactory factory, TestStore store, MachineList ml) {
+
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CarAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CarAction.java
new file mode 100755
index 000000000..3819eeaf9
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CarAction.java
@@ -0,0 +1,100 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: CarAction.java,v 1.3 2008/03/07 13:13:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+import com.example.car.CarFactory;
+import com.example.car.CarPackage;
+import com.example.car.CarsList;
+
+/**
+ * Test bugzilla 199373
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class CarAction extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public CarAction() {
+ super(CarPackage.eINSTANCE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPPING, "true");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ {
+ final CarsList carsList = CarFactory.eINSTANCE.createCarsList();
+ store.beginTransaction();
+ store.store(carsList);
+ store.commitTransaction();
+ }
+
+ try {
+ final Resource dbResource = store.getResource();
+ try {
+ dbResource.load(null);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ final CarsList carsList = (CarsList) dbResource.getContents().get(0);
+ final EList eListDatabaseCarType = carsList.getCarType();
+ final EList eListDatabaseCarLink = carsList.getCarLink();
+
+ final Resource fileRes = new XMLResourceImpl();
+ fileRes.load(CarFactory.class.getResourceAsStream("model/cars.xml"), Collections.EMPTY_MAP);
+
+ final CarsList rootElementFile = (CarsList) fileRes.getContents().get(0);
+ EList eListFileCarType = rootElementFile.getCarType();
+ EList eListFileCarLink = rootElementFile.getCarLink();
+
+ eListDatabaseCarType.addAll(eListFileCarType);
+ eListDatabaseCarLink.addAll(eListFileCarLink);
+ dbResource.save(Collections.EMPTY_MAP);
+ } catch (Exception e) {
+ throw new StoreTestException(e.getMessage(), e);
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogAction.java
new file mode 100755
index 000000000..d6dac3ddb
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogAction.java
@@ -0,0 +1,301 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: CatalogAction.java,v 1.8 2008/06/02 07:15:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.PriceType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.ProductType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.StringType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.SupplierType;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Performs a number of test actions on the catalog example. Create products, link a supplier, add
+ * to catalog, delete from catalog.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public abstract class CatalogAction extends AbstractTestAction {
+
+ private static int COMMENT_LENGTH = 10;
+
+ public CatalogAction() {
+ super(CatalogPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ props.setProperty(PersistenceOptions.MAX_COMMENT_LENGTH, COMMENT_LENGTH + "");
+ return props;
+ }
+
+ /** Creates a supplier, a product, relates then, saves and retrieves them again. */
+ @Override
+ public void doAction(TestStore store) {
+ long millis = (112671594);
+ millis = millis * 10000;
+ millis = millis + 4562;
+
+ final CatalogFactory factory = CatalogFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ final SupplierType supplier = factory.createSupplierType();
+ supplier.setName("supplier1");
+ supplier.setNoOfEmployees(1);
+ store.store(supplier);
+
+ final PriceType price = factory.createPriceType();
+ price.setPrice(69.96);
+ price.setSupplier(supplier);
+ price.setQuantityTo(100.0);
+ store.store(price);
+
+ final ProductType product = factory.createProductType();
+ product.setCode("product1");
+ product.setDescription("This is a very nice product");
+ final StringType str1 = factory.createStringType();
+ str1.setValue("remarka");
+ final StringType str2 = factory.createStringType();
+ str2.setValue("remarkb");
+ product.getRemark().add(str1);
+ product.getRemark().add(str2);
+ product.setPrice(price);
+ store.store(product);
+
+ // and create another product
+ final PriceType price2 = factory.createPriceType();
+ price2.setPrice(75.0);
+ price2.setSupplier(supplier);
+ price2.setQuantityTo(100.0);
+ // store.store(price2);
+
+ final ProductType product2 = factory.createProductType();
+ product2.setCode("product2");
+ // product2.setDescription("This is a very nice product");
+ final StringType strfor2 = factory.createStringType();
+ strfor2.setValue("remarkb");
+ product2.getRemark().add(strfor2);
+ product2.setPrice(price2);
+ product2.setDescription("description2");
+ store.store(product2);
+
+ store.commitTransaction();
+ }
+
+ // retrieve one product
+ // delete one of its remarks and add another remark
+ {
+ store.beginTransaction();
+
+ final List<?> results = store.query(ProductType.class, "code", "product1", 1);
+
+ assertTrue(results.size() == 1);
+
+ ProductType result = (ProductType) results.get(0);
+
+ assertTrue(result != null);
+ assertTrue(result.getCode().compareTo("product1") == 0);
+ assertTrue(result.getRemark().size() == 2);
+
+ assertTrue((result.getRemark().get(0)).getValue().compareTo("remarka") == 0);
+ assertTrue((result.getRemark().get(1)).getValue().compareTo("remarkb") == 0);
+
+ // then remove one
+ result.getRemark().remove(1);
+
+ // add another
+ final StringType str1 = factory.createStringType();
+ str1.setValue("remarkc");
+
+ result.getRemark().add(str1);
+
+ // store.store(result);
+
+ // and store again
+ store.commitTransaction();
+ }
+
+ // directly checks if the following StringTypes are in the database: remarka, remarkb and
+ // remarkc
+ // this test fails for jpox
+ {
+ store.beginTransaction();
+
+ final List<?> results = store.getObjects(StringType.class);
+ assertEquals(3, results.size());
+
+ int remarka = 0;
+ int remarkb = 0;
+ int remarkc = 0;
+ Iterator<?> it = results.iterator();
+ while (it.hasNext()) {
+ StringType str = (StringType) it.next();
+ if (str.getValue().compareTo("remarka") == 0) {
+ remarka++;
+ } else if (str.getValue().compareTo("remarkb") == 0) {
+ remarkb++;
+ } else if (str.getValue().compareTo("remarkc") == 0) {
+ remarkc++;
+ } else {
+ fail();
+ }
+ }
+ assertTrue(remarka == 1);
+ assertTrue(remarkb == 1);
+ assertTrue(remarkc == 1);
+ store.commitTransaction();
+ }
+
+ // now retrieve the second product and check it
+ {
+ store.beginTransaction();
+
+ final List<?> results = store.query(ProductType.class, "code", "product2", 1);
+
+ assertTrue(results.size() == 1);
+
+ ProductType result = (ProductType) results.get(0);
+
+ assertTrue(result.getCode().compareTo("product2") == 0);
+ assertTrue(result.getRemark().size() == 1);
+ final StringType remark = result.getRemark().get(0);
+ assertTrue(remark.eContainer() != null);
+
+ assertTrue((result.getRemark().get(0)).getValue().compareTo("remarkb") == 0);
+
+ store.commitTransaction();
+ }
+
+ // again retrieve two products
+ // create a main catalog and add the two products to it
+ // create a subcatalog and attach it to the main catalog
+ // and save the lot
+ {
+ store.beginTransaction();
+
+ ProductType result = (ProductType) store.query(ProductType.class, "code", "product1", 1).get(0);
+ ProductType result2 = (ProductType) store.query(ProductType.class, "code", "product2", 1).get(0);
+
+ final CatalogType mainCatalog = factory.createCatalogType();
+ mainCatalog.setName("MainCatalog");
+ mainCatalog.setDescription("my description");
+ mainCatalog.getProduct().add(result);
+ mainCatalog.getProduct().add(result2);
+ final CatalogType subCatalog = factory.createCatalogType();
+ subCatalog.setName("SubCatalog");
+ subCatalog.setDescription("mydescription");
+
+ mainCatalog.getSubCatalog().add(subCatalog);
+
+ store.store(mainCatalog);
+
+ store.commitTransaction();
+ }
+
+ // retrieve the main catalog and check that all products are present
+ // remove one product
+ {
+ store.beginTransaction();
+
+ CatalogType cat = (CatalogType) store.query(CatalogType.class, "name", "MainCatalog", 1).get(0);
+
+ assertTrue(cat != null);
+ assert (cat != null);
+ assertTrue(cat.getName().compareTo("MainCatalog") == 0);
+ assertTrue(cat.getProduct().size() == 2);
+ assertTrue((cat.getProduct().get(0)).getCode().compareTo("product1") == 0);
+ assertTrue((cat.getProduct().get(1)).getCode().compareTo("product2") == 0);
+ cat.getProduct().remove(1); // this product will not be deleted, only the reference
+ assertTrue((cat.getSubCatalog().get(0)).getName().compareTo("SubCatalog") == 0);
+
+ store.commitTransaction();
+ }
+
+ // test if the product2 was not deleted
+ {
+ store.beginTransaction();
+ ProductType result2 = (ProductType) store.query(ProductType.class, "code", "product2", 1).get(0);
+ assertTrue(result2 != null);
+ store.commitTransaction();
+ }
+
+ // retrieve both catalogs
+ {
+ store.beginTransaction();
+ final List<?> result = store.getObjects(CatalogType.class);
+ assertTrue(result.size() == 2);
+ Iterator<?> it = result.iterator();
+ while (it.hasNext()) {
+ CatalogType cat = (CatalogType) it.next();
+ assertTrue(cat.getName().compareTo("MainCatalog") == 0 || cat.getName().compareTo("SubCatalog") == 0);
+ }
+ store.commitTransaction();
+ }
+
+ // select a product based on one of its remark values
+ {
+ store.beginTransaction();
+
+ ProductType prod = null;
+ prod = (ProductType) store.query(getQueryText(), 1).get(0);
+
+ assertTrue((prod.getRemark().get(0)).getValue().compareTo("remarka") == 0);
+ store.commitTransaction();
+ }
+
+ // test the comments in the hdm
+ if (store.isHibernateTestStore()) {
+ final String[] test =
+ new String[] { "My product documentation".substring(0, COMMENT_LENGTH),
+ "My description documentation".substring(0, COMMENT_LENGTH),
+ "My producttype documentation".substring(0, COMMENT_LENGTH) };
+ final String xml = store.getMappingXML();
+ for (String t : test) {
+ if (xml.indexOf(t) == -1) {
+ fail("The following documentation does not appear: " + t);
+ }
+ }
+ }
+ }
+
+ /**
+ * @return Returns the string used to query a product with remarks containing the text 'remarka'
+ */
+ protected abstract String getQueryText();
+ // TODO specialize
+ // for jpox
+ // SELECT FROM org.eclipse.emf.teneo.test.emf.sample.catalog.gen.impl.ProductTypeImpl
+ // WHERE remark.contains(rem) && rem.value == \"remarka\"
+ // VARIABLES org.eclipse.emf.teneo.test.emf.sample.catalog.gen.impl.StringTypeImpl rem
+ // for hibernate
+ // SELECT product FROM org.eclipse.emf.teneo.test.emf.sample.catalog.gen.ProductType product,
+ // org.eclipse.emf.teneo.test.emf.sample.catalog.gen.StringType rem
+ // WHERE rem in elements(product.remark) and rem.value = 'remarka'
+ // }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogResourceAction.java
new file mode 100755
index 000000000..915e66c23
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/CatalogResourceAction.java
@@ -0,0 +1,378 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: CatalogResourceAction.java,v 1.8 2008/06/02 07:15:40 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.CatalogType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.PriceType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.ProductType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.StringType;
+import org.eclipse.emf.teneo.samples.emf.sample.catalog.SupplierType;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Performs a number of test actions on the catalog example. Create products, link a supplier, add
+ * to catalog, delete from catalog.
+ *
+ * All using a resource, tests add, delete and update of objects in a resource.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class CatalogResourceAction extends AbstractTestAction {
+ /**
+ * Constructor
+ *
+ * @param arg0
+ */
+ public CatalogResourceAction() {
+ super(CatalogPackage.eINSTANCE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#hibernateEnabled()
+ */
+ protected boolean hibernateEnabled() {
+ return true;
+ }
+
+ /**
+ * Creates a supplier, a product, relates then, saves them in a resource and retrieves them
+ * again. and does sme
+ */
+ Resource resource;
+
+ @Override
+ public void doAction(TestStore store) {
+ final CatalogFactory factory = CatalogFactory.eINSTANCE;
+ try {
+ double checkPrice = 69.96; // is checked later
+
+ {
+ resource = store.getResource();
+ resource.load(null);
+
+ final SupplierType supplier = factory.createSupplierType();
+ supplier.setName("supplier1");
+ supplier.setNoOfEmployees(1);
+ resource.getContents().add(supplier);
+
+ final PriceType price = factory.createPriceType();
+ price.setPrice(checkPrice);
+ price.setSupplier(supplier);
+ price.setQuantityTo(100.0);
+ resource.getContents().add(price);
+
+ final ProductType product = factory.createProductType();
+ product.setCode("product1");
+ product.setDescription("This is a very nice product");
+ final StringType str1 = factory.createStringType();
+ str1.setValue("remarka");
+ final StringType str2 = factory.createStringType();
+ str2.setValue("remarkb");
+ product.getRemark().add(str1);
+ product.getRemark().add(str2);
+ product.setPrice(price);
+ resource.getContents().add(product);
+ resource.save(null);
+ resource.unload();
+ }
+
+ {
+ // test retrieval by connection params
+ resource = store.getResource();
+ resource.load(null);
+
+ assertTrue("There should be two top objects in the resource but there are " +
+ resource.getContents().size(), resource.getContents().size() == 2);
+
+ // get the supplier
+ SupplierType supplier = null;
+ for (int i = 0; i < resource.getContents().size(); i++) {
+ if (resource.getContents().get(i) instanceof SupplierType) {
+ supplier = (SupplierType) resource.getContents().get(i);
+ }
+ }
+
+ // and create another product
+ final PriceType price2 = factory.createPriceType();
+ price2.setPrice(75.0);
+ price2.setSupplier(supplier);
+ price2.setQuantityTo(100.0);
+
+ final ProductType product2 = factory.createProductType();
+ product2.setCode("product2");
+ product2.setDescription("This is a very nice product");
+ final StringType strfor2 = factory.createStringType();
+ strfor2.setValue("remarkb");
+ product2.getRemark().add(strfor2);
+ product2.setPrice(price2);
+ resource.getContents().add(product2);
+ resource.save(null);
+ resource.unload();
+ }
+
+ store.beginTransaction();
+ store.checkNumber(ProductType.class, 2);
+ store.checkNumber(SupplierType.class, 1);
+ store.checkNumber(PriceType.class, 2);
+ store.checkNumber(StringType.class, 3);
+ store.commitTransaction();
+
+ // directly checks if the following StringTypes are in the database: remarka, remarkb
+ // and remarkc
+ {
+ store.beginTransaction();
+ final List<?> results = store.getObjects(StringType.class);
+ assertTrue(results.size() == 3);
+ int remarka = 0;
+ int remarkb = 0;
+ int remarkc = 0;
+ Iterator<?> it = results.iterator();
+ while (it.hasNext()) {
+ StringType str = (StringType) it.next();
+ if (str.getValue().compareTo("remarka") == 0) {
+ remarka++;
+ } else if (str.getValue().compareTo("remarkb") == 0) {
+ remarkb++;
+ } else if (str.getValue().compareTo("remarkc") == 0) {
+ remarkc++;
+ } else {
+ fail();
+ }
+ }
+ assertTrue(remarka == 1);
+ assertTrue(remarkb == 2);
+ assertTrue(remarkc == 0);
+ store.commitTransaction();
+ }
+
+ store.beginTransaction();
+ store.checkNumber(ProductType.class, 2);
+ store.checkNumber(SupplierType.class, 1);
+ store.checkNumber(PriceType.class, 2);
+ store.checkNumber(StringType.class, 3);
+ store.commitTransaction();
+
+ // again retrieve two products
+ // create a main catalog and add the two products to it
+ // create a subcatalog and attach it to the main catalog
+ // and save the lot
+ {
+ // test retrieval using minimal connection params
+ resource = store.getResource("fetch_minimal=true");
+ resource.load(null);
+
+ // this should force a load of the products
+ Iterator<?> it = resource.getContents().iterator();
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (obj instanceof ProductType) {
+ assertTrue(((ProductType) obj).getDescription() != null);
+ }
+ }
+
+ final CatalogType mainCatalog = factory.createCatalogType();
+ mainCatalog.setName("MainCatalog");
+ mainCatalog.setDescription("my description");
+
+ // add the products to the maincatalog
+ it = resource.getContents().iterator();
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (obj instanceof ProductType) {
+ mainCatalog.getProduct().add((ProductType) obj);
+ }
+ }
+ final CatalogType subCatalog = factory.createCatalogType();
+ subCatalog.setName("SubCatalog");
+ subCatalog.setDescription("mydescription");
+
+ mainCatalog.getSubCatalog().add(subCatalog);
+ resource.getContents().add(mainCatalog);
+ resource.getContents().add(subCatalog);
+ resource.save(null);
+ resource.unload();
+ }
+
+ store.beginTransaction();
+ store.checkNumber(CatalogType.class, 2);
+ store.commitTransaction();
+
+ // retrieve the main catalog and check that all products are present
+ // remove one product, note that because this is a non-containment relation
+ {
+ resource = store.getResource();
+ resource.load(null);
+ Iterator<?> it = resource.getContents().iterator();
+ CatalogType cat = null;
+ while (it.hasNext()) {
+ final Object obj = it.next();
+
+ assertTrue("Only top classes should be returned", obj instanceof ProductType ||
+ obj instanceof SupplierType || obj instanceof CatalogType);
+
+ if (obj instanceof CatalogType && ((CatalogType) obj).getName().compareTo("MainCatalog") == 0) {
+ assertTrue("There should only be one MainCatalog", cat == null);
+ cat = (CatalogType) obj;
+ }
+ }
+ assertTrue(cat != null);
+ assert (cat != null);
+ assertEquals(0, cat.getName().compareTo("MainCatalog"));
+ assertEquals(2, cat.getProduct().size());
+ assertTrue((cat.getProduct().get(0)).getCode().compareTo("product1") == 0);
+ assertTrue((cat.getProduct().get(1)).getCode().compareTo("product2") == 0);
+ cat.getProduct().remove(1); // this product will not be deleted, only the reference
+ assertTrue((cat.getSubCatalog().get(0)).getName().compareTo("SubCatalog") == 0);
+
+ resource.save(null);
+ resource.unload();
+ }
+
+ // product was not deleted
+ store.beginTransaction();
+ store.checkNumber(ProductType.class, 2);
+ store.commitTransaction();
+
+ // retrieve the resource and delete one product
+ {
+ resource = store.getResource();
+ resource.load(null);
+
+ // count the products in the resource
+ List<?> list = resource.getContents();
+ int cnt = 0;
+ ProductType delProduct = null;
+ for (int i = 0; i < list.size(); i++) {
+ Object obj = list.get(i);
+ if (obj instanceof ProductType) {
+ cnt++;
+
+ // test if the containment is set correctly
+ // there is always at least one remark!
+ EObject eobj = ((ProductType) obj).getRemark().get(0);
+ assertTrue("The remark should be contained in the product", eobj.eContainer() == obj);
+
+ // delete the product with 1 remark, this is then tested below
+ if (((ProductType) obj).getRemark().size() == 1) {
+ delProduct = (ProductType) obj;
+ }
+ }
+ }
+ assertTrue("There should be two products in the resource.", cnt == 2);
+
+ // now remove one product from the resource
+ resource.getContents().remove(delProduct);
+ resource.save(null);
+ resource.unload();
+ }
+
+ // do some counts
+ store.beginTransaction();
+ store.checkNumber(ProductType.class, 1);
+ store.checkNumber(SupplierType.class, 1);
+ store.checkNumber(PriceType.class, 1);
+ // note the product with one remark was deleted therefore there are 2 left
+ store.checkNumber(StringType.class, 2);
+ store.commitTransaction();
+
+ // now update an object in the resource, update a derived element (the price) and
+ // remove one remark from the list and a new one.
+ {
+ resource = store.getResource();
+ resource.load(null);
+ ProductType result = null;
+ for (int i = 0; i < resource.getContents().size(); i++) {
+ if (resource.getContents().get(i) instanceof ProductType) {
+ // there should only be one product
+ assertTrue("There should only be one product", result == null);
+ result = (ProductType) resource.getContents().get(i);
+ }
+ }
+
+ assertTrue(result != null);
+ assertTrue(result.getCode().compareTo("product1") == 0);
+ assertTrue(result.getRemark().size() == 2);
+
+ assertTrue((result.getRemark().get(0)).getValue().compareTo("remarka") == 0);
+ assertTrue((result.getRemark().get(1)).getValue().compareTo("remarkb") == 0);
+
+ // then remove one
+ result.getRemark().remove(1);
+
+ // add another
+ final StringType str1 = factory.createStringType();
+ str1.setValue("remarkc");
+
+ result.getRemark().add(str1);
+
+ result.getPrice().setPrice(result.getPrice().getPrice() + 100.0);
+ resource.save(null);
+ resource.unload();
+ }
+
+ // there should now only be a remarka and a remarkc
+ {
+ store.beginTransaction();
+ final List<?> results = store.getObjects(StringType.class);
+ assertTrue(results.size() == 2);
+ int remarka = 0;
+ int remarkb = 0;
+ int remarkc = 0;
+ Iterator<?> it = results.iterator();
+ while (it.hasNext()) {
+ StringType str = (StringType) it.next();
+ if (str.getValue().compareTo("remarka") == 0) {
+ remarka++;
+ } else if (str.getValue().compareTo("remarkb") == 0) {
+ remarkb++;
+ } else if (str.getValue().compareTo("remarkc") == 0) {
+ remarkc++;
+ } else {
+ fail();
+ }
+ }
+ assertTrue(remarka == 1);
+ assertTrue(remarkb == 0);
+ assertTrue(remarkc == 1);
+ store.commitTransaction();
+ }
+
+ // check if the update of the price was passed on
+ {
+ store.beginTransaction();
+ ProductType result = (ProductType) store.query(ProductType.class, "code", "product1", 1).get(0);
+ assertTrue(result != null);
+ assertEquals(169.96, result.getPrice().getPrice(), 0.01);
+ store.commitTransaction();
+ }
+ } catch (Exception e) {
+ throw new StoreTestException(e.getMessage(), e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ClaimAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ClaimAction.java
new file mode 100755
index 000000000..310cec8df
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ClaimAction.java
@@ -0,0 +1,117 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ClaimAction.java,v 1.3 2009/11/10 10:05:34 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.claim.Claim;
+import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimCompositeKey;
+import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimLine;
+import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimLineCompositeKey;
+import org.eclipse.emf.teneo.samples.emf.sample.claim.ClaimPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the capa, detach and update
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class ClaimAction extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public ClaimAction() {
+ super(ClaimPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.EXTRA_ANNOTATION_SOURCES,
+ "teneo.extra, teneo.extra.test, teneo.extra.test2");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ store.beginTransaction();
+ store.store(createClaim(1));
+ store.store(createClaim(2));
+ store.store(createClaim(3));
+ store.commitTransaction();
+
+ store.beginTransaction();
+ List<?> claims = store.getObjects(Claim.class);
+ for (Object o : claims) {
+ final Claim c = (Claim) o;
+ final int t = Integer.parseInt(c.getBillingName());
+ assertEquals("v" + t, c.getClaimGroupVSPId());
+ assertEquals("s" + t, c.getClaimStatus());
+ assertEquals(t, c.getClaimLine().size());
+ assertEquals("ext" + t, c.getClaimCompositeKey().getClaimExtensionNumber());
+ assertEquals("num" + t, c.getClaimCompositeKey().getClaimNumber());
+ int k = 0;
+ for (Object co : c.getClaimLine()) {
+ final ClaimLine cl = (ClaimLine) co;
+ int number = (1 + k++) * 10 * t;
+ assertEquals(number, Integer.parseInt(cl.getClaimLineCompositeKey().getClaimLineNumber()));
+ assertEquals("" + number, cl.getClaimLineStatus());
+ assertTrue(c == cl.getClaimLineCompositeKey().getClaim());
+ }
+ }
+ store.commitTransaction();
+ }
+
+ private Claim createClaim(int i) {
+ final Claim c = ClaimFactory.eINSTANCE.createClaim();
+ c.setBillingName("" + i);
+ c.setClaimGroupVSPId("v" + i);
+ c.setClaimStatus("s" + i);
+
+ ClaimCompositeKey ckey = ClaimFactory.eINSTANCE.createClaimCompositeKey();
+ ckey.setClaimExtensionNumber("ext" + i);
+ ckey.setClaimNumber("num" + i);
+ c.setClaimCompositeKey(ckey);
+ for (int j = 0; j < i; j++) {
+ c.getClaimLine().add(createClaimLine((j + 1) * 10 * i));
+ }
+ return c;
+ }
+
+ private static ClaimLine createClaimLine(int i) {
+ ClaimLine cl = ClaimFactory.eINSTANCE.createClaimLine();
+ cl.setClaimLineBilledAmount(new BigDecimal(400.0 + i));
+ cl.setClaimLineStatus("" + i);
+ cl.setServiceCode("servicecode" + i);
+
+ ClaimLineCompositeKey clkey = ClaimFactory.eINSTANCE.createClaimLineCompositeKey();
+ clkey.setClaimLineNumber(i + "");
+ cl.setClaimLineCompositeKey(clkey);
+ return cl;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/Ecore.ecore b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/Ecore.ecore
new file mode 100755
index 000000000..7ef58de7a
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/Ecore.ecore
@@ -0,0 +1,357 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="ecore"
+ nsURI="http://www.eclipse.org/emf/2002/Ecore" nsPrefix="ecore">
+ <eClassifiers xsi:type="ecore:EClass" name="EAttribute" eSuperTypes="#//EStructuralFeature">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="iD" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAttributeType" lowerBound="1"
+ eType="#//EDataType" changeable="false" volatile="true" transient="true" derived="true"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EAnnotation" eSuperTypes="#//EModelElement">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="source" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="details" upperBound="-1"
+ eType="#//EStringToStringMapEntry" containment="true" resolveProxies="false"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eModelElement" eType="#//EModelElement"
+ transient="true" resolveProxies="false" eOpposite="#//EModelElement/eAnnotations"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="contents" upperBound="-1"
+ eType="#//EObject" containment="true" resolveProxies="false"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="references" upperBound="-1"
+ eType="#//EObject"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EClass" eSuperTypes="#//EClassifier">
+ <eOperations name="isSuperTypeOf" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
+ <eParameters name="someClass" eType="#//EClass"/>
+ </eOperations>
+ <eOperations name="getFeatureCount" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ <eOperations name="getEStructuralFeature" eType="#//EStructuralFeature">
+ <eParameters name="featureID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ </eOperations>
+ <eOperations name="getFeatureID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt">
+ <eParameters name="feature" eType="#//EStructuralFeature"/>
+ </eOperations>
+ <eOperations name="getEStructuralFeature" eType="#//EStructuralFeature">
+ <eParameters name="featureName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eOperations>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="abstract" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="interface" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eSuperTypes" upperBound="-1"
+ eType="#//EClass"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eOperations" upperBound="-1"
+ eType="#//EOperation" containment="true" resolveProxies="false" eOpposite="#//EOperation/eContainingClass"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAllAttributes" upperBound="-1"
+ eType="#//EAttribute" changeable="false" volatile="true" transient="true"
+ derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAllReferences" upperBound="-1"
+ eType="#//EReference" changeable="false" volatile="true" transient="true"
+ derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eReferences" upperBound="-1"
+ eType="#//EReference" changeable="false" volatile="true" transient="true"
+ derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAttributes" upperBound="-1"
+ eType="#//EAttribute" changeable="false" volatile="true" transient="true"
+ derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAllContainments" upperBound="-1"
+ eType="#//EReference" changeable="false" volatile="true" transient="true"
+ derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAllOperations" upperBound="-1"
+ eType="#//EOperation" changeable="false" volatile="true" transient="true"
+ derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAllStructuralFeatures"
+ upperBound="-1" eType="#//EStructuralFeature" changeable="false" volatile="true"
+ transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAllSuperTypes" upperBound="-1"
+ eType="#//EClass" changeable="false" volatile="true" transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eIDAttribute" eType="#//EAttribute"
+ changeable="false" volatile="true" transient="true" derived="true" resolveProxies="false"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eStructuralFeatures" upperBound="-1"
+ eType="#//EStructuralFeature" containment="true" resolveProxies="false" eOpposite="#//EStructuralFeature/eContainingClass"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EClassifier" abstract="true" eSuperTypes="#//ENamedElement">
+ <eOperations name="isInstance" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
+ <eParameters name="object" eType="#//EJavaObject"/>
+ </eOperations>
+ <eOperations name="getClassifierID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="instanceClassName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="instanceClass" eType="#//EJavaClass"
+ changeable="false" volatile="true" transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="defaultValue" eType="#//EJavaObject"
+ changeable="false" volatile="true" transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="ePackage" eType="#//EPackage"
+ changeable="false" transient="true" eOpposite="#//EPackage/eClassifiers"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EDataType" eSuperTypes="#//EClassifier">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="serializable" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ defaultValueLiteral="true"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EEnum" eSuperTypes="#//EDataType">
+ <eOperations name="getEEnumLiteral" eType="#//EEnumLiteral">
+ <eParameters name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eOperations>
+ <eOperations name="getEEnumLiteral" eType="#//EEnumLiteral">
+ <eParameters name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ </eOperations>
+ <eOperations name="getEEnumLiteralByLiteral" eType="#//EEnumLiteral">
+ <eParameters name="literal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eOperations>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eLiterals" upperBound="-1"
+ eType="#//EEnumLiteral" containment="true" resolveProxies="false" eOpposite="#//EEnumLiteral/eEnum"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EEnumLiteral" eSuperTypes="#//ENamedElement">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="instance" eType="#//EEnumerator"
+ transient="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="literal" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eEnum" eType="#//EEnum"
+ changeable="false" transient="true" resolveProxies="false" eOpposite="#//EEnum/eLiterals"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EFactory" eSuperTypes="#//EModelElement">
+ <eOperations name="create" eType="#//EObject">
+ <eParameters name="eClass" eType="#//EClass"/>
+ </eOperations>
+ <eOperations name="createFromString" eType="#//EJavaObject">
+ <eParameters name="eDataType" eType="#//EDataType"/>
+ <eParameters name="literalValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eOperations>
+ <eOperations name="convertToString" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
+ <eParameters name="eDataType" eType="#//EDataType"/>
+ <eParameters name="instanceValue" eType="#//EJavaObject"/>
+ </eOperations>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="ePackage" lowerBound="1"
+ eType="#//EPackage" transient="true" resolveProxies="false" eOpposite="#//EPackage/eFactoryInstance"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EModelElement" abstract="true" eSuperTypes="#//EObject">
+ <eOperations name="getEAnnotation" eType="#//EAnnotation">
+ <eParameters name="source" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eOperations>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eAnnotations" upperBound="-1"
+ eType="#//EAnnotation" containment="true" resolveProxies="false" eOpposite="#//EAnnotation/eModelElement"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="ENamedElement" abstract="true" eSuperTypes="#//EModelElement">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EObject">
+ <eOperations name="eClass" eType="#//EClass"/>
+ <eOperations name="eIsProxy" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eOperations name="eResource" eType="#//EResource"/>
+ <eOperations name="eContainer" eType="#//EObject"/>
+ <eOperations name="eContainingFeature" eType="#//EStructuralFeature"/>
+ <eOperations name="eContainmentFeature" eType="#//EReference"/>
+ <eOperations name="eContents" eType="#//EEList"/>
+ <eOperations name="eAllContents" eType="#//ETreeIterator"/>
+ <eOperations name="eCrossReferences" eType="#//EEList"/>
+ <eOperations name="eGet" eType="#//EJavaObject">
+ <eParameters name="feature" eType="#//EStructuralFeature"/>
+ </eOperations>
+ <eOperations name="eGet" eType="#//EJavaObject">
+ <eParameters name="feature" eType="#//EStructuralFeature"/>
+ <eParameters name="resolve" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ </eOperations>
+ <eOperations name="eSet">
+ <eParameters name="feature" eType="#//EStructuralFeature"/>
+ <eParameters name="newValue" eType="#//EJavaObject"/>
+ </eOperations>
+ <eOperations name="eIsSet" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
+ <eParameters name="feature" eType="#//EStructuralFeature"/>
+ </eOperations>
+ <eOperations name="eUnset">
+ <eParameters name="feature" eType="#//EStructuralFeature"/>
+ </eOperations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EOperation" eSuperTypes="#//ETypedElement">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eContainingClass" eType="#//EClass"
+ changeable="false" transient="true" resolveProxies="false" eOpposite="#//EClass/eOperations"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eParameters" upperBound="-1"
+ eType="#//EParameter" containment="true" resolveProxies="false" eOpposite="#//EParameter/eOperation"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eExceptions" upperBound="-1"
+ eType="#//EClassifier"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EPackage" eSuperTypes="#//ENamedElement">
+ <eOperations name="getEClassifier" eType="#//EClassifier">
+ <eParameters name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eOperations>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="nsURI" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="nsPrefix" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eFactoryInstance" lowerBound="1"
+ eType="#//EFactory" transient="true" resolveProxies="false" eOpposite="#//EFactory/ePackage"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eClassifiers" upperBound="-1"
+ eType="#//EClassifier" containment="true" eOpposite="#//EClassifier/ePackage"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eSubpackages" upperBound="-1"
+ eType="#//EPackage" containment="true" eOpposite="#//EPackage/eSuperPackage"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eSuperPackage" eType="#//EPackage"
+ changeable="false" transient="true" eOpposite="#//EPackage/eSubpackages"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EParameter" eSuperTypes="#//ETypedElement">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eOperation" eType="#//EOperation"
+ changeable="false" transient="true" resolveProxies="false" eOpposite="#//EOperation/eParameters"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EReference" eSuperTypes="#//EStructuralFeature">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="containment" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="container" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ changeable="false" volatile="true" transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="resolveProxies" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ defaultValueLiteral="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eOpposite" eType="#//EReference"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eReferenceType" lowerBound="1"
+ eType="#//EClass" changeable="false" volatile="true" transient="true" derived="true"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EStructuralFeature" abstract="true"
+ eSuperTypes="#//ETypedElement">
+ <eOperations name="getFeatureID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ <eOperations name="getContainerClass" eType="#//EJavaClass"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="changeable" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ defaultValueLiteral="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="volatile" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="transient" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="defaultValueLiteral" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="defaultValue" eType="#//EJavaObject"
+ changeable="false" volatile="true" transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="unsettable" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="derived" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eContainingClass" eType="#//EClass"
+ changeable="false" transient="true" resolveProxies="false" eOpposite="#//EClass/eStructuralFeatures"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="ETypedElement" abstract="true" eSuperTypes="#//ENamedElement">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="ordered" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ defaultValueLiteral="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="unique" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ defaultValueLiteral="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="lowerBound" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="upperBound" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
+ defaultValueLiteral="1"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="many" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ changeable="false" volatile="true" transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="required" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
+ changeable="false" volatile="true" transient="true" derived="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="eType" eType="#//EClassifier"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EBigDecimal" instanceClassName="java.math.BigDecimal">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#decimal"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EBigInteger" instanceClassName="java.math.BigInteger">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#integer"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EBoolean" instanceClassName="boolean">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#boolean"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EBooleanObject" instanceClassName="java.lang.Boolean">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="EBoolean"/>
+ <details key="name" value="EBoolean:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EByte" instanceClassName="byte">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#byte"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EByteArray" instanceClassName="byte[]">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#hexBinary"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EByteObject" instanceClassName="java.lang.Byte">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="EByte"/>
+ <details key="name" value="EByte:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EChar" instanceClassName="char"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="ECharacterObject" instanceClassName="java.lang.Character">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="EChar"/>
+ <details key="name" value="EChar:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EDate" instanceClassName="java.util.Date"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EDiagnosticChain" instanceClassName="org.eclipse.emf.common.util.DiagnosticChain"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EDouble" instanceClassName="double">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#double"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EDoubleObject" instanceClassName="java.lang.Double">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="EDouble"/>
+ <details key="name" value="EDouble:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EEList" instanceClassName="org.eclipse.emf.common.util.EList"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EEnumerator" instanceClassName="org.eclipse.emf.common.util.Enumerator"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EFeatureMap" instanceClassName="org.eclipse.emf.ecore.util.FeatureMap"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EFeatureMapEntry" instanceClassName="org.eclipse.emf.ecore.util.FeatureMap$Entry"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EFloat" instanceClassName="float">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#float"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EFloatObject" instanceClassName="java.lang.Float">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="EFloat"/>
+ <details key="name" value="EFloat:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EInt" instanceClassName="int">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#int"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EIntegerObject" instanceClassName="java.lang.Integer">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="EInt"/>
+ <details key="name" value="EInt:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EJavaClass" instanceClassName="java.lang.Class"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EJavaObject" instanceClassName="java.lang.Object"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="ELong" instanceClassName="long">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#long"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="ELongObject" instanceClassName="java.lang.Long">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="ELong"/>
+ <details key="name" value="ELong:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EMap" instanceClassName="java.util.Map"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EResource" instanceClassName="org.eclipse.emf.ecore.resource.Resource"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EResourceSet" instanceClassName="org.eclipse.emf.ecore.resource.ResourceSet"
+ serializable="false"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="EShort" instanceClassName="short">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#short"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EShortObject" instanceClassName="java.lang.Short">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="EShort"/>
+ <details key="name" value="EShort:Object"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="EString" instanceClassName="java.lang.String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="baseType" value="http://www.w3.org/2001/XMLSchema#string"/>
+ </eAnnotations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EStringToStringMapEntry" instanceClassName="java.util.Map$Entry">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EDataType" name="ETreeIterator" instanceClassName="org.eclipse.emf.common.util.TreeIterator"
+ serializable="false"/>
+</ecore:EPackage>
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/EcoreAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/EcoreAction.java
new file mode 100755
index 000000000..edd3e127f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/EcoreAction.java
@@ -0,0 +1,198 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: EcoreAction.java,v 1.19 2010/04/02 15:25:47 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests persisting of ecore models in a relational store. Only stores them and then reads them again.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.19 $
+ */
+public class EcoreAction extends AbstractTestAction {
+
+ /** Constructor */
+ public EcoreAction() {
+ super(new EPackage[] { EcorePackage.eINSTANCE, org.eclipse.emf.ecore.xml.type.XMLTypePackage.eINSTANCE });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Reads the library model and persists it. */
+ @Override
+ public void doAction(TestStore store) {
+ if (store.getInheritanceType().equals(InheritanceType.SINGLE_TABLE)) {
+ // ignore this as this fails any way
+ return;
+ }
+ if (store.getDatabaseAdapter().getDbName().contains("mysql")) {
+ // too many joins error so ignore...
+ return;
+ }
+ // read ecore as a resource
+ final Resource resourceOne = new XMIResourceImpl();
+ try {
+ // read from the resource
+ {
+ resourceOne.load(EcoreAction.class.getResourceAsStream("library.ecore"), Collections.EMPTY_MAP);
+ // EPackage epack = (EPackage)resource.getContents().get(0);
+ // resource.unload();
+ final EPackage epack = (EPackage) resourceOne.getContents().get(0);
+
+ // some logic adds adapters (for example the EAV schema, get rid of them...)
+ for (TreeIterator<EObject> it = epack.eAllContents(); it.hasNext();) {
+ it.next().eAdapters().clear();
+ }
+ final EPackage ecorePackage = EcorePackage.eINSTANCE;
+ for (TreeIterator<EObject> it = ecorePackage.eAllContents(); it.hasNext();) {
+ it.next().eAdapters().clear();
+ }
+ final EPackage xmlTypePackage = XMLTypePackage.eINSTANCE;
+ for (TreeIterator<EObject> it = xmlTypePackage.eAllContents(); it.hasNext();) {
+ it.next().eAdapters().clear();
+ }
+
+ store.beginTransaction();
+ store.store(epack);
+ store.store(ecorePackage);
+ store.store(xmlTypePackage);
+ store.commitTransaction();
+ }
+
+ // test 285409
+ {
+ store.beginTransaction();
+ List<EAnnotation> eas = store.getObjects(EAnnotation.class);
+ assertTrue(eas.size() > 0);
+ for (EAnnotation eAnnotation : eas) {
+ assertTrue(eAnnotation.getDetails().size() > 0);
+ }
+ store.commitTransaction();
+ }
+
+ // read from the relational store
+ // and save it in a xml byte array
+ final Resource resourceTwo = new XMIResourceImpl();
+ if (true) {
+ store.beginTransaction();
+ final List<?> result = store.getObjects(EPackage.class);
+ // get the library ecore from the result
+ // EPackage libEPack = null;
+ for (int i = 0; i < result.size(); i++) {
+ final EPackage epack = (EPackage) result.get(i);
+ resourceTwo.getContents().add(epack);
+ // very simple test on name, ouch!
+ // if (epack.getName().compareToIgnoreCase("library") == 0) {
+ // libEPack = epack;
+ // }
+ }
+ // assertNotNull(libEPack);
+ // just iterate over the contents
+ int cnt = 0;
+ final Iterator<?> it = resourceTwo.getAllContents();
+ while (it.hasNext()) {
+ it.next();
+ cnt++;
+ }
+ // now compare the two resources
+ // compares fails for now
+ // compareResult(resourceOne, resourceTwo);
+ store.commitTransaction();
+ }
+
+ // and now delete the ecorepackage
+ {
+ store.beginTransaction();
+ final List<?> list = store.getObjects(EPackage.class);
+ for (Object o : list) {
+ store.deleteObject(o);
+ }
+ store.commitTransaction();
+ }
+
+ // now try the debfile
+ {
+ final Resource fileRes = new XMIResourceImpl();
+ fileRes.load(EcoreAction.class.getResourceAsStream("debFile.ecore"), Collections.EMPTY_MAP);
+ store.beginTransaction();
+ for (Object o : fileRes.getContents()) {
+ store.store(o);
+ }
+ store.commitTransaction();
+ }
+ // {
+ // store.beginTransaction();
+ // final Resource res = new XMIResourceImpl();
+ // for (Object o : store.getObjects(EPackage.class)) {
+ // res.getContents().add((EObject) o);
+ // }
+ // final OutputStream os = new FileOutputStream("/home/mtaal/mytmp/test.ecore");
+ // res.save(os, Collections.EMPTY_MAP);
+ // store.commitTransaction();
+ // }
+
+ } catch (Exception e) {
+ throw new StoreTestException("Exception when testing persistence of ecore", e);
+ }
+ }
+
+ /** Compare the original and the generated xml file */
+ protected void compareResult(Resource resourceOne, Resource ResourceTwo) throws IOException {
+ final Iterator<?> original_iterator = resourceOne.getAllContents();
+
+ final Iterator<?> new_iterator = ResourceTwo.getAllContents();
+
+ // rough structural test
+ while (new_iterator.hasNext()) {
+ assertTrue(original_iterator.hasNext());
+
+ final EObject original_object = (EObject) original_iterator.next();
+ final EObject new_object = (EObject) new_iterator.next();
+ assertEquals(original_object.getClass(), new_object.getClass());
+ }
+ assertTrue(!new_iterator.hasNext());
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ExtendedPO2Action.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ExtendedPO2Action.java
new file mode 100755
index 000000000..c05979366
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ExtendedPO2Action.java
@@ -0,0 +1,190 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ExtendedPO2Action.java,v 1.6 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.Customer;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.EPO2Factory;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.EPO2Package;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.GlobalAddress;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.Item;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.OrderStatus;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.PurchaseOrder;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.Supplier;
+import org.eclipse.emf.teneo.samples.emf.sample.epo2.USAddress;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the extended po 2 example
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $ $Date: 2008/02/28 07:08:14 $
+ */
+public abstract class ExtendedPO2Action extends AbstractTestAction {
+ public ExtendedPO2Action() {
+ super(EPO2Package.eINSTANCE);
+ }
+
+ /** Stores a TopModel Object */
+ @Override
+ public void doAction(TestStore store) {
+ final EPO2Factory factory = EPO2Factory.eINSTANCE;
+ {
+ Supplier supplier = factory.createSupplier(); // This is the root. Keep it ....
+ supplier.setName("Computer City");
+
+ PurchaseOrder po = factory.createPurchaseOrder();
+ supplier.getOrders().add(po);
+ PurchaseOrder prevpo = factory.createPurchaseOrder();
+ supplier.getOrders().add(prevpo);
+
+ po.setComment("a new purchase order");
+ prevpo.setComment("the previous purchase order");
+
+ USAddress adr = factory.createUSAddress();
+ adr.setCity("Doorn");
+ adr.setCountry("Netherlands");
+ adr.setName("M. Taal");
+ adr.setState("Utrecht");
+ adr.setStreet("Nassaulaan 7");
+ adr.setZip(3941);
+
+ USAddress adr1 = factory.createUSAddress();
+ adr1.setCity("Doorn");
+ adr1.setCountry("Netherlands");
+ adr1.setName("M. Taal");
+ adr1.setState("Utrecht");
+ adr1.setStreet("Nassaulaan 7");
+ adr1.setZip(3941);
+
+ // both have same billto
+ po.setBillTo(adr);
+ prevpo.setBillTo(adr1);
+
+ po.setOrderDate(new Date());
+ Calendar cal = new GregorianCalendar();
+ cal.add(Calendar.DAY_OF_MONTH, -5);
+ prevpo.setOrderDate(cal.getTime());
+
+ Customer cust = factory.createCustomer();
+ supplier.getCustomers().add(cust);
+ cust.setCustomerID(5000);
+ cust.getOrders().add(po); // Added by DSC for JCR validation. Remove later....
+ cust.getOrders().add(prevpo); // Added by DSC for JCR validation. Remove later....
+ po.setCustomer(cust);
+ prevpo.setCustomer(cust);
+
+ GlobalAddress globadr = factory.createGlobalAddress();
+ globadr.setCountry("Belgium");
+ globadr.setCountryCode(36);
+ globadr.setName("Belgium Office");
+ globadr.getLocation().add("MY GLOBAL LOCATION");
+
+ GlobalAddress globadr1 = factory.createGlobalAddress();
+ globadr1.setCountry("Belgium");
+ globadr1.setCountryCode(36);
+ globadr1.setName("Belgium Office");
+ globadr1.getLocation().add("MY GLOBAL LOCATION");
+
+ // both have same shipto
+ po.setShipTo(globadr);
+ prevpo.setShipTo(globadr1);
+
+ po.setStatus(OrderStatus.COMPLETE_LITERAL);
+ prevpo.setStatus(OrderStatus.BACK_ORDER_LITERAL);
+
+ Item item = factory.createItem();
+ item.setComment("I like this product");
+ item.setPartNum("500.11.22");
+ item.setProductName("Dell Latitude");
+ item.setQuantity(50);
+ item.setShipDate(new Date());
+ item.setOrder(po); // Added by DSC for JCR validation. Remove later....
+
+ Item item2 = factory.createItem();
+ item2.setComment("A few of these for me.");
+ item2.setPartNum("500.11.2000");
+ item2.setProductName("Sun Opteron Workstation");
+ item2.setQuantity(200);
+ item2.setShipDate(new Date());
+ item2.setOrder(prevpo); // Added by DSC for JCR validation. Remove later....
+
+ po.getItems().add(item);
+ prevpo.getItems().add(item2);
+ po.setPreviousOrder(prevpo);
+ store.beginTransaction();
+ store.store(supplier);
+ store.commitTransaction();
+ /*
+ * final Resource res = store.getResource(); res.getContents().add(supplier); try {
+ * res.save(Collections.EMPTY_MAP); } catch (IOException e) { throw new
+ * StoreTestException("IOException", e); }
+ */
+ }
+
+ {
+ store.beginTransaction();
+ // final Resource res2 = store.getResource();
+ // Supplier supplierTest = (Supplier)res2.getContents().get(0);
+ Supplier supplierTest = (Supplier) store.getObject(Supplier.class);
+ List<?> customers = supplierTest.getCustomers();
+ assertNotNull(customers);
+ assertTrue(customers.size() == 1);
+ assertNotNull(customers.get(0));
+ assertTrue(((Customer) customers.get(0)).getCustomerID() > 0);
+ assertNotNull(((Customer) customers.get(0)).getOrders());
+ assertTrue(((Customer) customers.get(0)).getOrders().size() == 2);
+ for (Object name : supplierTest.getOrders()) {
+ PurchaseOrder potest = (PurchaseOrder) name;
+ assertNotNull(potest.getStatus().getLiteral());
+ assertTrue(potest.getItems().size() > 0);
+ Item itemtest = potest.getItems().get(0);
+ assertNotNull(itemtest.eContainer());
+ assertNotNull(itemtest.getOrder());
+ assertNotNull(itemtest.getShipDate());
+ assertNotNull(itemtest.getPartNum());
+ assertNotNull(potest.getCustomer());
+ USAddress billTo = (USAddress) potest.getBillTo();
+ assertNotNull(billTo);
+ assertNotNull(billTo.getStreet());
+ GlobalAddress shipTo = (GlobalAddress) potest.getShipTo();
+ assertNotNull(shipTo);
+ assertTrue(shipTo.getCountryCode() > 0);
+ }
+ store.commitTransaction();
+ }
+
+ checkContainerForSeparatelyReadItem(store);
+ }
+
+ protected abstract void checkContainerForSeparatelyReadItem(TestStore store);
+ // TODO jpox was
+ // // if a contained item is read separately from the db then the
+ // // container is not set!
+ // if (store instanceof JPOXTestStore)
+ // {
+ // store.beginTransaction();
+ // Item itemtest2 = (Item)store.getObject(Item.class);
+ // assertTrue(itemtest2.eContainer() == null);
+ // store.commitTransaction();
+ // }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/FleetAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/FleetAction.java
new file mode 100755
index 000000000..f0e74b443
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/FleetAction.java
@@ -0,0 +1,129 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: FleetAction.java,v 1.3 2009/08/21 15:02:00 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Date;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+import temporal.TemporalPackage;
+import fleet.Address;
+import fleet.Car;
+import fleet.Fleet;
+import fleet.FleetFactory;
+import fleet.FleetPackage;
+import fleet.Garage;
+import fleet.Person;
+import fleet.Tire;
+import fleet.VehicleInfo;
+
+/**
+ * Tests EStore
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class FleetAction extends AbstractTestAction {
+
+ public FleetAction() {
+ super(new EPackage[] { FleetPackage.eINSTANCE, TemporalPackage.eINSTANCE });
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final FleetFactory factory = FleetFactory.eINSTANCE;
+ final Garage garage = factory.createGarage();
+ garage.setName("Great Garage1");
+ final Address address = factory.createAddress();
+ address.setCity("doorn");
+ address.setCountry("NL");
+ address.setStreetName("Dutchlane");
+ address.setStreetNumber("25");
+ garage.setAddress(address);
+
+ final Fleet fl1 = factory.createFleet();
+ fl1.setId("fl1");
+ fl1.setServiceGarage(garage);
+ createData(fl1);
+
+ final Fleet fl2 = factory.createFleet();
+ fl2.setId("fl2");
+ fl2.setServiceGarage(garage);
+ createData(fl2);
+
+ store.beginTransaction();
+ store.store(garage);
+ store.store(fl1);
+ store.store(fl2);
+ store.commitTransaction();
+
+ }
+
+ private void createData(Fleet fleet) {
+ final FleetFactory factory = FleetFactory.eINSTANCE;
+
+ String indexStr = fleet.getId();
+ final Address address = factory.createAddress();
+ address.setCity(indexStr + "doorn");
+ address.setCountry(indexStr + "NL");
+ address.setStreetName(indexStr + "Dutchlane");
+ address.setStreetNumber(indexStr + "25");
+
+ final Person person = factory.createPerson();
+ person.setBirthAddress(address);
+ person.setEmployed(false);
+ person.setId(indexStr + "111-222-333-444");
+ person.setName(indexStr + "Piet Hein");
+
+ final Tire tire = factory.createTire();
+ tire.setMake("michellin");
+ tire.setModel("winter");
+ tire.setProfile(2);
+ tire.setRadius(2);
+ tire.setWidth(3);
+
+ final Car car = factory.createCar();
+ car.setId(indexStr + "01-ps-fb");
+ car.setBrand(indexStr + "volvo");
+ car.setColor(indexStr + "dark-metalic-blue");
+ car.setLength(5);
+ car.setMake(indexStr + "TD5");
+ car.setModel(indexStr + "v70");
+ car.setNumPassengers(7);
+ car.setNumTires(4);
+ car.setOwner(person);
+
+ assertTrue(person.eContainmentFeature() != null);
+
+ car.setPassengerName(indexStr + "p");
+ car.setPlate("01-ps-fb");
+ car.setYear(2004);
+ car.setTireSpec(tire);
+ fleet.getVehicles().add(car);
+
+ fleet.getServiceGarage().getVehicles().add(car);
+
+ VehicleInfo vInfo = factory.createVehicleInfo();
+ vInfo.setAcquisitionDate(new Date());
+ vInfo.setVehicle(car);
+ fleet.getVehicleInformation().add(vInfo);
+
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ForumAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ForumAction.java
new file mode 100755
index 000000000..3e1cec972
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ForumAction.java
@@ -0,0 +1,89 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ForumAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.forum.Forum;
+import org.eclipse.emf.teneo.samples.emf.sample.forum.ForumFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.forum.ForumPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.forum.Member;
+import org.eclipse.emf.teneo.samples.emf.sample.forum.Post;
+import org.eclipse.emf.teneo.samples.emf.sample.forum.Topic;
+import org.eclipse.emf.teneo.samples.emf.sample.forum.TopicCategory;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the forum example
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+ */
+public class ForumAction extends AbstractTestAction {
+ public ForumAction() {
+ super(ForumPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Test */
+ @Override
+ public void doAction(TestStore store) {
+ final ForumFactory factory = ForumFactory.eINSTANCE;
+
+ store.beginTransaction();
+ final Forum forum = factory.createForum();
+ forum.setTitle("my first forum1");
+
+ final Member member = factory.createMember();
+ member.setNickname("martin");
+
+ final Topic topic = factory.createTopic();
+ topic.setCategory(TopicCategory.ANNOUNCEMENT_LITERAL);
+ topic.setCreator(member);
+ topic.setTitle("my first topic!");
+
+ // is a two-way relation!
+ assertTrue((member.getCreated().get(0)).getTitle().compareTo("my first topic!") == 0);
+
+ final Post post = factory.createPost();
+ post.setTopic(topic);
+ post.setAuthor(member);
+ post.setComment("my post");
+
+ forum.getTopics().add(topic);
+ forum.getMembers().add(member);
+
+ store.store(forum);
+
+ for (int i = 0; i < 100; i++) {
+ final Member newMember = factory.createMember();
+ newMember.setNickname("martin" + i);
+ forum.getMembers().add(newMember);
+ store.store(newMember);
+ }
+ store.store(forum);
+ store.commitTransaction();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java
new file mode 100755
index 000000000..d9a3d378d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction.java
@@ -0,0 +1,92 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: GMFNotationAction.java,v 1.8 2009/06/08 07:44:05 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Properties;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests persisting of gmf diagram.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class GMFNotationAction extends AbstractTestAction {
+
+ /** Constructor */
+ public GMFNotationAction() {
+ throw new UnsupportedOperationException("Not supported");
+ // super(new EPackage[] { EcorePackage.eINSTANCE, NotationPackage.eINSTANCE, MindmapPackage.eINSTANCE });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ // props.setProperty(PersistenceOptions.USE_MAPPING_FILE, "true");
+ return props;
+ }
+
+ /** Reads the library model and persists it. */
+ @Override
+ public void doAction(TestStore store) {
+ final URL mindmapURL = getClass().getResource("default.mindmap");
+ final URI mindmapURI = URI.createURI(mindmapURL.toString());
+ final URL diagramURL = getClass().getResource("default.mmd");
+ final URI diagramURI = URI.createURI(diagramURL.toString());
+ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mmd", new XMIResourceFactoryImpl());
+ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("mindmap", new XMIResourceFactoryImpl());
+ final ResourceSet rs = new ResourceSetImpl();
+ final XMIResource mindmapResource = (XMIResource) rs.createResource(mindmapURI);
+ final XMIResource diagramResource = (XMIResource) rs.createResource(diagramURI);
+ try {
+ // default load options.
+ final HashMap<Object, Object> loadOptions = new HashMap<Object, Object>();
+ loadOptions.putAll(mindmapResource.getDefaultLoadOptions());
+ // loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE);
+ loadOptions.put(XMIResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE);
+ mindmapResource.load(loadOptions);
+ diagramResource.load(loadOptions);
+ store.beginTransaction();
+ for (Object element : mindmapResource.getContents()) {
+ store.store(element);
+ }
+ for (Object element : diagramResource.getContents()) {
+ store.store(element);
+ }
+ store.commitTransaction();
+ } catch (Exception e) {
+ throw new StoreTestException("Exception", e);
+ }
+
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction_old.persistence.xml b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction_old.persistence.xml
new file mode 100755
index 000000000..39e55580a
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/GMFNotationAction_old.persistence.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<persistence-mapping xmlns="http://www.eclipse.org/emft/teneo"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <epackage namespace-uri="http://www.eclipse.org/gmf/runtime/1.0.0/notation">
+
+ <eclass name="SortingStyle">
+ <property name="sortingKeys">
+ <transient/>
+ </property>
+ </eclass>
+
+ </epackage>
+
+</persistence-mapping> \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/InventoryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/InventoryAction.java
new file mode 100755
index 000000000..1abef38a6
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/InventoryAction.java
@@ -0,0 +1,92 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: InventoryAction.java,v 1.5 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.inv.InventoryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.inv.InventoryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.inv.PDeclaration;
+import org.eclipse.emf.teneo.samples.emf.sample.inv.PType;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class InventoryAction extends AbstractTestAction {
+ public InventoryAction() {
+ super(InventoryPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Creates a supplier, a product, relates then, saves and retrieves them again. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final InventoryFactory factory = InventoryFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+ PType pt = factory.createPType();
+ pt.setName("myname");
+
+ PType ptChild = factory.createPType();
+ ptChild.setName("child");
+ ptChild.setBase(pt);
+
+ PType ptOther = factory.createPType();
+ ptOther.setName("other");
+ pt.getSubNOTypes().add(ptOther);
+
+ PDeclaration pd = factory.createPDeclaration();
+ pd.setName("pd");
+ pt.getInfoReferences().add(pd);
+ PDeclaration pd1 = factory.createPDeclaration();
+ pd1.setName("pd1");
+ pt.getInfoReferences().add(pd1);
+ pt.getInfoReferences().add(pd);
+
+ store.store(pt);
+ store.store(ptChild);
+ store.store(ptOther);
+ store.commitTransaction();
+ }
+
+ store.checkNumber(PType.class, 3);
+
+ {
+ store.beginTransaction();
+ List list = store.query(PType.class, "name", "myname", 1);
+ PType pt = (PType) list.get(0);
+ assertEquals(((PType) pt.getSubNOTypes().get(0)).getName(), "other");
+ assertEquals(((PType) pt.getSubTypes().get(0)).getName(), "child");
+ pt.getInfoReferences().add(pt.getInfoReferences().get(0));
+ store.store(pt);
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/JuliaAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/JuliaAction.java
new file mode 100755
index 000000000..cb014dc15
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/JuliaAction.java
@@ -0,0 +1,60 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: JuliaAction.java,v 1.3 2008/04/11 03:21:48 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+import com.ibm.websphere.appserver.schemas._6._0.ibm.portal.test.TestPackage;
+
+/**
+ * Test bugzilla 199373
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class JuliaAction extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public JuliaAction() {
+ super(TestPackage.eINSTANCE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+// props.setProperty(PersistenceOptions.DISABLE_ECONTAINER_MAPPING, "true");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryAction.java
new file mode 100755
index 000000000..91679d355
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryAction.java
@@ -0,0 +1,345 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryAction.java,v 1.26 2010/11/12 13:35:58 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.26 $
+ */
+public class LibraryAction extends AbstractTestAction {
+
+ public LibraryAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ // public void setExtensions(ExtensionManager extensionManager) {
+ // extensionManager.registerExtension(EntityNameStrategy.class.getName(),
+ // ClassNameEntityNameStrategy.class.getName());
+ // }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY,
+ "READ_WRITE");
+ props.setProperty(PersistenceOptions.ALSO_MAP_AS_CLASS, "false");
+ props.setProperty(PersistenceOptions.DEFAULT_VARCHAR_LENGTH, "50");
+ props.setProperty(PersistenceOptions.DEFAULT_VARCHAR_LENGTH, "50");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // {
+ // store.beginTransaction();
+ //
+ // // Create a library.
+ // Library library = LibraryFactory.eINSTANCE.createLibrary();
+ // library.setName("My Library");
+ // // Make it persistent.
+ // store.store(library);
+ //
+ // // Create a writer...
+ // Writer writer = LibraryFactory.eINSTANCE.createWriter();
+ // writer.setName("JRR Tolkien");
+ //
+ // // ...and one of his books.
+ // Book book = LibraryFactory.eINSTANCE.createBook();
+ // book.setAuthor(writer);
+ // book.setPages(305);
+ // book.setTitle("The Hobbit");
+ // book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ //
+ // // Add the Writer and Book to the Library. They are made
+ // // persistent automatically because the Library is already
+ // // persistent.
+ // library.getWriters().add(writer);
+ // library.getBooks().add(book);
+ // store.commitTransaction();
+ // }
+
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+
+ book.setAuthor(writer);
+ book.setPages(5);
+ book.setTitle("The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(5);
+ book2.setTitle("The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.setName("Science Fiction Library");
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+ store.store(library);
+
+ store.commitTransaction();
+ assertEquals(2, writer.getBooks().size());
+ }
+
+ // walk through the structure starting from the library
+ {
+ store.beginTransaction();
+ Library lib = (Library) store.query(Library.class, "name",
+ "Science Fiction Library", 1).get(0);
+
+ testLazySize(lib.getWriters());
+ testLazySize(lib.getBooks());
+
+ assertTrue((lib.getWriters().get(0)).getName().compareTo(
+ "JRR Tolkien") == 0);
+ testLazySize(lib.getWriters().get(0).getBooks());
+
+ // final Object[] eobjs =
+ // store.getCrossReferencers((EObject)lib.getWriters().get(0),
+ // false);
+
+ // these two books should be the same as this book is the first in
+ // the writers
+ // collection
+ // and in the library collection
+ Book wBook = (lib.getWriters().get(0)).getBooks().get(0);
+ Book lBook = lib.getBooks().get(0);
+
+ // check container
+ assertTrue(lBook.eContainer() == lib);
+
+ assertTrue(wBook.getTitle().compareTo(lBook.getTitle()) == 0);
+ assertTrue(wBook.getPages() == lBook.getPages());
+ assertTrue(wBook.getCategory() instanceof BookCategory);
+ assertTrue(wBook.getCategory() == BookCategory.SCIENCE_FICTION_LITERAL);
+ store.commitTransaction();
+ }
+
+ // check container relations
+ if (true) {
+ store.beginTransaction();
+
+ final Writer writ = store.getObjects(Writer.class).get(0);
+
+ // store.refresh(writ);
+
+ // test notifications of the elist
+ // disabled this test as the elist notifications have been disabled
+ // WriterAdapter writerAdapter = new WriterAdapter();
+ // writ.eAdapters().add(writerAdapter);
+ // assertEquals(2, writ.getBooks().size()); // this should not
+ // trigger the adapter to be
+ // called
+ // assertEquals(1, writerAdapter.getCountNotifications());
+
+ checkContainerAfterWriterRetrieve(store, writ);
+
+ Library lib = (Library) store.getCrossReferencers(writ, true)[0];
+ checkContainerAfterLibraryRetrieve(store, writ);
+ checkDetachCopy(store, writ);
+
+ // now set the container of the writer
+ assertTrue("The container of the writer should be set!",
+ store.setContainer(writ));
+
+ assertEquals(LibraryPackage.eINSTANCE.getLibrary_Writers()
+ .getFeatureID(), writ.eContainingFeature().getFeatureID());
+
+ assertTrue(
+ "The container of the writer should be equal to the earlier retrieved Library",
+ lib == writ.eContainer());
+
+ final Object[] eobjs = store.getCrossReferencers(writ, false);
+ assertEquals(3, eobjs.length);
+ for (final Object obj : eobjs) {
+ if (obj instanceof Library) {
+ assertTrue(obj == lib);
+ } else {
+ assertTrue(((Book) obj).getAuthor() == writ);
+ assertTrue(lib.getBooks().contains(obj));
+ }
+ }
+
+ final Book bk = store.getObjects(Book.class).get(0);
+ assertTrue(bk.eContainer() == lib);
+
+ // check if the containing feature is also set correctly
+ assertTrue(bk.eContainingFeature() == LibraryPackage.eINSTANCE
+ .getLibrary_Books());
+
+ assertTrue(lib.getBooks().contains(bk));
+
+ store.refresh(lib);
+
+ store.commitTransaction();
+ }
+
+ // test https://bugs.eclipse.org/bugs/show_bug.cgi?id=297627
+ checkIndexName(store);
+
+ dumpPAModel(store);
+ checkTeneoSQLNameStrategy();
+ testMerge(store);
+ }
+
+ protected void testMerge(TestStore store) {
+
+ }
+
+ protected void testLazySize(List<?> list) {
+
+ }
+
+ /** Reads objects in multiple sessions and checks that they are unequal */
+ @SuppressWarnings("unchecked")
+ protected void checkUseCache(TestStore store) {
+ // read the writers in the cache
+ store.refresh();
+ store.beginTransaction();
+ final Writer writer = store.getObject(Writer.class);
+ assertTrue(writer != null);
+ store.commitTransaction();
+ store.refresh();
+ store.beginTransaction();
+ final List books1 = new ArrayList(store.getObjects(Book.class));
+ store.commitTransaction();
+ store.refresh();
+ store.beginTransaction();
+ final List books2 = new ArrayList(store.getObjects(Book.class));
+ assertTrue(books1.size() == books2.size());
+ store.commitTransaction();
+ for (int i = 0; i < books1.size(); i++) {
+ final Book bk1 = (Book) books1.get(i);
+ final Book bk2 = (Book) books2.get(i);
+ assertEquals(bk1.getTitle(), bk2.getTitle());
+ assertTrue(bk1 != bk2);
+ assertTrue(bk1.getAuthor() != bk2.getAuthor());
+ }
+ }
+
+ // check detachcopy for jpox
+ protected void checkDetachCopy(TestStore store, Writer writ) {
+ }
+
+ protected void checkContainerAfterLibraryRetrieve(TestStore store,
+ final Writer writ) {
+ // TODO specialize for Hibernate/JPOX, was:
+ // if (store instanceof JPOXTestStore)
+ // {
+ // assertTrue("Container of writer is not yet set now, because of lazy
+ // loading of container
+ // relations",
+ // writ.eContainer() == null);
+ // }
+ }
+
+ protected void checkContainerAfterWriterRetrieve(TestStore store,
+ final Writer writ) {
+ // TODO specialize for Hibernate/JPOX, was:
+ // if (store instanceof HibernateTestStore)
+ // {
+ // assertTrue(writ.eContainer() != null);
+ // assertTrue(writ.eContainer() instanceof Library);
+ // }
+ }
+
+ /**
+ * @return Returns <code>true</code> the given value indeed encodes a list
+ */
+ protected boolean listValueOfCorrectType(Object value) {
+ // TODO specialize hibernate/jpox, was
+ // return (value instanceof PersistableEList || value instanceof
+ // org.eclipse.emf.teneo.jpox.emf.elist.EListWrapper)
+ return true;
+ }
+
+ /** Dump the annotated model to standard output */
+ protected void dumpPAModel(TestStore testStore) {
+ }
+
+ protected void checkTeneoSQLNameStrategy() {
+ }
+
+ protected void checkIndexName(TestStore store) {
+ }
+
+ // /** Small adapter test
+ // private class WriterAdapter extends AdapterImpl {
+ // /** Counts the number of changes */
+ // private int countNotifications = 0;
+ //
+ // /**
+ // * Returns <code>false</code>
+ // *
+ // * @param type
+ // * the type.
+ // * @return <code>false</code>
+ // */
+ // public boolean isAdapterForType(Object type) {
+ // return type instanceof Writer;
+ // }
+ //
+ // /**
+ // * Does nothing; clients may override so that it does something.
+ // */
+ // public void notifyChanged(Notification msg) {
+ // assertTrue("The new value is of type: " +
+ // msg.getNewValue().getClass().getName(),
+ // listValueOfCorrectType(msg.getNewValue()));
+ //
+ // // must be a load event
+ // assertTrue("Eventtype is not load notification but: " +
+ // msg.getEventType(),
+ // msg.getEventType() == AnnotationUtil.ELIST_LOAD_NOTIFICATION);
+ //
+ // countNotifications++;
+ // }
+ //
+ // /** Returns the number of notifications */
+ // public int getCountNotifications() {
+ // return countNotifications;
+ // }
+ // }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryCheckNameAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryCheckNameAction.java
new file mode 100755
index 000000000..7a6b5a0d3
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryCheckNameAction.java
@@ -0,0 +1,59 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryCheckNameAction.java,v 1.3 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class LibraryCheckNameAction extends LibraryColLengthAction {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#setExtensions(org.eclipse.emf.teneo.extension.ExtensionManager)
+ */
+ @Override
+ public void setExtensions(ExtensionManager extensionManager) {
+ // purposely empty, do not remove
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.put(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH, "8");
+ props.put(PersistenceOptions.ID_COLUMN_NAME, "myID");
+ return props;
+ }
+
+ @Override
+ protected String getTestQuery() {
+ return "SELECT * FROM BOOK WHERE lb_bk_d<>0 AND lb_bk_dx>0 AND wr_bk_dx>0".toLowerCase();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryColLengthAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryColLengthAction.java
new file mode 100755
index 000000000..970038ab6
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryColLengthAction.java
@@ -0,0 +1,149 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryColLengthAction.java,v 1.9 2009/04/03 06:15:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+import org.eclipse.emf.teneo.mapping.strategy.SQLNameStrategy;
+import org.eclipse.emf.teneo.mapping.strategy.impl.ClassicSQLNameStrategy;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.9 $
+ */
+public class LibraryColLengthAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryColLengthAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.emf.teneo.test.AbstractTestAction#setExtensions(org.eclipse.emf.teneo.extension.ExtensionManager)
+ */
+ @Override
+ public void setExtensions(ExtensionManager extensionManager) {
+ extensionManager.registerExtension(SQLNameStrategy.class.getName(), ClassicSQLNameStrategy.class.getName());
+ extensionManager.registerExtension("org.eclipse.emf.teneo.hibernate.mapper.MappingContext",
+ "org.eclipse.emf.teneo.hibernate.mapper.classic.ClassicMappingContext");
+ super.setExtensions(extensionManager);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.put(PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH, "5");
+ props.put(PersistenceOptions.ID_COLUMN_NAME, "myID");
+ props.put(PersistenceOptions.ID_FEATURE_AS_PRIMARY_KEY, "false");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(5);
+ book.setTitle("The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(5);
+ book2.setTitle("The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.setName("Science Fiction Library");
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+ store.store(library);
+
+ store.commitTransaction();
+ assertEquals(2, writer.getBooks().size());
+ }
+
+ if (true) {
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery(getTestQuery());
+ assertTrue(rs.next());
+ } catch (SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ stmt = null;
+ }
+
+ if (conn != null) {
+ conn.close();
+ conn = null;
+ }
+ } catch (SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ }
+ }
+ }
+ }
+
+ protected String getTestQuery() {
+ return "SELECT * FROM BOOK WHERE BO_ID<>0 AND L_IDX>0 AND W_IDX>0".toLowerCase();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDBothAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDBothAction.java
new file mode 100644
index 000000000..a57497256
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDBothAction.java
@@ -0,0 +1,38 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryContainerFeatureIDBothAction.java,v 1.1 2009/03/15 14:49:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+public class LibraryContainerFeatureIDBothAction extends LibraryAction {
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(
+ PersistenceOptions.ECONTAINER_FEATURE_PERSISTENCE_STRATEGY,
+ "both");
+ return props;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDFeatureIDAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDFeatureIDAction.java
new file mode 100644
index 000000000..e51c22e1a
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryContainerFeatureIDFeatureIDAction.java
@@ -0,0 +1,39 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryContainerFeatureIDFeatureIDAction.java,v 1.1 2009/03/15 14:49:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.1 $
+ */
+public class LibraryContainerFeatureIDFeatureIDAction extends LibraryAction {
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(
+ PersistenceOptions.ECONTAINER_FEATURE_PERSISTENCE_STRATEGY,
+ "featureid");
+ return props;
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryFKAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryFKAction.java
new file mode 100755
index 000000000..b1c9b1620
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryFKAction.java
@@ -0,0 +1,37 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryFKAction.java,v 1.2 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+
+/**
+ * Tests foreign key
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class LibraryFKAction extends LibraryAction {
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = super.getExtraConfigurationProperties();
+ props.setProperty(PersistenceOptions.SET_FOREIGN_KEY_NAME, "true");
+ return props;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryGlobalEagerAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryGlobalEagerAction.java
new file mode 100755
index 000000000..679576b7b
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryGlobalEagerAction.java
@@ -0,0 +1,221 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryGlobalEagerAction.java,v 1.9 2009/04/03 06:15:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.mapping.elist.PersistableEList;
+import org.eclipse.emf.teneo.resource.StoreResource;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests setting of eager loading of containment at global level
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.9 $
+ */
+public class LibraryGlobalEagerAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryGlobalEagerAction() {
+ super(LibraryPackage.eINSTANCE);
+
+ }
+
+ /**
+ * Can be overridden by subclass returns properties which control the or layer. Such as setting of eager loading.
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.put(PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, "true");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR_Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship_of_the_Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(500);
+ book2.setTitle("The_Hobbit");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ // sorry george making a mistake here, will correct this below
+ final Book book3 = factory.createBook();
+ book3.setAuthor(writer);
+ book3.setPages(500);
+ book3.setTitle("nineteeneightyfour");
+ book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.setName("Science_Fiction");
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getBooks().add(book3);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ res.save(null);
+ res.unload();
+ }
+
+ // test settrackingmodification before load
+ {
+ Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.setTrackingModification(true);
+ res.load(null);
+ testResolving(res);
+ }
+
+ // test settrackingmodification after load
+ {
+ Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.load(null);
+ res.setTrackingModification(true);
+ testResolving(res);
+ }
+
+ // test with resolving
+ {
+ Resource res = store.getResource();
+ // default is false
+ res.load(null);
+ res.setTrackingModification(true);
+ testResolving(res);
+ }
+
+ // simple test without setTrackingModification
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+ PersistableEList writers = (PersistableEList) lib.getWriters();
+ assertTrue("Elist should be loaded", writers.isLoaded());
+ }
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+
+ /** Check adapters and lazy loading of nonresolving */
+ @SuppressWarnings("unchecked")
+ private void testResolving(Resource res) {
+ final LibraryAdapter libraryAdapter = new LibraryAdapter();
+ res.eAdapters().add(libraryAdapter);
+
+ Library lib = (Library) res.getContents().get(0);
+ PersistableEList writers = (PersistableEList) lib.getWriters();
+ PersistableEList books = (PersistableEList) lib.getBooks();
+ assertTrue("Elist is not loaded", writers.isLoaded());
+ assertTrue("Elist is not loaded", books.isLoaded());
+ assertTrue("BasicIterator should have next true", books.basicIterator().hasNext());
+ assertTrue("BasicListIterator should have next true", books.basicListIterator().hasNext());
+ assertTrue("BasicIterator should have next true", writers.basicIterator().hasNext());
+ assertTrue("BasicListIterator should have next true", writers.basicListIterator().hasNext());
+
+ lib.setName("test" + lib.getName());
+
+ // get the first book and change it
+ final Book book = (Book) books.get(0);
+ book.setTitle("test" + book.getTitle());
+
+ assertEquals(2, libraryAdapter.getCountNotifications());
+
+ boolean fndLibrary = false;
+ boolean fndBook = false;
+ for (EObject element : ((StoreResource) res).getModifiedEObjects()) {
+ fndLibrary = fndLibrary || element == lib;
+ fndBook = fndBook || element == book;
+ }
+ assertTrue("Library should be a modified object", fndLibrary);
+ assertTrue("Book should be a modified object", fndBook);
+ assertEquals(2, ((StoreResource) res).getModifiedEObjects().size());
+ res.unload();
+ }
+
+ /** Small adapter test */
+ private class LibraryAdapter extends AdapterImpl {
+ /** Counts the number of changes */
+ private int countNotifications = 0;
+
+ /**
+ * Returns <code>false</code>
+ *
+ * @param type
+ * the type.
+ * @return <code>false</code>
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type instanceof Writer;
+ }
+
+ /**
+ * Does nothing; clients may override so that it does something.
+ */
+ @Override
+ public void notifyChanged(Notification msg) {
+ countNotifications++;
+ }
+
+ /** Returns the number of notifications */
+ public int getCountNotifications() {
+ return countNotifications;
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java
new file mode 100755
index 000000000..2d744b3fa
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryJoinTableNamingAction.java
@@ -0,0 +1,123 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryJoinTableNamingAction.java,v 1.5 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class LibraryJoinTableNamingAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryJoinTableNamingAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE");
+ props.setProperty(PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS, "true");
+ props.setProperty(PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY, "unique");
+ props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
+ props.setProperty(PersistenceOptions.SQL_CASE_STRATEGY, "uppercase");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+
+ book.setAuthor(writer);
+ book.setPages(5);
+ book.setTitle("The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(5);
+ book2.setTitle("The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.setName("Science Fiction Library");
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+ store.store(library);
+
+ store.commitTransaction();
+ assertEquals(2, writer.getBooks().size());
+ }
+
+ if (true) {
+ Connection conn = null;
+ Statement stmt = null;
+ try {
+ conn = store.getConnection();
+ stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT * FROM WRITER_BOOKS");
+ assertTrue(rs.next());
+ } catch (SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (SQLException s) {
+ throw new StoreTestException("SQL Exception", s);
+ }
+ }
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryLargeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryLargeAction.java
new file mode 100755
index 000000000..f5a7500b9
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryLargeAction.java
@@ -0,0 +1,161 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryLargeAction.java,v 1.3 2008/10/12 11:24:40 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd using a larger dataset.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class LibraryLargeAction extends AbstractTestAction {
+
+ private static final int BK_CNT = 1000;
+ private static final int WRITER_CNT = 100;
+ private static final int LIB_CNT = 1;
+ private static final int NUM_OF_TRANS = 3;
+
+ private static final int NUM_WRITER_TRANSACTION = LIB_CNT * WRITER_CNT;
+ private static final int NUM_BOOK_TRANSACTION = NUM_WRITER_TRANSACTION * BK_CNT;
+
+ public LibraryLargeAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+// props.setProperty(PersistenceOptions.MAP_ALL_LISTS_AS_IDBAG, "true");
+ props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
+ return props;
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ {
+ long t = System.currentTimeMillis();
+ for (int j = 0; j < NUM_OF_TRANS; j++) {
+ store.beginTransaction();
+ for (int i = 0; i < LIB_CNT; i++) {
+ store.store(createLibrary(i + " Number " + j));
+ }
+ System.err.println("before commit");
+ long commitTime = System.currentTimeMillis();
+ store.commitTransaction();
+ System.err.println("Transaction " + (j + 1) + " inserted library(#" + LIB_CNT + ") and Writer(#" +
+ NUM_WRITER_TRANSACTION + ") and Book(#" + NUM_BOOK_TRANSACTION + ") in " +
+ ((System.currentTimeMillis() - t) / 1000) + " seconds of which the commit took " +
+ ((System.currentTimeMillis() - commitTime) / 1000));
+ t = System.currentTimeMillis();
+ }
+ }
+
+ // load each writer and add a book
+ {
+ long t = System.currentTimeMillis();
+ store.beginTransaction();
+ final List<?> ls = store.getObjects(Library.class);
+ for (Object o : ls) {
+ final Library l = (Library) o;
+ System.err.println(l.getName());
+ for (Writer w : l.getWriters()) {
+ // removed the book in the middle
+ final Book removeBk = w.getBooks().remove(BK_CNT / 2);
+ l.getBooks().remove(removeBk);
+
+ // and add a book in the middle
+ final Book bk = LibraryFactory.eINSTANCE.createBook();
+ bk.setPages(BK_CNT);
+ bk.setTitle(w.getName() + "bk");
+ bk.setCategory(BookCategory.MYSTERY_LITERAL);
+ bk.setAuthor(w);
+
+ l.getBooks().add(BK_CNT / 2, bk);
+ }
+ }
+ store.commitTransaction();
+ System.err.println("Time to remove and add " + (LIB_CNT * WRITER_CNT) + " books: " +
+ ((System.currentTimeMillis() - t) / 1000) + " seconds ");
+ }
+ }
+
+ private Library createLibrary(String prefix) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+ final Library l = factory.createLibrary();
+ l.setName(prefix + " Library");
+ for (int i = 0; i < WRITER_CNT; i++) {
+ final Writer w = factory.createWriter();
+ w.setName(prefix + " Writer " + i);
+ l.getWriters().add(w);
+ createBooks(l, w, prefix);
+ }
+ return l;
+ }
+
+ private void createBooks(Library l, Writer w, String prefix) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+ for (int i = 0; i < BK_CNT; i++) {
+ final Book bk = factory.createBook();
+ bk.setTitle(prefix + " Book " + i);
+ bk.setAuthor(w);
+ bk.setPages(i);
+ bk.setCategory(BookCategory.BIOGRAPHY_LITERAL);
+ l.getBooks().add(bk);
+ }
+ }
+
+ /** Reads objects in multiple sessions and checks that they are unequal */
+ @SuppressWarnings("unchecked")
+ protected void checkUseCache(TestStore store) {
+ // read the writers in the cache
+ store.refresh();
+ store.beginTransaction();
+ final Writer writer = store.getObject(Writer.class);
+ assertTrue(writer != null);
+ store.commitTransaction();
+ store.refresh();
+ store.beginTransaction();
+ final List books1 = new ArrayList(store.getObjects(Book.class));
+ store.commitTransaction();
+ store.refresh();
+ store.beginTransaction();
+ final List books2 = new ArrayList(store.getObjects(Book.class));
+ assertTrue(books1.size() == books2.size());
+ store.commitTransaction();
+ for (int i = 0; i < books1.size(); i++) {
+ final Book bk1 = (Book) books1.get(i);
+ final Book bk2 = (Book) books2.get(i);
+ assertEquals(bk1.getTitle(), bk2.getTitle());
+ assertTrue(bk1 != bk2);
+ assertTrue(bk1.getAuthor() != bk2.getAuthor());
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryListAsBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryListAsBagAction.java
new file mode 100755
index 000000000..8ebb2c7c0
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryListAsBagAction.java
@@ -0,0 +1,105 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryListAsBagAction.java,v 1.5 2009/04/03 06:15:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+public class LibraryListAsBagAction extends AbstractTestAction {
+
+ public LibraryListAsBagAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.ALWAYS_MAP_LIST_AS_BAG, "true");
+ return props;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Writer writer = factory.createWriter();
+ writer.setName("writer");
+
+ final Book book = factory.createBook();
+
+ book.setAuthor(writer);
+ book.setPages(1);
+ book.setTitle("The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(2);
+ book2.setTitle("The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.setName("Science Fiction Library");
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+ store.store(library);
+
+ store.commitTransaction();
+ }
+
+ // move the books arround
+ int page0 = 0;
+ int page1 = 1;
+ {
+ store.beginTransaction();
+ final Library lib = store.getObject(Library.class);
+ page0 = lib.getBooks().get(0).getPages();
+ page1 = lib.getBooks().get(1).getPages();
+ lib.getBooks().move(0, 1); // moved second book to first location
+ store.commitTransaction();
+ }
+
+ // check if it succeeded, should not
+ {
+ store.beginTransaction();
+ final Library lib = store.getObject(Library.class);
+ assertEquals(page0, (lib.getBooks().get(0)).getPages());
+ assertEquals(page1, (lib.getBooks().get(1)).getPages());
+ store.commitTransaction();
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNonResolvingAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNonResolvingAction.java
new file mode 100755
index 000000000..c63a8f23d
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNonResolvingAction.java
@@ -0,0 +1,231 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryNonResolvingAction.java,v 1.11 2009/04/03 06:15:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.mapping.elist.PersistableEList;
+import org.eclipse.emf.teneo.resource.StoreResource;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests non-resolving behavior of containment references. Main test is that setTrackingModification does not result in
+ * loaded containment elists.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.11 $
+ */
+public class LibraryNonResolvingAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryNonResolvingAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR_Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship_of_the_Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(500);
+ book2.setTitle("The_Hobbit");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ // sorry george making a mistake here, will correct this below
+ final Book book3 = factory.createBook();
+ book3.setAuthor(writer);
+ book3.setPages(500);
+ book3.setTitle("nineteeneightyfour");
+ book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.setName("Science_Fiction");
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getBooks().add(book3);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ res.save(null);
+ res.unload();
+ }
+
+ // test settrackingmodification before load
+ {
+ Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.setTrackingModification(true);
+ res.load(null);
+ testResolving(res);
+ }
+
+ // test settrackingmodification before load
+ {
+ Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.load(null);
+ res.setTrackingModification(true);
+ testResolving(res);
+ }
+ {
+ Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.load(null);
+ Library lib = (Library) res.getContents().get(0);
+ lib.setName(lib.getName() + "_");
+ res.save(Collections.EMPTY_MAP);
+ // testResolving(res);
+ }
+
+ {
+ Resource res = store.getResource();
+ // default is false
+ // ((StoreResource)res).setAutoResolve(false);
+ res.setTrackingModification(true);
+ res.load(null);
+ testResolving(res);
+ }
+
+ // test with resolving
+ {
+ Resource res = store.getResource();
+ // default is false
+ res.load(null);
+ res.setTrackingModification(true);
+ testResolving(res);
+ }
+
+ // simple test without setTrackingModification
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+ PersistableEList writers = (PersistableEList) lib.getWriters();
+ assertFalse("Elist should not be loaded", writers.isLoaded());
+ }
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+
+ /** Check adapters and lazy loading of nonresolving */
+ @SuppressWarnings("unchecked")
+ private void testResolving(Resource res) {
+ final LibraryAdapter libraryAdapter = new LibraryAdapter();
+ res.eAdapters().add(libraryAdapter);
+
+ Library lib = (Library) res.getContents().get(0);
+ PersistableEList writers = (PersistableEList) lib.getWriters();
+ PersistableEList books = (PersistableEList) lib.getBooks();
+
+ assertFalse("Elist should not be loaded", writers.isLoaded());
+ assertFalse("Elist should not be loaded", books.isLoaded());
+ assertFalse("BasicIterator should have next false", books.basicIterator().hasNext());
+ assertFalse("BasicListIterator should have next false", books.basicListIterator().hasNext());
+ assertFalse("BasicIterator should have next false", writers.basicIterator().hasNext());
+ assertFalse("BasicListIterator should have next false", writers.basicListIterator().hasNext());
+
+ lib.setName("test" + lib.getName());
+
+ // get the first book and change it
+ final Book book = (Book) books.get(0);
+ book.setTitle("test" + book.getTitle());
+
+ assertEquals(2, libraryAdapter.getCountNotifications());
+
+ boolean fndLibrary = false;
+ boolean fndBook = false;
+ for (EObject element : ((StoreResource) res).getModifiedEObjects()) {
+ fndLibrary = fndLibrary || element == lib;
+ fndBook = fndBook || element == book;
+ }
+ assertTrue("Library should be a modified object", fndLibrary);
+ assertTrue("Book should be a modified object", fndBook);
+ assertEquals(2, ((StoreResource) res).getModifiedEObjects().size());
+
+ res.unload();
+ }
+
+ /** Small adapter test */
+ private class LibraryAdapter extends AdapterImpl {
+ /** Counts the number of changes */
+ private int countNotifications = 0;
+
+ /**
+ * Returns <code>false</code>
+ *
+ * @param type
+ * the type.
+ * @return <code>false</code>
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type instanceof Writer;
+ }
+
+ /**
+ * Does nothing; clients may override so that it does something.
+ */
+ @Override
+ public void notifyChanged(Notification msg) {
+ countNotifications++;
+ }
+
+ /** Returns the number of notifications */
+ public int getCountNotifications() {
+ return countNotifications;
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNotifyingTestAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNotifyingTestAction.java
new file mode 100644
index 000000000..133721ee7
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryNotifyingTestAction.java
@@ -0,0 +1,205 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryNotifyingTestAction.java,v 1.2 2009/03/15 23:26:03 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+import org.eclipse.emf.teneo.type.PersistentStoreAdapter;
+import org.eclipse.emf.teneo.util.StoreUtil;
+
+/**
+ * Tests the library example of emf/xsd and specifically the notifications when
+ * objects are updated. Tests the new PersistentStoreAdapter which keeps the
+ * persistentList in the adapter.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class LibraryNotifyingTestAction extends AbstractTestAction {
+ public LibraryNotifyingTestAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(5);
+ book.setTitle("The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(5);
+ book2.setTitle("The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+
+ // set name
+ library.setName("Science Fiction Library");
+
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+
+ final EList<?> libraryBooks = library.getBooks();
+ final EList<?> libraryWriters = library.getWriters();
+ final EList<?> writerBooks = writer.getBooks();
+
+ store.store(library);
+ store.commitTransaction();
+
+ store.beginTransaction();
+
+ library.getBooks().clear();
+
+ // add action
+ library.getBooks().add(book);
+
+ // remove action
+ library.getBooks().remove(book);
+
+ // add action
+ library.getBooks().add(book2);
+
+ // set action
+ library.getBooks().set(0, book);
+
+ // add again
+ library.getBooks().add(book2);
+
+ // move it
+ library.getBooks().move(0, 1);
+
+ library.getBooks().move(1, book2);
+
+ // count them
+ assertTrue(library.getBooks().size() == 2);
+
+ // clear it all
+ library.getBooks().clear();
+
+ final List<Book> books = new ArrayList<Book>();
+ books.add(book);
+ books.add(book2);
+ library.getBooks().addAll(books);
+
+ library.getBooks().removeAll(books);
+
+ library.getWriters().add(writer);
+
+ store.commitTransaction();
+ store.beginTransaction();
+ {
+ assertTrue(libraryBooks == library.getBooks());
+ assertTrue(libraryWriters == library.getWriters());
+ assertTrue(writerBooks == writer.getBooks());
+ PersistentStoreAdapter libraryAdapter = StoreUtil
+ .getPersistentStoreAdapter(library);
+ final List<?> persistentLibraryBooks = (List<?>) libraryAdapter
+ .getStoreCollection(LibraryPackage.eINSTANCE
+ .getLibrary_Books());
+ final List<?> persistentLibraryWriters = (List<?>) libraryAdapter
+ .getStoreCollection(LibraryPackage.eINSTANCE
+ .getLibrary_Writers());
+ PersistentStoreAdapter writerAdapter = StoreUtil
+ .getPersistentStoreAdapter(writer);
+ final List<?> persistentWriterBooks = (List<?>) writerAdapter
+ .getStoreCollection(LibraryPackage.eINSTANCE
+ .getWriter_Books());
+ checkEqualList(persistentLibraryWriters, libraryWriters);
+ checkEqualList(persistentLibraryBooks, libraryBooks);
+ checkEqualList(persistentWriterBooks, writerBooks);
+ }
+ store.commitTransaction();
+ {
+ assertTrue(libraryBooks == library.getBooks());
+ assertTrue(libraryWriters == library.getWriters());
+ assertTrue(writerBooks == writer.getBooks());
+ PersistentStoreAdapter libraryAdapter = StoreUtil
+ .getPersistentStoreAdapter(library);
+ final List<?> persistentLibraryBooks = (List<?>) libraryAdapter
+ .getStoreCollection(LibraryPackage.eINSTANCE
+ .getLibrary_Books());
+ final List<?> persistentLibraryWriters = (List<?>) libraryAdapter
+ .getStoreCollection(LibraryPackage.eINSTANCE
+ .getLibrary_Writers());
+ PersistentStoreAdapter writerAdapter = StoreUtil
+ .getPersistentStoreAdapter(writer);
+ final List<?> persistentWriterBooks = (List<?>) writerAdapter
+ .getStoreCollection(LibraryPackage.eINSTANCE
+ .getWriter_Books());
+ checkEqualList(persistentLibraryWriters, libraryWriters);
+ checkEqualList(persistentLibraryBooks, libraryBooks);
+ checkEqualList(persistentWriterBooks, writerBooks);
+ }
+ }
+ {
+ store.beginTransaction();
+ final Library lib = store.getObject(Library.class);
+ final List<?> libBooks = lib.getBooks();
+ final List<?> libWriters = lib.getWriters();
+ lib.setName(lib.getName() + "0");
+ assertEquals(2, lib.getBooks().size());
+
+ assertTrue(libBooks == lib.getBooks());
+ assertTrue(libWriters == lib.getWriters());
+
+ final Book book = factory.createBook();
+ book.setAuthor(lib.getWriters().get(0));
+ book.setPages(5);
+ book.setTitle("The Hobbit AGAIN");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ lib.getBooks().add(book);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ final Library lib = store.getObject(Library.class);
+ assertEquals(3, lib.getBooks().size());
+ store.commitTransaction();
+ }
+ }
+
+ private void checkEqualList(List<?> l1, List<?> l2) {
+ assertTrue(l1 != l2);
+ assertTrue(l1.size() == l2.size());
+ for (Object o : l1) {
+ assertEquals(l1.indexOf(o), l2.indexOf(o));
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryQualifyActionHB.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryQualifyActionHB.java
new file mode 100755
index 000000000..b1673ad65
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryQualifyActionHB.java
@@ -0,0 +1,102 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryQualifyActionHB.java,v 1.7 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import org.eclipse.emf.teneo.extension.ExtensionManager;
+import org.eclipse.emf.teneo.mapping.strategy.EntityNameStrategy;
+import org.eclipse.emf.teneo.mapping.strategy.impl.QualifyingEntityNameStrategy;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests setting of qualified enames
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.7 $
+ */
+public class LibraryQualifyActionHB extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryQualifyActionHB() {
+ super(LibraryPackage.eINSTANCE);
+
+ }
+
+ /** Add extensions if you want */
+ @Override
+ public void setExtensions(ExtensionManager extensionManager) {
+ extensionManager.registerExtension(EntityNameStrategy.class.getName(), QualifyingEntityNameStrategy.class
+ .getName());
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(5);
+ book.setTitle("The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(5);
+ book2.setTitle("The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.setName("Science Fiction Library");
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+ store.store(library);
+
+ store.commitTransaction();
+ assertEquals(2, writer.getBooks().size());
+ }
+
+ // now test some qualified queries
+ {
+ store.beginTransaction();
+ Library lib = (Library) store.query("select l from " + LibraryPackage.eNS_PREFIX + ".Library l").get(0);
+ assertTrue(lib != null);
+ Writer writ = (Writer) store.query("select w from " + LibraryPackage.eNS_PREFIX + ".Writer w").get(0);
+ assertTrue(writ != null);
+ Book bk = (Book) store.query("select b from " + LibraryPackage.eNS_PREFIX + ".Book b").get(0);
+ assertTrue(bk != null);
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java
new file mode 100755
index 000000000..79d086acc
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceAction.java
@@ -0,0 +1,277 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryResourceAction.java,v 1.20 2010/02/07 23:12:02 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.resource.StoreResource;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd using a resource. Actually tests bidirectional references using resources. Most
+ * other aspects of resources are handled in the Catalog example.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.20 $
+ */
+public class LibraryResourceAction extends AbstractTestAction {
+ public LibraryResourceAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ Resource res = getResource(store);
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR_Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship_of_the_Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(500);
+ book2.setTitle("The_Hobbit");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ // sorry george making a mistake here, will correct this below
+ final Book book3 = factory.createBook();
+ book3.setAuthor(writer);
+ book3.setPages(500);
+ book3.setTitle("nineteeneightyfour");
+ book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ final Library library = factory.createLibrary();
+ library.setName("Science_Fiction");
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getBooks().add(book3);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ res.save(null);
+ res.save(null);
+ res.unload();
+ assertTrue(res.getContents().size() == 0);
+ assertTrue(library.getBooks().size() > 0);
+ assertTrue(library.getWriters().size() > 0);
+ }
+
+ // walk through the structure starting from the library
+ String libURI = null;
+ String writerURI = null;
+ {
+ Resource res = getResource(store);
+ // res.setTrackingModification(true);
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+
+ Writer tolkien = lib.getWriters().get(0);
+
+ libURI = res.getURIFragment(lib);
+ writerURI = res.getURIFragment(tolkien);
+
+ /*
+ * final Object[] obj = ((StoreResource)res).getCrossReferencers(tolkien); for (int i = 0; i <
+ * obj.length; i++) {
+ */
+
+ /*
+ * assertEquals(3, tolkien.getBooks().size());
+ *
+ * assertEquals(0 , tolkien.getName().compareTo("JRR Tolkien")); Book wBook =
+ * (Book)tolkien.getBooks().get(0); Book lBook = (Book)lib.getBooks().get(0);
+ * assertTrue("Book is contained in the library", wBook.eContainer() == lib);
+ * assertTrue("Book is contained in the library", lBook.eContainer() == lib);
+ *
+ * assertTrue(lBook.getAuthor() == tolkien); assertTrue(tolkien.getBooks().contains(lBook));
+ * assertTrue(tolkien.getBooks().contains(wBook)); // ordering is the same
+ * assertTrue(wBook.getTitle().compareTo(lBook.getTitle()) == 0); assertTrue(wBook.getPages() ==
+ * lBook.getPages()); assertTrue(wBook.getCategory() instanceof BookCategory);
+ * assertTrue(wBook.getCategory() == BookCategory.SCIENCE_FICTION_LITERAL);
+ */
+ // correct the mistake we made
+ Book orwellsBook = tolkien.getBooks().get(2);
+ assertTrue(orwellsBook.getTitle().compareTo("nineteeneightyfour") == 0);
+
+ // add orwell as a writer
+ final Writer george = factory.createWriter();
+ george.setName("George_Orwell");
+ orwellsBook.setAuthor(george);
+
+ // and put george in our library
+ lib.getWriters().add(george);
+
+ if (!isEAVTest()) {
+ assertEquals(2, tolkien.getBooks().size());
+ assertEquals(3, lib.getBooks().size());
+ }
+
+ // and save it all
+ res.save(null);
+ res.save(null);
+
+ george.setName("G._Orwell"); // there was a bug in which this
+ // failed, reported by
+ // Georgi Manev
+ res.save(null);
+ res.save(null);
+ res.unload();
+ assertTrue(res.getContents().size() == 0);
+ assertTrue(lib.getBooks().size() > 0);
+ assertTrue(lib.getWriters().size() > 0);
+ }
+
+ {
+ Resource res = getResource(store);
+ Library lib = (Library) res.getEObject(libURI);
+
+ final StoreResource sr = (StoreResource) res;
+ assertFalse(sr.getNewEObjects().contains(lib));
+
+ Writer w = (Writer) res.getEObject(writerURI);
+ assertFalse(sr.getNewEObjects().contains(w));
+ assertEquals("JRR_Tolkien", w.getName());
+ if (!isEAVTest()) {
+ assertEquals(2, w.getBooks().size());
+ }
+ assertEquals("The_Hobbit", w.getBooks().get(1).getTitle());
+ assertEquals(lib.getName(), "Science_Fiction");
+ assertTrue(lib.getWriters().contains(w));
+ assertTrue(lib.getBooks().contains(w.getBooks().get(0)));
+ res.unload();
+ assertTrue(res.getContents().size() == 0);
+ assertTrue(lib.getBooks().size() > 0);
+ assertTrue(lib.getWriters().size() > 0);
+ }
+
+ {
+ Resource res = getResource(store);
+ Library lib = (Library) res.getEObject(libURI);
+ Writer w = factory.createWriter();
+ w.setName("writer");
+ Book b = factory.createBook();
+ b.setTitle("title");
+ b.setPages(1);
+ b.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ w.getBooks().add(b);
+ lib.getWriters().add(0, w);
+ lib.getBooks().add(b);
+ res.save(null);
+ assertTrue(lib.getBooks().size() > 0);
+ assertTrue(lib.getWriters().size() > 0);
+ }
+
+ // {
+ //
+ // XMLResourceImpl xi = new XMLResourceImpl();
+ // xi.getContents().add(tolkien);
+ // FileOutputStream fos = new
+ // FileOutputStream("/home/mtaal/mytmp/test.xml");
+ // xi.save(fos, Collections.EMPTY_MAP);
+ //
+ // ResourceSet rs = new ResourceSetImpl();
+ // Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",
+ // new
+ // XMLResourceFactoryImpl());
+ //
+ // Resource xi =
+ // rs.createResource(URI.createFileURI("/home/mtaal/mytmp/test.xml"));
+ // //xi.load(fis, Collections.EMPTY_MAP);
+ // xi.load(Collections.EMPTY_MAP);
+ // Writer wt = (Writer)xi.getContents().get(0);
+ // }
+
+ // TODO put in JPOX specific test code
+ // // now retrieve the writer using a simple query
+ // if (store instanceof JPOXTestStore)
+ // {
+ // store.beginTransaction();
+ // Writer george = (Writer)store.query("SELECT FROM " +
+ // JPOXHelper.INSTANCE.getInstanceClassName(Writer.class) +
+ // " WHERE name == \"G. Orwell\"", 1).get(0);
+ // assertTrue(george.getBooks().size() == 1);
+ // Book georgesBook = (Book)george.getBooks().get(0);
+ // assertTrue(georgesBook.getAuthor() == george);
+ // store.commitTransaction();
+ // }
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+
+ try {
+ Resource res = getResource(store);
+ res.load(null);
+ Library lib = (Library) res.getContents().get(0);
+ assertTrue(lib.getBooks().size() > 0);
+ assertTrue(lib.getWriters().size() > 0);
+ res.unload();
+ assertTrue(res.getContents().size() == 0);
+ assertTrue(lib.getBooks().size() > 0);
+ assertTrue(lib.getWriters().size() > 0);
+ } catch (IOException e) {
+ throw new StoreTestException(e.getMessage(), e);
+ }
+
+ try {
+ Resource res = getResource(store);
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+
+ Writer writer = lib.getWriters().get(0);
+
+ Library newLib = factory.createLibrary();
+ newLib.setName("tstlib");
+ res.getContents().add(newLib);
+ lib.getWriters().remove(writer);
+ assertTrue(lib.getBooks().size() > 0); // force load of books to
+ // prevent dangling error
+ // in jpox
+ newLib.getWriters().add(writer);
+ res.save(null);
+ res.unload();
+ fail("Orphan delete was not set"); // should fail
+ } catch (Exception e) {
+ // note the above fail will throw an error so that one
+ // does not end up here
+ }
+ }
+
+ protected Resource getResource(TestStore store) {
+ return store.getResource();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceCutPasteAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceCutPasteAction.java
new file mode 100755
index 000000000..fd72f65d6
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceCutPasteAction.java
@@ -0,0 +1,148 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryResourceCutPasteAction.java,v 1.9 2009/04/03 06:15:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests cut/paste action
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.9 $
+ */
+public class LibraryResourceCutPasteAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryResourceCutPasteAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_CASCADE_ALL_ON_CONTAINMENT, "false");
+ props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "REMOVE,MERGE,PERSIST,REFRESH");
+ return props;
+ }
+
+ /** Runs testcase */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR_Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship_of_the_Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(500);
+ book2.setTitle("The_Hobbit");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.setName("Science_Fiction");
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+
+ final Library library2 = factory.createLibrary();
+ library2.setName("Literature");
+
+ res.getContents().add(library);
+ res.getContents().add(library2);
+ res.save(null);
+ res.unload();
+ }
+
+ // walk through the structure starting from the library
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+ Library lib2 = (Library) res.getContents().get(1);
+
+ // cut from paste to
+ Library from = null;
+ Library to = null;
+
+ if (lib.getName().compareTo("Literature") == 0) {
+ from = lib2;
+ to = lib;
+ } else {
+ to = lib2;
+ from = lib;
+ }
+
+ to.getWriters().add(from.getWriters().get(0));
+ res.save(Collections.EMPTY_MAP);
+ res.unload();
+ }
+
+ // check cascade deletes
+ {
+ Resource res = store.getResource();
+ res.load(null);
+ res.getContents().remove(0);
+ res.getContents().remove(0);
+ res.save(null);
+ res.unload();
+ }
+
+ store.checkNumber(Writer.class, 0);
+ store.checkNumber(Book.class, 0);
+ store.checkNumber(Library.class, 0);
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceVisitTreeAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceVisitTreeAction.java
new file mode 100755
index 000000000..4d211d09f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryResourceVisitTreeAction.java
@@ -0,0 +1,99 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryResourceVisitTreeAction.java,v 1.3 2010/02/06 20:50:51 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.TeneoException;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.samples.emf.sample.library.impl.LibraryImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests how children are added to a resource.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class LibraryResourceVisitTreeAction extends AbstractTestAction {
+ public LibraryResourceVisitTreeAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR_Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship_of_the_Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(500);
+ book2.setTitle("The_Hobbit");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ // sorry george making a mistake here, will correct this below
+ final Book book3 = factory.createBook();
+ book3.setAuthor(writer);
+ book3.setPages(500);
+ book3.setTitle("nineteeneightyfour");
+ book3.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ final Library library = factory.createLibrary();
+ library.setName("Science_Fiction");
+ library.getBooks().add(book);
+ library.getBooks().add(book2);
+ library.getBooks().add(book3);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ res.save(null);
+ res.unload();
+ }
+
+ {
+ Resource res = store.getResource("query1=From " + LibraryImpl.class.getName());
+
+ // res.setTrackingModification(true);
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+ assertTrue(lib != null);
+ res.unload();
+ }
+ } catch (Exception e) {
+ throw new TeneoException(e.getMessage(), e);
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java
new file mode 100755
index 000000000..49ac4526c
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibrarySerializationAction.java
@@ -0,0 +1,183 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibrarySerializationAction.java,v 1.10 2010/03/23 16:35:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+
+import org.eclipse.emf.teneo.classloader.ClassLoaderResolver;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.samples.emf.sample.library.impl.BookImpl;
+import org.eclipse.emf.teneo.samples.emf.sample.library.impl.LibraryImpl;
+import org.eclipse.emf.teneo.samples.emf.sample.library.impl.WriterImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests serialization of the library example, also after persistence solution has replaced members.
+ *
+ * Test case uses Impl classes to facilitate build on emft server (encountered class loading
+ * errors).
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.10 $
+ */
+public class LibrarySerializationAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibrarySerializationAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ /** Does its thing */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // first serialize a non persisted document set
+ serialize(getTestSet(factory, "one"), "one");
+
+ // then persist a set and check serialization after persisting
+ {
+ store.beginTransaction();
+ Library lib = getTestSet(factory, "two");
+ store.store(lib);
+ store.commitTransaction();
+ serialize(lib, "two");
+ }
+
+ // then serialize after reading
+ {
+ store.beginTransaction();
+ LibraryImpl lib = (LibraryImpl) store.getObject(Library.class);
+ assertEquals(2, lib.getBooks().size());
+ // load the list
+ assertTrue(lib.getBooks().get(0) != null);
+ assertEquals(1, lib.getWriters().size());
+ assertEquals(2, (lib.getWriters().get(0)).getBooks().size());
+ assertTrue(null != (lib.getWriters().get(0)).getBooks().get(0));
+ serialize(lib, "two");
+ store.commitTransaction();
+ }
+ }
+
+ /** Serialize and check result */
+ private void serialize(Library lib, String prefix) {
+ try {
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(lib);
+ oos.close();
+
+ final byte[] bytes = bos.toByteArray();
+
+ final ObjectInputStream ois = new ElverObjectInputStream(new ByteArrayInputStream(bytes));
+ checkTestSet((Library) ois.readObject(), prefix);
+ ois.close();
+ } catch (Exception e) {
+ throw new StoreTestException("IOException during serialization test", e);
+ }
+
+ }
+
+ /** Creates a test set and returns a library */
+ @SuppressWarnings("unchecked")
+ private Library getTestSet(LibraryFactory factory, String preFix) {
+ final WriterImpl writer = (WriterImpl) factory.createWriter();
+ writer.setName(preFix + "JRR Tolkien");
+
+ final BookImpl book = (BookImpl) factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(5);
+ book.setTitle(preFix + "The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(7);
+ book2.setTitle(preFix + "The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.setName(preFix + "Science Fiction Library");
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+ return library;
+ }
+
+ /** Checks the test set */
+ @SuppressWarnings("unchecked")
+ private void checkTestSet(Library library, String preFix) {
+ assertEquals(preFix + "Science Fiction Library", library.getName());
+ assertEquals(2, library.getBooks().size());
+ assertEquals(1, library.getWriters().size());
+
+ Writer writer = library.getWriters().get(0);
+ assertEquals(preFix + "JRR Tolkien", writer.getName());
+ assertEquals(2, writer.getBooks().size());
+
+ Book bk1 = library.getBooks().get(0);
+ assertEquals(preFix + "The Hobbit", bk1.getTitle());
+ assertEquals(5, bk1.getPages());
+ assertEquals(BookCategory.SCIENCE_FICTION_LITERAL, bk1.getCategory());
+
+ Book bk2 = library.getBooks().get(1);
+ assertEquals(preFix + "The fellowship of the ring", bk2.getTitle());
+ assertEquals(7, bk2.getPages());
+ assertEquals(BookCategory.SCIENCE_FICTION_LITERAL, bk2.getCategory());
+ }
+
+ /** Specific Object input stream to get rid of classloading issue */
+ private class ElverObjectInputStream extends ObjectInputStream {
+
+ /** Constructor */
+ public ElverObjectInputStream(InputStream in) throws IOException {
+ super(in);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
+ */
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ final String clsName = desc.getName();
+ final Class<?> cls = ClassLoaderResolver.classForName(clsName);
+ if (cls == null) {
+ return super.resolveClass(desc);
+ }
+ return cls;
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryUseMappingFileAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryUseMappingFileAction.java
new file mode 100755
index 000000000..66f861d11
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryUseMappingFileAction.java
@@ -0,0 +1,129 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryUseMappingFileAction.java,v 1.6 2008/03/30 15:12:08 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.HsqldbTestDatabaseAdapter;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class LibraryUseMappingFileAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryUseMappingFileAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props
+ .setProperty(PersistenceOptions.MAPPING_FILE_PATH,
+ "/org/eclipse/emf/teneo/hibernate/test/emf/test.hbm.xml,/org/eclipse/emf/teneo/hibernate/test/emf/test2.hbm.xml");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(5);
+ book.setTitle("The Hobbit");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Book book2 = factory.createBook();
+ book2.setAuthor(writer);
+ book2.setPages(5);
+ book2.setTitle("The fellowship of the ring");
+ book2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.setName("Science Fiction Library");
+ library.getBooks().add(book2);
+ library.getWriters().add(writer);
+ store.store(library);
+
+ store.commitTransaction();
+ assertEquals(2, writer.getBooks().size());
+
+ testTables(store);
+ }
+ }
+
+ private void testTables(TestStore store) {
+ final Connection conn = store.getConnection();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ if (store.getDatabaseAdapter() instanceof HsqldbTestDatabaseAdapter) {
+ rs = stmt.executeQuery("select count(*) from \"testBook\"");
+ } else {
+ rs = stmt.executeQuery("select count(*) from testBook");
+ }
+ rs.next();
+ assertEquals(2, rs.getInt(1));
+ rs.close();
+ } catch (final SQLException e) {
+ assertTrue(e.getMessage(), false);
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (final SQLException e) {
+ }
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ } catch (final SQLException e) {
+ }
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryValidateResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryValidateResourceAction.java
new file mode 100755
index 000000000..2c5f84c31
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/LibraryValidateResourceAction.java
@@ -0,0 +1,184 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: LibraryValidateResourceAction.java,v 1.11 2010/04/02 22:42:54 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.resource.StoreResource;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests if simple validation works for the resource implementation.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.11 $
+ */
+public class LibraryValidateResourceAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public LibraryValidateResourceAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#hibernateEnabled()
+ */
+ protected boolean hibernateEnabled() {
+ return true;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR_Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.getBooks().add(book);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ try {
+ res.save(null);
+ fail("Validation did not work");
+ } catch (Exception e) {
+ library.setName("Science_Fiction");
+ book.setTitle("Fellowship_of_the_Ring");
+ res.save(null);
+ res.save(null);
+ }
+
+ res.save(null);
+ res.unload();
+ }
+
+ {
+ Resource res = store.getResource();
+ res.load(null);
+
+ // test tracking modification
+ res.setTrackingModification(true);
+
+ Library lib = null;
+ for (int i = 0; i < res.getContents().size(); i++) {
+ Object obj = res.getContents().get(i);
+ if (obj instanceof Library) {
+ lib = (Library) obj;
+ break;
+ }
+ }
+
+ assert (lib != null);
+ Writer tolkien = lib.getWriters().get(0);
+
+ tolkien.setName("Mr._Tolkien");
+
+ Writer orwell = factory.createWriter();
+ orwell.setName("G._Orwell");
+ lib.getWriters().add(orwell);
+
+ final StoreResource sr = (StoreResource) res;
+ final List<EObject> ca = sr.getNewEObjects();
+ final HashSet<EObject> cm = sr.getModifiedEObjects();
+ assertEquals(2, ca.size() + cm.size());
+ assertTrue(cm.contains(tolkien));
+ assertTrue(ca.contains(orwell));
+
+ res.save(null);
+ res.unload();
+ }
+
+ {
+ // special test case which occurs when an invalid object is added to an elist which
+ // was
+ Resource res = store.getResource();
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+
+ // create a writer
+ Writer martin = factory.createWriter();
+
+ // and then set the name
+ martin.setName("martin");
+
+ // add to library, writer name not set so invalid
+ lib.getWriters().add(martin);
+
+ // now we can savely save
+ res.save(null);
+ res.unload();
+ }
+
+ {
+ Resource res = store.getResource();
+ res.load(null);
+ Library lib = (Library) res.getContents().get(0);
+ boolean martinFound = false;
+ for (int i = 0; i < lib.getWriters().size(); i++) {
+ Writer wt = lib.getWriters().get(i);
+ martinFound = martinFound || wt.getName().compareTo("martin") == 0;
+ }
+ assertTrue("New writer martin was not committed", martinFound);
+ res.unload();
+ }
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+
+ /** Specific Hibernate flush test */
+ protected void testFlush(Resource res) {
+ /*
+ * if (res instanceof HibernateResource) { HibernateResource hres = (HibernateResource)res; Session session =
+ * hres.getSession(); Transaction tx = session.beginTransaction(); // this should not fail! try { tx.commit(); }
+ * // there should be a finally block but this is only a test catch (Exception e) { fail("The transaction commit
+ * should not flush illegal objects to the database"); } }
+ */
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ListAsIdBagAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ListAsIdBagAction.java
new file mode 100755
index 000000000..1723ce29f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ListAsIdBagAction.java
@@ -0,0 +1,106 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ListAsIdBagAction.java,v 1.2 2009/03/15 14:49:53 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.issues.bz237790.Bz237790Factory;
+import org.eclipse.emf.teneo.samples.issues.bz237790.Bz237790Package;
+import org.eclipse.emf.teneo.samples.issues.bz237790.Many;
+import org.eclipse.emf.teneo.samples.issues.bz237790.One;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class ListAsIdBagAction extends AbstractTestAction {
+
+ private final Bz237790Factory factory = Bz237790Factory.eINSTANCE;
+
+ public ListAsIdBagAction() {
+ super(Bz237790Package.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.MAP_ALL_LISTS_AS_IDBAG, "true");
+ return props;
+ }
+
+ @Override
+ public void doAction(TestStore store) {
+ {
+ store.beginTransaction();
+ addDataSet(store, 1);
+ addDataSet(store, 2);
+ store.commitTransaction();
+ }
+
+ // read the writers and add the second book to the second writer
+ {
+ store.beginTransaction();
+ final List<One> os = store.getObjects(One.class);
+ One o1 = null;
+ One o2 = null;
+ for (One o : os) {
+ if (o.getManies().size() == 2) {
+ o1 = o;
+ } else {
+ o2 = o;
+ }
+ }
+ final List<Many> reserve = new ArrayList<Many>(o1.getManies());
+ o1.getManies().clear();
+ reserve.add(1, o2.getManies().get(1));
+ o1.getManies().addAll(reserve);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final List<One> os = store.getObjects(One.class);
+ for (One o : os) {
+ assertEquals(3, o.getManies().size());
+ }
+ store.commitTransaction();
+ }
+ }
+
+ private void addDataSet(TestStore store, int index) {
+ {
+ final One one = factory.createOne();
+ store.store(one);
+ int num = 3;
+ if (index == 2) {
+ num = 2;
+ }
+ for (int i = 0; i < num; i++) {
+ final Many many = factory.createMany();
+ many.setName("" + index);
+ one.getManies().add(many);
+ store.store(many);
+ }
+ }
+
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/MindMapAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/MindMapAction.java
new file mode 100755
index 000000000..4168e25a8
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/MindMapAction.java
@@ -0,0 +1,146 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: MindMapAction.java,v 1.8 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+import org.example.mindmap.Map;
+import org.example.mindmap.MindmapFactory;
+import org.example.mindmap.MindmapPackage;
+import org.example.mindmap.Priority;
+import org.example.mindmap.Relationship;
+import org.example.mindmap.RelationshipType;
+import org.example.mindmap.Resource;
+import org.example.mindmap.Topic;
+
+/**
+ * Tests the gmf mindmap example
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.8 $
+ */
+public class MindMapAction extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public MindMapAction() {
+ super(MindmapPackage.eINSTANCE);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ final MindmapFactory factory = MindmapFactory.eINSTANCE;
+ {
+ final Map map = factory.createMap();
+ map.setTitle("Persistency Discussions");
+
+ final Resource res1 = factory.createResource();
+ res1.setEmail("mtaal@elver.org");
+ res1.setName("Martin Taal");
+
+ final Resource res2 = factory.createResource();
+ res2.setEmail("test@elver.org");
+ res2.setName("Test Me");
+
+ map.getResources().add(res1);
+ map.getResources().add(res2);
+
+ map.getRootTopics().add(createTopic(store, map.getResources(), factory, "Teneo JPOX", 5));
+ map.getRootTopics().add(createTopic(store, new ArrayList(), factory, "Teneo Hibernate", 3));
+
+ final Relationship rel = factory.createRelationship();
+ rel.setSource((Topic) map.getRootTopics().get(0));
+ rel.setTarget((Topic) map.getRootTopics().get(1));
+ rel.setType(RelationshipType.EXTENDS_LITERAL);
+
+ map.getRelations().add(rel);
+
+ store.beginTransaction();
+ store.store(map);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ Map map = store.getObject(Map.class);
+ assertEquals(2, map.getRootTopics().size());
+ checkTopic(map, (Topic) map.getRootTopics().get(0), "Teneo JPOX", 5);
+ checkTopic(map, (Topic) map.getRootTopics().get(1), "Teneo Hibernate", 3);
+ Relationship rs = (Relationship) map.getRelations().get(0);
+ assertEquals(rs.getSource(), map.getRootTopics().get(0));
+ assertEquals(rs.getTarget(), map.getRootTopics().get(1));
+ map.getRelations().remove(0);
+ map.getRootTopics().remove(1);
+ store.commitTransaction();
+ }
+ {
+ store.beginTransaction();
+ Map map = store.getObject(Map.class);
+ assertEquals(1, map.getRootTopics().size());
+ checkTopic(map, (Topic) map.getRootTopics().get(0), "Teneo JPOX", 5);
+ store.commitTransaction();
+ }
+ }
+
+ /** Create a default topic */
+ @SuppressWarnings("unchecked")
+ private Topic createTopic(TestStore store, List resources, MindmapFactory factory, String name, int level) {
+ final Topic topic = factory.createTopic();
+ topic.setEndDate(store.getDate(new Date()));
+ topic.setStartDate(store.getDate(new Date()));
+ topic.setName(name + level);
+ topic.setPriority(Priority.get(level));
+ topic.setPercentComplete((float) (level * 10.0 / 100.0));
+ topic.getResources().addAll(resources);
+ for (int i = 0; i < level; i++) {
+ topic.getSubtopics().add(createTopic(store, resources, factory, name + "_", level - 1));
+ }
+ return topic;
+ }
+
+ private void checkTopic(Map map, Topic topic, String name, int level) {
+ assertEquals(name + level, topic.getName());
+ assertEquals(level, topic.getSubtopics().size());
+ assertEquals(Priority.get(level), topic.getPriority());
+ assertEquals((float) (level * 10.0 / 100.0), topic.getPercentComplete(), 0.1f);
+ for (int i = 0; i < topic.getResources().size(); i++) {
+ assertEquals(topic.getResources().get(i), map.getResources().get(i));
+ }
+ for (int i = 0; i < level; i++) {
+ checkTopic(map, (Topic) topic.getSubtopics().get(i), name + "_", level - 1);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/NoEscapeLibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/NoEscapeLibraryAction.java
new file mode 100755
index 000000000..fffc34c84
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/NoEscapeLibraryAction.java
@@ -0,0 +1,45 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: NoEscapeLibraryAction.java,v 1.2 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd without escape character.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class NoEscapeLibraryAction extends LibraryAction {
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SQL_NAME_ESCAPE_CHARACTER, "");
+ props.putAll(super.getExtraConfigurationProperties());
+ return props;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ assertTrue(store.getMappingXML().indexOf("`") == -1);
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayAction.java
new file mode 100755
index 000000000..1225544bb
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayAction.java
@@ -0,0 +1,139 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: PlayAction.java,v 1.9 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.eclipse.emf.teneo.samples.emf.sample.play.PlayPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.play.PlayType;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests by reading a play.xml file storing it in the database, then retrieve it again, store it in an xml file and
+ * compare the data in this xml file with the original.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.9 $
+ */
+public class PlayAction extends AbstractTestAction {
+ public PlayAction() {
+ super(PlayPackage.eINSTANCE);
+ }
+
+ /** Creates a supplier, a product, relates then, saves and retrieves them again. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ // read play.xml as a resource!
+ PlayType play = null;
+ try {
+ // read from the resource
+ {
+ // a file handle to the current class
+ // the play.xml is in the model directory
+ final Resource resource = new XMLResourceImpl();
+ resource.load(PlayType.class.getResourceAsStream("data/small_play.xml"), Collections.EMPTY_MAP);
+ resource.load(Collections.EMPTY_MAP);
+ play = (PlayType) resource.getContents().get(0);
+ // resource.unload();
+ }
+
+ // store the play in the database
+ {
+ store.beginTransaction();
+ store.store(play);
+ /*
+ * apparently jpox started to find the element name group a reserved word which was
+ * not allowed anymore in the where clause. List list = store.query("SELECT FROM
+ * org.eclipse.emf.teneo.test.emf.sample.play.impl.SceneTypeImpl WHERE " + "
+ * group.contains(sceneGroup) && sceneGroup.speech == speech &&" + "
+ * speech.group.contains(puckSpeaker) && puckSpeaker.speaker==\"PUCK\"" + "
+ * VARIABLES org.eclipse.emf.teneo.test.emf.sample.play.impl.SceneTypeImplgroup
+ * sceneGroup; " + " org.eclipse.emf.teneo.test.emf.sample.play.impl.SpeechTypeImpl
+ * speech; " + " org.eclipse.emf.teneo.test.emf.sample.play.impl.SpeechTypeImplgroup
+ * puckSpeaker"); assertEquals(6, list.size());
+ */
+ store.commitTransaction();
+ play = null;
+ }
+
+ // read from the relational store
+ // and save it in a xml byte array
+ byte[] bytes;
+ {
+ store.beginTransaction();
+ final PlayType myplay = store.getObject(PlayType.class);
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final Resource resource = new XMLResourceImpl();
+ resource.getContents().add(myplay);
+ resource.save(bos, Collections.EMPTY_MAP);
+ bytes = bos.toByteArray();
+ store.commitTransaction();
+ }
+
+ // now compare the two resources
+ compareResult("small_play.xml", bytes, true);
+ } catch (Exception e) {
+ throw new StoreTestException("Exception when loading play.xml", e);
+ }
+ }
+
+ /** Compare the original and the generated xml file */
+ @SuppressWarnings("unchecked")
+ protected void compareResult(String fileNameOne, byte[] bytes, boolean asXML) throws IOException {
+ final InputStream isOne = PlayType.class.getResourceAsStream("data/" + fileNameOne);
+
+ final Resource original_resource;
+ if (asXML) {
+ original_resource = new XMLResourceImpl();
+ } else {
+ original_resource = new XMIResourceImpl();
+ }
+ original_resource.load(isOne, Collections.EMPTY_MAP);
+ final Iterator original_iterator = original_resource.getAllContents();
+
+ final Resource new_resource;
+ if (asXML) {
+ new_resource = new XMLResourceImpl();
+ } else {
+ new_resource = new XMIResourceImpl();
+ }
+ new_resource.load(new ByteArrayInputStream(bytes), Collections.EMPTY_MAP);
+ final Iterator new_iterator = new_resource.getAllContents();
+
+ // rough structural test
+ while (original_iterator.hasNext()) {
+ assertTrue("The new_play.xml has less nodes", new_iterator.hasNext());
+
+ final EObject original_object = (EObject) original_iterator.next();
+ final EObject new_object = (EObject) new_iterator.next();
+ assertEquals(original_object.getClass(), new_object.getClass());
+ }
+ assertTrue("The original_play.xml has less nodes", !new_iterator.hasNext());
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayImExportAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayImExportAction.java
new file mode 100755
index 000000000..0d375c3d6
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PlayImExportAction.java
@@ -0,0 +1,54 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: PlayImExportAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.emf.teneo.samples.emf.sample.play.PlayType;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests by reading a play.xml file storing it in the database, then retrieve it again, store it in an xml file
+ * and compare the data in this xml file with the original.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+*/
+public abstract class PlayImExportAction extends PlayAction {
+ /** Creates a supplier, a product, relates then, saves and retrieves them again. */
+ public void doAction(TestStore store) {
+ try {
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ imExport(PlayType.class.getResourceAsStream("data" + File.separator + "original_play.xml"),
+ bos, store);
+
+ // and compare the result
+ compareResult("original_play.xml", bos.toByteArray(), true);
+ } catch (IOException e) {
+ throw new StoreTestException("IOException ", e);
+ }
+ }
+
+ /** Import/export, from and to */
+ protected abstract void imExport(InputStream is, OutputStream os, TestStore store);
+
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PrimerPOAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PrimerPOAction.java
new file mode 100755
index 000000000..02bee9d47
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/PrimerPOAction.java
@@ -0,0 +1,90 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: PrimerPOAction.java,v 1.6 2008/02/28 07:08:16 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.Item;
+import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.PurchaseOrder;
+import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.SchemaprimerpoFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.SchemaprimerpoPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.schemaprimerpo.USAddress;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the library example of emf/xsd.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public class PrimerPOAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public PrimerPOAction() {
+ super(SchemaprimerpoPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ {
+ store.beginTransaction();
+ final SchemaprimerpoFactory factory = SchemaprimerpoFactory.eINSTANCE;
+ final Item item = factory.createItem();
+ item.setComment("This is my test item");
+ item.setPartNum("partnumber");
+ item.setProductName("productname");
+ item.setQuantity(new BigInteger("500"));
+ item.setUSPrice(new BigDecimal(50.123));
+ item.setShipDate((XMLGregorianCalendar) store.getDate(new Date()));
+
+ final Item item2 = factory.createItem();
+ item2.setComment("This is my second test item");
+ item2.setPartNum("partnumber");
+ item2.setProductName("productname");
+ item2.setQuantity(new BigInteger("500"));
+ item2.setUSPrice(new BigDecimal(50.123));
+ item2.setShipDate((XMLGregorianCalendar) store.getDate(new Date()));
+
+ final USAddress addr = factory.createUSAddress();
+ addr.setCity("c");
+ addr.setCountry("country");
+ addr.setName("name");
+ addr.setState("state");
+ addr.setStreet("street");
+ addr.setZip(new BigDecimal("3941"));
+
+ final PurchaseOrder po = factory.createPurchaseOrder();
+ po.setComment("this is my comment");
+ po.setBillTo(addr);
+ po.getItems().add(item);
+ po.getItems().add(item2);
+ po.setOrderDate((XMLGregorianCalendar) store.getDate(new Date()));
+
+ store.store(po);
+ store.commitTransaction();
+ }
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ProductAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ProductAction.java
new file mode 100755
index 000000000..fadcebd54
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/ProductAction.java
@@ -0,0 +1,136 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: ProductAction.java,v 1.12 2010/11/12 09:33:38 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Date;
+import java.util.Properties;
+
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.product.ClassificationType;
+import org.eclipse.emf.teneo.samples.emf.sample.product.ProductFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.product.ProductPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.product.ProductType;
+import org.eclipse.emf.teneo.samples.emf.sample.product.SupplierType;
+import org.eclipse.emf.teneo.samples.emf.sample.product.impl.ProductTypeImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Very simple emf test which tests a simple relation between a product and its
+ * supplier and some primitive types (double and date).
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.12 $
+ */
+public class ProductAction extends AbstractTestAction {
+ public ProductAction() {
+ super(ProductPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(
+ PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT,
+ "true");
+ return props;
+ }
+
+ /**
+ * Creates a supplier, a product, relates then, saves and retrieves them
+ * again.
+ */
+ @Override
+ public void doAction(TestStore store) {
+ {
+ store.beginTransaction();
+
+ final ProductFactory factory = ProductFactory.eINSTANCE;
+
+ final SupplierType supplier = factory.createSupplierType();
+ supplier.setName("supplier1");
+ supplier.setNoOfEmployees(1);
+ store.store(supplier);
+
+ final ProductType product = factory.createProductType();
+ product.setCode("product1");
+ product.setCreatedOn(store.getDate(new Date()));
+ product.setId("productid1");
+ product.setPrice(199.95);
+ product.setSupplier(supplier);
+
+ ClassificationType c1 = factory.createClassificationType();
+ c1.setName("c1");
+ ClassificationType c2 = factory.createClassificationType();
+ c2.setName("c2");
+ ClassificationType c3 = factory.createClassificationType();
+ c3.setName("c3");
+
+ product.setAnyOne(c1);
+ product.getAnyList().add(c2);
+ product.getAnyList().add(c3);
+ product.getAnyList().add(supplier);
+
+ store.store(product);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ ProductTypeImpl result = (ProductTypeImpl) store
+ .getObject(ProductType.class);
+ assertTrue(result != null);
+ assert (result != null);
+ assertTrue(result.getCode().compareTo("product1") == 0);
+ assertTrue(result.getSupplier() != null);
+ assertEquals(199.95, result.getPrice(), 0.01);
+ assertTrue(result.getSupplier().getName().compareTo("supplier1") == 0);
+
+ ClassificationType c1 = (ClassificationType) result.getAnyOne();
+ assertEquals("c1", c1.getName());
+ assertEquals("c2",
+ ((ClassificationType) result.getAnyList().get(0)).getName());
+ assertEquals("c3",
+ ((ClassificationType) result.getAnyList().get(1)).getName());
+ assertEquals(result.getSupplier(), result.getAnyList().get(2));
+ result.setAnyOne(result.getSupplier());
+ result.getAnyList().remove(1);
+ result.getAnyList().remove(0);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ ProductTypeImpl result = (ProductTypeImpl) store
+ .getObject(ProductType.class);
+ assertEquals(1, result.getAnyList().size());
+ result.setAnyOne(null);
+ store.commitTransaction();
+ }
+
+ // test update of pk, is not supported by hb
+ /*
+ * { store.beginTransaction(); ProductTypeImpl result =
+ * (ProductTypeImpl) store.getObject(ProductType.class);
+ * result.setId("newid"); store.store(result);
+ * store.commitTransaction(); } { store.beginTransaction();
+ * ProductTypeImpl result = (ProductTypeImpl)
+ * store.getObject(ProductType.class); assertEquals("newid",
+ * result.getId()); store.commitTransaction(); }
+ */
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalMapAsClassAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalMapAsClassAction.java
new file mode 100755
index 000000000..dbeffd536
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalMapAsClassAction.java
@@ -0,0 +1,164 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: RentalMapAsClassAction.java,v 1.4 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.rental.Currency;
+import org.eclipse.emf.teneo.rental.Manufacturer;
+import org.eclipse.emf.teneo.rental.RentalBicycle;
+import org.eclipse.emf.teneo.rental.RentalBicycleType;
+import org.eclipse.emf.teneo.rental.RentalCar;
+import org.eclipse.emf.teneo.rental.RentalCarSize;
+import org.eclipse.emf.teneo.rental.RentalContract;
+import org.eclipse.emf.teneo.rental.RentalFactory;
+import org.eclipse.emf.teneo.rental.RentalPackage;
+import org.eclipse.emf.teneo.rental.impl.RentalContractImpl;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests mapping an eclass as a class.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+ */
+public class RentalMapAsClassAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public RentalMapAsClassAction() {
+ super(RentalPackage.eINSTANCE);
+ }
+
+ /**
+ * Set the SET_PROXY property to true.
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_PROXY, "true");
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Test */
+ @Override
+ public void doAction(TestStore store) {
+ final RentalFactory rf = RentalFactory.eINSTANCE;
+
+ {
+ RentalContract rcontract = rf.createRentalContract();
+ RentalCar rcar = rf.createRentalCar();
+ RentalBicycle rb = rf.createRentalBicycle();
+ rcar.setDescription("car");
+ rcar.setSize(RentalCarSize.FAMILY);
+ rb.setDescription("bicycle");
+ rb.setType(RentalBicycleType.MOUNTAIN_BIKE);
+ Manufacturer m = rf.createManufacturer();
+ m.setCode("gazelle");
+ rb.setManufacturer(m);
+ rcontract.getRentalUnits().add(rcar);
+ rcontract.getRentalUnits().add(rb);
+ rcontract.setCost(4.5f);
+ rcontract.setStartDate(new Date());
+ rcontract.setEndDate(new Date());
+ rcontract.setRentToBusinessPartner("business partner");
+
+ Currency c = rf.createCurrency();
+ c.setCode("EUR");
+ rcontract.setCurrency(c);
+ store.beginTransaction();
+ store.store(rcontract.getRentalUnits());
+ store.store(rcontract);
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ final RentalContract rc = (RentalContract) store.query("select rc from RentalContract as rc").get(0);
+ assertEquals(2, rc.getRentalUnits().size());
+ final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0);
+ final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1);
+ Currency c = rc.getCurrency();
+ assertEquals("EUR", c.getCode());
+ assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no
+ // dependencies on
+ // hibernate from this
+ // package
+ assertEquals("car", rcar.getDescription());
+ assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType());
+ assertEquals("bicycle", rb.getDescription());
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ List<?> list = store.query("select rc from " + RentalContractImpl.class.getName() + " as rc");
+ RentalContract rc = (RentalContract) list.get(0);
+ assertEquals(2, rc.getRentalUnits().size());
+ final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0);
+ final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1);
+ Currency c = rc.getCurrency();
+ assertEquals("EUR", c.getCode());
+ assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no
+ // dependencies on
+ // hibernate from this
+ // package
+ assertEquals("car", rcar.getDescription());
+ assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType());
+ assertEquals("bicycle", rb.getDescription());
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ List<?> list = store.query("select rc from " + RentalContract.class.getName() + " as rc");
+ RentalContract rc = (RentalContract) list.get(0);
+ assertEquals(2, rc.getRentalUnits().size());
+ final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0);
+ final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1);
+ Currency c = rc.getCurrency();
+ assertEquals("EUR", c.getCode());
+ assertTrue(c.getClass().getSimpleName().indexOf("$$") != -1); // rough test, no
+ // dependencies on
+ // hibernate from this
+ // package
+ assertEquals("car", rcar.getDescription());
+ assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType());
+ assertEquals("bicycle", rb.getDescription());
+ store.commitTransaction();
+ }
+
+ try {
+ Resource res = store.getResource();
+ res.load(Collections.EMPTY_MAP);
+ assertEquals(5, res.getContents().size());
+ } catch (Exception e) {
+ throw new StoreTestException(e.getMessage(), e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalResourceReferenceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalResourceReferenceAction.java
new file mode 100755
index 000000000..818c23695
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/RentalResourceReferenceAction.java
@@ -0,0 +1,131 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: RentalResourceReferenceAction.java,v 1.4 2008/02/28 07:08:15 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Properties;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.rental.Manufacturer;
+import org.eclipse.emf.teneo.rental.RentalBicycle;
+import org.eclipse.emf.teneo.rental.RentalBicycleType;
+import org.eclipse.emf.teneo.rental.RentalCar;
+import org.eclipse.emf.teneo.rental.RentalCarSize;
+import org.eclipse.emf.teneo.rental.RentalContract;
+import org.eclipse.emf.teneo.rental.RentalFactory;
+import org.eclipse.emf.teneo.rental.RentalPackage;
+import org.eclipse.emf.teneo.resource.StoreResource;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests references from an xml to a db resource.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+ */
+public class RentalResourceReferenceAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public RentalResourceReferenceAction() {
+ super(RentalPackage.eINSTANCE);
+ }
+
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.SET_DEFAULT_CASCADE_ON_NON_CONTAINMENT, "true");
+ return props;
+ }
+
+ /** Test */
+ @Override
+ public void doAction(TestStore store) {
+ final RentalFactory rf = RentalFactory.eINSTANCE;
+ byte[] bytes = null;
+
+ try {
+ RentalContract rcontract = rf.createRentalContract();
+ RentalCar rcar = rf.createRentalCar();
+ RentalBicycle rb = rf.createRentalBicycle();
+ rcar.setDescription("car");
+ rcar.setSize(RentalCarSize.FAMILY);
+ rb.setDescription("bicycle");
+ rb.setType(RentalBicycleType.MOUNTAIN_BIKE);
+ Manufacturer m = rf.createManufacturer();
+ m.setCode("gazelle");
+ rb.setManufacturer(m);
+ rcontract.getRentalUnits().add(rcar);
+ rcontract.getRentalUnits().add(rb);
+ rcontract.setCost(4.5f);
+ rcontract.setEndDate(new Date());
+ rcontract.setRentToBusinessPartner("business partner");
+
+ // save the car and bicycle in a database resource
+ Resource res = store.getResource();
+ res.load(null);
+ res.getContents().add(rcar);
+ res.getContents().add(rb);
+ res.save(Collections.EMPTY_MAP);
+
+ // save the contract in an xml file
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final Resource resource = new XMLResourceImpl();
+ resource.getContents().add(rcontract);
+ resource.save(bos, Collections.EMPTY_MAP);
+
+ // now also save to a file
+ // final FileOutputStream fos = new FileOutputStream("/home/mtaal/mytmp/rental.xml");
+ // resource.save(fos, Collections.EMPTY_MAP);
+ bytes = bos.toByteArray();
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+
+ try {
+ final ResourceSet rs = new ResourceSetImpl();
+ rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());
+ final Resource new_resource = rs.createResource(URI.createFileURI("rental.xml"));
+ new_resource.load(new ByteArrayInputStream(bytes), Collections.EMPTY_MAP);
+ final RentalContract rc = (RentalContract) new_resource.getContents().get(0);
+ assertEquals(2, rc.getRentalUnits().size());
+ final RentalCar rcar = (RentalCar) rc.getRentalUnits().get(0);
+ final RentalBicycle rb = (RentalBicycle) rc.getRentalUnits().get(1);
+ assertEquals("car", rcar.getDescription());
+ assertEquals(rb.eResource(), rcar.eResource());
+ assertTrue(rb.eResource() instanceof StoreResource);
+ assertEquals(RentalBicycleType.MOUNTAIN_BIKE, rb.getType());
+ assertEquals("bicycle", rb.getDescription());
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SchoolLibraryAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SchoolLibraryAction.java
new file mode 100755
index 000000000..3d7f2e95b
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SchoolLibraryAction.java
@@ -0,0 +1,257 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: SchoolLibraryAction.java,v 1.14 2008/06/04 20:15:49 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.PersistenceOptions;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.Writer;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.impl.BookImpl;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.library.impl.WriterImpl;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoolBook;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoolLibrary;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoollibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.schoollibrary.schoollibrary.SchoollibraryPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.AbstractTestStore;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the schoollibrary example which has some more inheritance structures.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.14 $
+ */
+public class SchoolLibraryAction extends AbstractTestAction {
+
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public SchoolLibraryAction() {
+ super(new EPackage[] { LibraryPackage.eINSTANCE, SchoollibraryPackage.eINSTANCE });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.teneo.test.AbstractTestAction#getExtraConfigurationProperties()
+ */
+ @Override
+ public Properties getExtraConfigurationProperties() {
+ final Properties props = new Properties();
+ props.setProperty(PersistenceOptions.DEFAULT_CACHE_STRATEGY, "READ_WRITE");
+ props.setProperty(AbstractTestStore.STORE_MAPPING_FILE_ONE_DIRECTORY_HIGHER, "true");
+ return props;
+ }
+
+ /** Creates simple types and tests against */
+ @Override
+ @SuppressWarnings("unchecked")
+ public void doAction(TestStore store) {
+ // test a simple type
+ final LibraryFactory libFactory = LibraryFactory.eINSTANCE;
+ final SchoollibraryFactory schoolFactory = SchoollibraryFactory.eINSTANCE;
+ {
+ store.beginTransaction();
+
+ SchoolLibrary sl = schoolFactory.createSchoolLibrary();
+ sl.setName("Primary School Library");
+
+ Writer teacher = libFactory.createWriter();
+ teacher.setName("mr. Mathematics");
+
+ SchoolBook sb = schoolFactory.createSchoolBook();
+ sb.setCategory(BookCategory.MYSTERY_LITERAL);
+ sb.setTitle("Mathematics Level 1");
+ sb.setPages(243);
+ sb.setValue(34.59f);
+ sb.setAuthor(teacher);
+
+ SchoolBook sb2 = schoolFactory.createSchoolBook();
+ sb2.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+ sb2.setTitle("Mathematics Level 2");
+ sb2.setPages(244);
+ sb2.setValue(35.70f);
+ sb2.setAuthor(teacher);
+
+ sl.getBooks().add(sb);
+ sl.getBooks().add(sb2);
+ sl.getWriters().add(teacher);
+ sl.setLocation("Schoolbuilding 1");
+ store.store(sb);
+ store.store(sb2);
+ store.store(sl);
+ store.commitTransaction();
+ }
+
+ // now use a resource to read!
+ try {
+ final Resource res = store.getResource(getQuery1());
+ res.load(Collections.EMPTY_MAP);
+ assertEquals(3, res.getContents().size());
+ Iterator it = res.getContents().iterator();
+ int cntTeachers = 0;
+ int cntBooks = 0;
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (obj instanceof Writer) {
+ cntTeachers++;
+ }
+ if (obj instanceof Book) {
+ cntBooks++;
+ }
+ }
+ assertEquals(1, cntTeachers);
+ assertEquals(2, cntBooks);
+ res.unload();
+ } catch (IOException e) {
+ throw new StoreTestException("Exception", e);
+ }
+
+ try {
+ final Resource res = store.getResource(getQuery2());
+ res.load(Collections.EMPTY_MAP);
+ assertEquals(1, res.getContents().size());
+ Writer writ = (Writer) res.getContents().get(0);
+ // in case of direct load into a resource the containers are not set correctly, only
+ // if the container was loaded earlier then this is done.
+ // assertTrue(hasContainer((InternalEObject) writ));
+ writ.getBooks().remove(0);
+ res.save(Collections.EMPTY_MAP);
+ res.unload();
+ } catch (IOException e) {
+ throw new StoreTestException("Exception", e);
+ }
+
+ // test result
+ try {
+ final Resource res = store.getResource(getQuery3());
+ res.load(Collections.EMPTY_MAP);
+ assertEquals(3, res.getContents().size());
+ Iterator it = res.getContents().iterator();
+ int cntTeachers = 0;
+ int cntBooks = 0;
+ int bookNoWriter = 0;
+ Writer checkWriter1 = null;
+ Writer checkWriter2 = null;
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (obj instanceof Writer) {
+ assertEquals(1, ((Writer) obj).getBooks().size());
+ checkWriter1 = (Writer) obj;
+ cntTeachers++;
+ }
+ if (obj instanceof Book) {
+ if (((Book) obj).getAuthor() == null) {
+ bookNoWriter++;
+ } else {
+ checkWriter2 = ((Book) obj).getAuthor();
+ }
+ cntBooks++;
+ if (obj instanceof SchoolBook) {
+ SchoolBook sb = (SchoolBook) obj;
+ if (sb.getValue() < 35f) {
+ assertEquals(34.59f, sb.getValue(), 0.001);
+ } else {
+ assertEquals(35.70f, sb.getValue(), 0.001);
+ }
+ }
+ }
+ }
+ assertEquals(1, cntTeachers);
+ assertEquals(2, cntBooks);
+ assertEquals(1, bookNoWriter);
+ assertTrue(checkWriter1 != null);
+ assertTrue(checkWriter2 == checkWriter1);
+ res.unload();
+ } catch (IOException e) {
+ throw new StoreTestException("Exception", e);
+ }
+
+ // now use a resource to read!
+// try {
+// final Resource res = store.getResource(getQuery4());
+// res.load(Collections.EMPTY_MAP);
+// Iterator it = res.getContents().iterator();
+// while (it.hasNext()) {
+// Book obj = (Book)it.next();
+// if (obj.getAuthor() != null) {
+// assertEquals(obj.eResource(), obj.getAuthor().eResource());
+// }
+// }
+// res.unload();
+// } catch (IOException e) {
+// throw new StoreTestException("Exception", e);
+// }
+
+ try {
+ Resource res = store.getResource();
+ res.load(Collections.EMPTY_MAP);
+ // 1 in case multiple inheritance is not supported
+ assertEquals(1, res.getContents().size());
+ final Library lib = (Library) res.getContents().get(0);
+ assertEquals(2, lib.getBooks().size());
+ res.unload();
+
+ } catch (IOException e) {
+ throw new StoreTestException("Exception", e);
+ }
+ }
+
+ /** Returns one test query */
+ protected String getQuery1() {
+ return "query1=SELECT FROM " + WriterImpl.class.getName() + "&query2=SELECT FROM " + BookImpl.class.getName();
+ // "query1=FROM " + Writer.class.getName() + "&query2=FROM " + Book.class.getName()
+ }
+
+ /** Returns one test query */
+ protected String getQuery2() {
+ return "query1=SELECT FROM " + WriterImpl.class.getName();
+ // "query1=FROM " + Writer.class.getName();
+ }
+
+ /** Returns one test query */
+ protected String getQuery3() {
+ return "query1=SELECT FROM " + WriterImpl.class.getName() + "&query2=SELECT FROM " + BookImpl.class.getName();
+ // "query1=FROM " + Writer.class.getName() + "&query2=FROM " + Book.class.getName();
+ }
+
+ /** Returns one test query */
+ protected String getQuery4() {
+ return "query1=SELECT FROM " + BookImpl.class.getName();
+ // "query1=FROM " + Writer.class.getName() + "&query2=FROM " + Book.class.getName();
+ }
+
+ /** Container present */
+ protected boolean hasContainer(InternalEObject obj) {
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleLibraryResourceAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleLibraryResourceAction.java
new file mode 100755
index 000000000..f2a11c669
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleLibraryResourceAction.java
@@ -0,0 +1,107 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: SimpleLibraryResourceAction.java,v 1.2 2009/04/03 06:15:39 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.io.IOException;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Book;
+import org.eclipse.emf.teneo.samples.emf.sample.library.BookCategory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Library;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.library.LibraryPackage;
+import org.eclipse.emf.teneo.samples.emf.sample.library.Writer;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.StoreTestException;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.2 $
+ */
+public class SimpleLibraryResourceAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public SimpleLibraryResourceAction() {
+ super(LibraryPackage.eINSTANCE);
+ }
+
+ protected boolean hibernateEnabled() {
+ return true;
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final LibraryFactory factory = LibraryFactory.eINSTANCE;
+
+ // create a book, writer and library
+ try {
+ {
+ Resource res = getResource(store);
+ res.load(null);
+
+ final Writer writer = factory.createWriter();
+ writer.setName("JRR_Tolkien");
+
+ final Book book = factory.createBook();
+ book.setAuthor(writer);
+ book.setPages(510);
+ book.setTitle("Fellowship_of_the_Ring");
+ book.setCategory(BookCategory.SCIENCE_FICTION_LITERAL);
+
+ final Library library = factory.createLibrary();
+ library.setName("Science_Fiction");
+ library.getBooks().add(book);
+ library.getWriters().add(writer);
+
+ res.getContents().add(library);
+ assertTrue(book.eDeliver());
+ assertTrue(writer.eDeliver());
+ res.save(null);
+ assertTrue(book.eDeliver());
+ assertTrue(writer.eDeliver());
+ res.unload();
+ }
+
+ // walk through the structure starting from the library
+ {
+ Resource res = getResource(store);
+ res.load(null);
+
+ Library lib = (Library) res.getContents().get(0);
+ Writer tolkien = lib.getWriters().get(0);
+ assertEquals("JRR_Tolkien", tolkien.getName());
+ tolkien.setName("Tolkien");
+ assertTrue(tolkien.eDeliver());
+ res.save(null);
+ assertTrue(tolkien.eDeliver());
+ assertTrue(lib.getBooks().get(0).eDeliver());
+ }
+ } catch (IOException e) {
+ throw new StoreTestException("IOException during save", e);
+ }
+ }
+
+ protected Resource getResource(TestStore store) {
+ return store.getResource();
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleRentalAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleRentalAction.java
new file mode 100755
index 000000000..3b41dcbfc
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SimpleRentalAction.java
@@ -0,0 +1,105 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: SimpleRentalAction.java,v 1.3 2010/10/29 09:35:22 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.Date;
+import java.util.List;
+
+import org.eclipse.emf.teneo.rental.Manufacturer;
+import org.eclipse.emf.teneo.rental.RentalCar;
+import org.eclipse.emf.teneo.rental.RentalCarSize;
+import org.eclipse.emf.teneo.rental.RentalContract;
+import org.eclipse.emf.teneo.rental.RentalFactory;
+import org.eclipse.emf.teneo.rental.RentalPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests creating holes in a list index in the db
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+ */
+public class SimpleRentalAction extends AbstractTestAction {
+ /**
+ * Constructor for ClassHierarchyParsing.
+ *
+ * @param arg0
+ */
+ public SimpleRentalAction() {
+ super(RentalPackage.eINSTANCE);
+ }
+
+ /** Test */
+ @Override
+ public void doAction(TestStore store) {
+ final RentalFactory rf = RentalFactory.eINSTANCE;
+ {
+ RentalContract rcontract = rf.createRentalContract();
+ RentalCar rcar1 = rf.createRentalCar();
+ rcar1.setDescription("car1");
+ rcar1.setSize(RentalCarSize.FAMILY);
+ RentalCar rcar2 = rf.createRentalCar();
+ rcar2.setDescription("car2");
+ rcar2.setSize(RentalCarSize.FAMILY);
+ RentalCar rcar3 = rf.createRentalCar();
+ rcar3.setDescription("car3");
+ rcar3.setSize(RentalCarSize.FAMILY);
+ rcontract.getRentalUnits().add(rcar1);
+ rcontract.getRentalUnits().add(rcar2);
+ rcontract.getRentalUnits().add(rcar3);
+ rcontract.setCost(4.5f);
+ rcontract.setEndDate(new Date());
+ rcontract.setStartDate(new Date());
+ rcontract.setRentToBusinessPartner("business partner");
+ store.beginTransaction();
+ store.store(rcontract);
+
+ Manufacturer man = rf.createManufacturer();
+ man.setCode("code");
+ man.setTrusted(false);
+ store.store(man);
+
+ store.commitTransaction();
+ }
+
+ {
+ store.beginTransaction();
+ List<?> cars = store.getObjects(RentalCar.class);
+ for (Object o : cars) {
+ final RentalCar rc = (RentalCar) o;
+ if (rc.getDescription().compareTo("car2") == 0) {
+ store.deleteObject(rc);
+ }
+ }
+ store.commitTransaction();
+ }
+
+ {
+ try {
+ store.beginTransaction();
+ final RentalContract rc = store.getObject(RentalContract.class);
+ assertTrue(null == rc.getRentalUnits().get(1));
+ store.commitTransaction();
+ fail();
+ } catch (NullPointerException npe) {
+ // do nothing we should get here
+ }
+ }
+
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SunBooksAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SunBooksAction.java
new file mode 100755
index 000000000..3f71504e3
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/SunBooksAction.java
@@ -0,0 +1,297 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: SunBooksAction.java,v 1.7 2010/02/06 20:50:51 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.AuthorsType;
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.BookCategoryType1;
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.BookType;
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.BooksType;
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.CollectionType;
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.PromotionType;
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.SunBooksFactory;
+import org.eclipse.emf.teneo.samples.emf.sample.sunBooks.SunBooksPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the sun books example, is mainly used to test EList methods (move, set, contains, move, etc)
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.7 $
+*/
+@SuppressWarnings({ "unchecked", "deprecation" })
+public class SunBooksAction extends AbstractTestAction {
+ public SunBooksAction() {
+ super(SunBooksPackage.eINSTANCE);
+ }
+
+ /** Creates an item, an address and links them to a po. */
+ @Override
+ public void doAction(TestStore store) {
+ final SunBooksFactory factory = SunBooksFactory.eINSTANCE;
+
+ // create a book, writer and library
+ {
+ store.beginTransaction();
+
+ BookType book = factory.createBookType();
+ {
+ book.setBookCategory(BookCategoryType1.FICTION_LITERAL);
+ book.setDescription("In this prequel story to George R. R. Martin's Award winning....");
+ book.setName("The Hedge Knight");
+ book.setISBN(97640110);
+ book.setItemId("097640110K");
+ book.setPrice("£6.99");
+
+ PromotionType promotion = factory.createPromotionType();
+ promotion.setDiscount("10%");
+ book.setPromotion(promotion);
+
+ book.setPublicationDate(store.getDate(new Date("10/10/2003")));
+
+ AuthorsType author = factory.createAuthorsType();
+ author.getAuthorName().add("George R.R. Martin");
+ author.getAuthorName().add("Ben Avery");
+ book.setAuthors(author);
+ }
+
+ BookType book1 = factory.createBookType();
+ {
+ book1.setBookCategory(BookCategoryType1.FICTION_LITERAL);
+ book1
+ .setDescription("The first book in a brand new series from world-wide bestselling author of MAGICIAN, Raymond E. Feist....");
+ book1.setName("Flight of the Nighthawks: Darkwar (Conclave of Shadows S.)");
+ book1.setISBN(713374);
+ book1.setItemId("000713374X");
+ book1.setPrice("£12.53");
+
+ PromotionType promotion = factory.createPromotionType();
+ promotion.setNone("none");
+ book1.setPromotion(promotion);
+
+ book1.setPublicationDate(store.getDate(new Date("10/10/2003")));
+
+ AuthorsType author = factory.createAuthorsType();
+ author.getAuthorName().add("Raymond Feist");
+ book1.setAuthors(author);
+ }
+
+ BookType book2 = factory.createBookType();
+ {
+ book2.setBookCategory(BookCategoryType1.FICTION_LITERAL);
+ book2
+ .setDescription("Foundation marks the first of a series of tales set so far in the future that Earth is all....");
+ book2.setName("Foundation (The Foundation Series)");
+ book2.setISBN(586010807);
+ book2.setItemId("0586010807");
+ book2.setPrice("£5.59");
+
+ PromotionType promotion = factory.createPromotionType();
+ promotion.setNone("none");
+ book2.setPromotion(promotion);
+
+ book2.setPublicationDate(store.getDate(new Date("10/10/2003")));
+
+ AuthorsType author = factory.createAuthorsType();
+ author.getAuthorName().add("Isaac Asimov");
+ book2.setAuthors(author);
+ }
+
+ // put the book in the collection
+ CollectionType coll = factory.createCollectionType();
+ BooksType booksType = factory.createBooksType();
+ booksType.getBook().add(book);
+ booksType.getBook().add(book1);
+ booksType.getBook().add(book2);
+ coll.setBooks(booksType);
+ store.store(coll);
+ store.commitTransaction();
+ }
+
+ // The following methods of the Elist are checked
+ // move
+ // isEmpty (false)
+ // get
+ // size
+ // contains
+ // containsAll
+ // iterator
+ // listiterator
+ {
+ store.beginTransaction();
+ final CollectionType coll = store.getObject(CollectionType.class);
+ final BooksType books = coll.getBooks();
+
+ // get Isaacs book
+ BookType isaac = books.getBook().get(2);
+
+ // move Isaac to the first position
+ books.getBook().move(0, 2);
+ assertTrue("Index of Isaacs book is " + books.getBook().indexOf(isaac), books.getBook().indexOf(isaac) == 0);
+ assertTrue(books.getBook().size() == 3); // move does not delete
+
+ // check contains on false
+ assertFalse(books.getBook().contains(factory.createBookType()));
+ assertTrue(books.getBook().contains(books.getBook().get(0)));
+
+ // is empty
+ assertFalse(books.getBook().isEmpty());
+
+ ArrayList checkContains = new ArrayList();
+ Iterator it = books.getBook().iterator();
+ while (it.hasNext()) {
+ checkContains.add(it.next());
+ }
+ assertTrue(books.getBook().containsAll(checkContains));
+
+ assertTrue(books.getBook().size() == 3);
+
+ ArrayList checkContains2 = new ArrayList();
+ ListIterator itList = books.getBook().listIterator();
+ while (itList.hasNext()) {
+ checkContains2.add(itList.next());
+ }
+ assertTrue(books.getBook().containsAll(checkContains2));
+
+ List subList = books.getBook().subList(0, 2);
+ assertTrue(subList.size() == 2);
+ assertTrue(books.getBook().containsAll(subList));
+
+ store.commitTransaction();
+ }
+
+ // test remove(int) and removeAll
+ {
+ store.beginTransaction();
+ final CollectionType coll = store.getObject(CollectionType.class);
+ final BooksType books = coll.getBooks();
+
+ // the first book should be Isaac, check the move
+ BookType isaacsBook = books.getBook().get(0);
+ String authorName = isaacsBook.getAuthors().getAuthorName().get(0);
+ assertTrue(authorName.compareTo("Isaac Asimov") == 0);
+
+ assertTrue(books.getBook().size() == 3);
+
+ books.getBook().remove(0); // remove Isaac
+ List removeList = new ArrayList(books.getBook().subList(0, 1));
+ books.getBook().removeAll(removeList);
+
+ store.commitTransaction();
+ }
+
+ // add a new book using set
+ BookType book4 = factory.createBookType();
+ {
+ book4.setBookCategory(BookCategoryType1.FICTION_LITERAL);
+ book4.setDescription(" The second volume in the Foundation saga. Catastrophic event....");
+ book4.setName("Foundation and Empire (The Foundation Series)");
+ book4.setISBN(586013555);
+ book4.setItemId("0586013555");
+ book4.setPrice("£5.59");
+
+ PromotionType promotion = factory.createPromotionType();
+ promotion.setNone("none");
+ book4.setPromotion(promotion);
+
+ book4.setPublicationDate(store.getDate(new Date("10/10/2003")));
+
+ AuthorsType author = factory.createAuthorsType();
+ author.getAuthorName().add("Isaac Asimov");
+ book4.setAuthors(author);
+
+ store.beginTransaction();
+ final CollectionType coll = store.getObject(CollectionType.class);
+ final BooksType books = coll.getBooks();
+ books.getBook().set(0, book4);
+ store.commitTransaction();
+ }
+
+ // add the first book again
+ BookType book0 = factory.createBookType();
+ {
+ book0.setBookCategory(BookCategoryType1.FICTION_LITERAL);
+ book0.setDescription("In this prequel story to George R. R. Martin's Award winning....");
+ book0.setName("The Hedge Knight");
+ book0.setISBN(97640110);
+ book0.setItemId("097640110K");
+ book0.setPrice("£6.99");
+
+ PromotionType promotion = factory.createPromotionType();
+ promotion.setDiscount("10%");
+ book0.setPromotion(promotion);
+
+ book0.setPublicationDate(store.getDate(new Date("10/10/2003")));
+
+ AuthorsType author = factory.createAuthorsType();
+ author.getAuthorName().add("George R.R. Martin");
+ author.getAuthorName().add("Ben Avery");
+ book0.setAuthors(author);
+
+ store.beginTransaction();
+ final CollectionType coll = store.getObject(CollectionType.class);
+ final BooksType books = coll.getBooks();
+ books.getBook().add(book0);
+ store.commitTransaction();
+ }
+
+ // test remove(object)
+ {
+ store.beginTransaction();
+ final CollectionType coll = store.getObject(CollectionType.class);
+ final BooksType books = coll.getBooks();
+ assertTrue(books.getBook().size() == 2);
+ BookType book = books.getBook().get(0);
+ books.getBook().remove(book);
+ store.commitTransaction();
+ }
+
+ // test clear
+ {
+ store.beginTransaction();
+ final CollectionType coll = store.getObject(CollectionType.class);
+ final BooksType books = coll.getBooks();
+ assertTrue(books.getBook().size() == 1);
+ books.getBook().clear();
+ store.commitTransaction();
+ }
+
+ // now everything should be zero
+ {
+ store.beginTransaction();
+ final CollectionType coll = store.getObject(CollectionType.class);
+ final BooksType books = coll.getBooks();
+ assertTrue(books.getBook().size() == 0);
+ store.commitTransaction();
+ }
+
+ // these should all be gone
+ {
+ store.beginTransaction();
+ store.checkNumber(BookType.class, 0);
+ store.checkNumber(AuthorsType.class, 0);
+ store.checkNumber(PromotionType.class, 0);
+ store.commitTransaction();
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/WorkFlowAction.java b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/WorkFlowAction.java
new file mode 100755
index 000000000..e50b22f3f
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/WorkFlowAction.java
@@ -0,0 +1,40 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: WorkFlowAction.java,v 1.3 2008/02/28 07:08:14 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.test.emf.sample;
+
+import org.eclipse.emf.teneo.samples.emf.sample.workflow.WorkflowPackage;
+import org.eclipse.emf.teneo.test.AbstractTestAction;
+import org.eclipse.emf.teneo.test.stores.TestStore;
+
+/**
+ * Tests the workflow example.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.3 $
+*/
+public class WorkFlowAction extends AbstractTestAction
+{
+ public WorkFlowAction()
+ {
+ super(WorkflowPackage.eINSTANCE);
+ }
+
+ /** Test */
+ public void doAction(TestStore store)
+ {
+ }
+}
diff --git a/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/debFile.ecore b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/debFile.ecore
new file mode 100755
index 000000000..0e14027b4
--- /dev/null
+++ b/tests/org.eclipse.emf.teneo.commontest/src/org/eclipse/emf/teneo/test/emf/sample/debFile.ecore
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xmi:XMI xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore">
+ <ecore:EPackage name="PrimitiveTypes" nsURI="atl.primitive.type" nsPrefix="ptyp">
+ <eClassifiers xsi:type="ecore:EDataType" name="Boolean" instanceClassName="boolean"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="Integer" instanceClassName="int"/>
+ <eClassifiers xsi:type="ecore:EDataType" name="String" instanceClassName="java.lang.String"/>
+ </ecore:EPackage>
+ <ecore:EPackage name="deb" nsURI="my.model.of.debian.package" nsPrefix="deb">
+ <eClassifiers xsi:type="ecore:EClass" name="Deb">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="metadata" ordered="false"
+ lowerBound="1" eType="#/1/Databin" containment="true" eOpposite="#/1/Databin/debpm"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="control" ordered="false"
+ lowerBound="1" eType="#/1/Archcontrol" containment="true" eOpposite="#/1/Archcontrol/debc"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="data" ordered="false"
+ lowerBound="1" eType="#/1/Archdata" containment="true" eOpposite="#/1/Archdata/debd"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false"
+ unique="false" lowerBound="1" eType="#/0/String"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Databin">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="debpm" ordered="false"
+ lowerBound="1" eType="#/1/Deb" eOpposite="#/1/Deb/metadata"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="blocs" ordered="false"
+ upperBound="-1" eType="#/1/Bloc" containment="true" eOpposite="#/1/Bloc/meta"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Bloc">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="meta" ordered="false"
+ lowerBound="1" eType="#/1/Databin" eOpposite="#/1/Databin/blocs"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="field" ordered="false"
+ upperBound="-1" eType="#/1/Field" containment="true" eOpposite="#/1/Field/blocs"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Field" abstract="true">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="val" ordered="false"
+ unique="false" lowerBound="1" eType="#/0/String"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="type" ordered="false"
+ unique="false" lowerBound="1" eType="#/0/String"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="blocs" ordered="false"
+ lowerBound="1" eType="#/1/Bloc" eOpposite="#/1/Bloc/field"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Version" eSuperTypes="#/1/Field"/>
+ <eClassifiers xsi:type="ecore:EClass" name="package_name" eSuperTypes="#/1/Field"/>
+ <eClassifiers xsi:type="ecore:EClass" name="Dependancy" eSuperTypes="#/1/Field"/>
+ <eClassifiers xsi:type="ecore:EClass" name="package_descriptions" eSuperTypes="#/1/Field"/>
+ <eClassifiers xsi:type="ecore:EClass" name="Script_descriptions" eSuperTypes="#/1/Field"/>
+ <eClassifiers xsi:type="ecore:EClass" name="Archcontrol">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="debc" ordered="false"
+ lowerBound="1" eType="#/1/Deb" eOpposite="#/1/Deb/control"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="scripts" ordered="false"
+ upperBound="-1" eType="#/1/Script" containment="true" eOpposite="#/1/Script/archscript"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Script">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="archscript" ordered="false"
+ lowerBound="1" eType="#/1/Archcontrol" eOpposite="#/1/Archcontrol/scripts"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="script_name" ordered="false"
+ unique="false" lowerBound="1" eType="#/0/String"/>
+ <eStructuralFeatures xsi:type="ecore:EA