From 4fd12adf44a84388fd6fc4121bcd9ecc3b92778b Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 28 Oct 2023 23:21:49 +0200 Subject: [PATCH] Add o.e.e4.core.javax.tests as javax-using copy of o.e.e4.core.tests and migrate o.e.e4.core.tests to use jakarta annotations. All test-cases, besides the About-tests, are copied from org.eclipse.e4.core.tests, before the migration of the latter. Consequently o.e.e4.core.javax.tests only differ in the fact that the former uses javax annotations, while the latter uses jakarta annotations. When support for javax annotations is removed from the E4-Injector, o.e.e4.core.javax.tests can be deleted too. --- .../.classpath | 11 + .../.gitignore | 1 + .../org.eclipse.e4.core.javax.tests/.project | 33 + .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.core.runtime.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 445 ++++++++ .../.settings/org.eclipse.jdt.ui.prefs | 66 ++ .../org.eclipse.pde.ds.annotations.prefs | 7 + .../META-INF/MANIFEST.MF | 40 + .../OSGI-INF/l10n/bundle.properties | 11 + .../OSGI-INF/l10n/bundle_de.properties | 10 + .../l10n/bundle_de_ch_test.properties | 10 + .../org.eclipse.e4.core.javax.tests/README.md | 2 + .../about.html | 36 + .../build.properties | 24 + .../org.eclipse.e4.core.javax.tests/pom.xml | 62 ++ .../resources/another.properties | 11 + .../resources/another_de.properties | 10 + .../internal/tests/CoreTestsActivator.java | 99 ++ .../tests/contexts/ActivationTest.java | 332 ++++++ .../tests/contexts/AddContextFunction.java | 37 + .../tests/contexts/ContextDynamicTest.java | 178 ++++ .../tests/contexts/ContextFunctionHigh.java | 11 + .../tests/contexts/ContextFunctionLow.java | 11 + .../tests/contexts/DependenciesLeakTest.java | 111 ++ .../tests/contexts/EclipseContextTest.java | 397 ++++++++ .../tests/contexts/NeutralValueTest.java | 206 ++++ .../tests/contexts/ReparentingTest.java | 387 +++++++ .../tests/contexts/RunAndTrackTest.java | 433 ++++++++ .../tests/contexts/StrongIterableTest.java | 273 +++++ .../inject/ActivationInjectionTest.java | 221 ++++ .../inject/AnnotationsInjectionTest.java | 367 +++++++ .../tests/contexts/inject/Bug317183Test.java | 82 ++ .../contexts/inject/ComplexDisposalTest.java | 104 ++ .../inject/ContextFunctionDynamicsTest.java | 181 ++++ .../inject/ContextInjectionDisposeTest.java | 138 +++ .../inject/ContextInjectionFactoryTest.java | 108 ++ .../contexts/inject/ContextInjectionTest.java | 325 ++++++ .../DisposingReferencedContextTest.java | 111 ++ .../inject/ExtraDependenciesTest.java | 115 +++ .../inject/GenericsInjectionTest.java | 151 +++ .../contexts/inject/GenericsListTest.java | 87 ++ .../contexts/inject/GroupedUpdatesTest.java | 142 +++ .../inject/InjectStaticContextTest.java | 277 +++++ .../contexts/inject/InjectionOrderTest.java | 110 ++ .../contexts/inject/InjectionUpdateTest.java | 189 ++++ .../contexts/inject/InvokeInRATTest.java | 89 ++ .../tests/contexts/inject/ObjectBasic.java | 81 ++ .../tests/contexts/inject/ObjectSubClass.java | 96 ++ .../contexts/inject/ObjectSuperClass.java | 93 ++ .../contexts/inject/OptionalAnnotations.java | 50 + .../inject/ParentContextDisposalTest.java | 61 ++ .../tests/contexts/inject/PrintService.java | 24 + .../inject/ProviderInjectionTest.java | 100 ++ .../contexts/inject/ServiceContextTest.java | 394 ++++++++ .../contexts/inject/StringPrintService.java | 33 + .../inject/TestConstructorInjection.java | 132 +++ .../contexts/inject/TestOtherService.java | 5 + .../tests/contexts/inject/TestService.java | 5 + .../tests/contexts/inject/TestServiceA.java | 8 + .../tests/contexts/inject/TestServiceB.java | 8 + .../inject/TestServiceController.java | 32 + .../performance/ContextPerformanceTest.java | 148 +++ .../di/AutoConstructWithCreatableTest.java | 106 ++ .../tests/di/DisposeClassLinkTest.java | 160 +++ .../internal/tests/di/InjectArraysTest.java | 75 ++ .../internal/tests/di/InjectBaseTypeTest.java | 121 +++ .../internal/tests/di/InjectBridgeTest.java | 79 ++ .../internal/tests/di/InjectionOrderTest.java | 72 ++ .../tests/di/InjectionResultLeakTest.java | 83 ++ .../e4/core/internal/tests/di/InvokeTest.java | 53 + .../tests/di/InvokeTestMissingAnnotation.java | 62 ++ .../tests/di/RecursiveObjectCreationTest.java | 96 ++ .../core/internal/tests/di/RequestorTest.java | 60 ++ .../tests/di/extensions/ComponentEnabler.java | 32 + .../tests/di/extensions/DisabledServiceA.java | 8 + .../tests/di/extensions/DisabledServiceB.java | 8 + .../ExtendedSupplierInjectionTests.java | 167 +++ .../tests/di/extensions/FilterServiceA.java | 8 + .../tests/di/extensions/FilterServiceB.java | 8 + .../di/extensions/InjectionEventTest.java | 288 ++++++ .../InjectionMixedSuppliersTest.java | 74 ++ .../extensions/InjectionOSGiHandlerTest.java | 59 ++ .../di/extensions/InjectionOSGiTest.java | 151 +++ .../extensions/InjectionPreferencesTest.java | 299 ++++++ .../extensions/InjectionWithoutOSGITest.java | 66 ++ .../tests/di/extensions/SampleServiceA.java | 8 + .../tests/di/extensions/SampleServiceB.java | 8 + .../extensions/ServiceSupplierTestCase.java | 316 ++++++ .../tests/di/extensions/TestService.java | 5 + .../manual/ComputedValueLimitationTest.java | 123 +++ .../internal/tests/manual/ContextExample.java | 167 +++ .../manual/InjectionErrorReportingTest.java | 220 ++++ .../internal/tests/nls/BundleMessages.java | 45 + .../tests/nls/BundleMessagesRegistry.java | 18 + .../tests/nls/LocaleTransformationTest.java | 168 ++++ .../tests/nls/MessageRegistryTest.java | 170 ++++ .../e4/core/internal/tests/nls/Messages.java | 42 + .../e4/core/internal/tests/nls/NLSTest.java | 948 ++++++++++++++++++ .../tests/nls/ResourceBundleClass.java | 24 + .../nls/ResourceBundleClassMessages.java | 44 + .../tests/nls/ResourceBundleClass_de.java | 23 + .../internal/tests/nls/ResourcesMessages.java | 44 + .../internal/tests/nls/SimpleMessages.java | 41 + .../tests/nls/SimpleMessages.properties | 11 + .../tests/nls/SimpleMessages_de.properties | 10 + .../tests/nls/SimpleMessages_de_CH.properties | 2 + .../nls/SimpleMessages_de_CH_OTHER.properties | 2 + .../nls/SimpleMessages_de_CH_TEST.properties | 2 + .../internal/tests/nls/messages.properties | 11 + .../internal/tests/nls/messages_de.properties | 10 + .../e4/core/javax/tests/CoreTestSuite.java | 133 +++ .../org.eclipse.e4.core.javax.tests/test.xml | 47 + .../META-INF/MANIFEST.MF | 4 +- .../tests/contexts/ActivationTest.java | 6 +- .../tests/contexts/ReparentingTest.java | 6 +- .../inject/ActivationInjectionTest.java | 6 +- .../inject/AnnotationsInjectionTest.java | 9 +- .../contexts/inject/ComplexDisposalTest.java | 8 +- .../inject/ContextFunctionDynamicsTest.java | 6 +- .../inject/ContextInjectionDisposeTest.java | 6 +- .../contexts/inject/ContextInjectionTest.java | 6 +- .../DisposingReferencedContextTest.java | 6 +- .../inject/ExtraDependenciesTest.java | 8 +- .../inject/GenericsInjectionTest.java | 6 +- .../contexts/inject/GenericsListTest.java | 4 +- .../contexts/inject/GroupedUpdatesTest.java | 6 +- .../inject/InjectStaticContextTest.java | 10 +- .../contexts/inject/InjectionOrderTest.java | 8 +- .../contexts/inject/InjectionUpdateTest.java | 8 +- .../contexts/inject/InvokeInRATTest.java | 4 +- .../tests/contexts/inject/ObjectBasic.java | 8 +- .../tests/contexts/inject/ObjectSubClass.java | 8 +- .../contexts/inject/ObjectSuperClass.java | 8 +- .../contexts/inject/OptionalAnnotations.java | 4 +- .../inject/ParentContextDisposalTest.java | 10 +- .../inject/ProviderInjectionTest.java | 6 +- .../contexts/inject/ServiceContextTest.java | 4 +- .../inject/TestConstructorInjection.java | 4 +- .../di/AutoConstructWithCreatableTest.java | 4 +- .../tests/di/DisposeClassLinkTest.java | 8 +- .../internal/tests/di/InjectArraysTest.java | 6 +- .../internal/tests/di/InjectBaseTypeTest.java | 6 +- .../internal/tests/di/InjectBridgeTest.java | 4 +- .../internal/tests/di/InjectionOrderTest.java | 8 +- .../tests/di/InjectionResultLeakTest.java | 6 +- .../tests/di/RecursiveObjectCreationTest.java | 6 +- .../ExtendedSupplierInjectionTests.java | 6 +- .../di/extensions/InjectionEventTest.java | 6 +- .../InjectionMixedSuppliersTest.java | 6 +- .../di/extensions/InjectionOSGiTest.java | 4 +- .../extensions/InjectionPreferencesTest.java | 4 +- .../extensions/InjectionWithoutOSGITest.java | 6 +- .../extensions/ServiceSupplierTestCase.java | 4 +- .../manual/ComputedValueLimitationTest.java | 4 +- .../internal/tests/manual/ContextExample.java | 4 +- .../manual/InjectionErrorReportingTest.java | 10 +- .../internal/tests/nls/BundleMessages.java | 2 +- .../tests/nls/BundleMessagesRegistry.java | 4 +- .../tests/nls/MessageRegistryTest.java | 4 +- .../e4/core/internal/tests/nls/Messages.java | 2 +- .../e4/core/internal/tests/nls/NLSTest.java | 4 +- .../nls/ResourceBundleClassMessages.java | 4 +- .../internal/tests/nls/ResourcesMessages.java | 4 +- .../internal/tests/nls/SimpleMessages.java | 2 +- 165 files changed, 12250 insertions(+), 149 deletions(-) create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.classpath create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.gitignore create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.project create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.resources.prefs create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.runtime.prefs create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.ui.prefs create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.pde.ds.annotations.prefs create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de_ch_test.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/README.md create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/about.html create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/build.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/pom.xml create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/resources/another.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/resources/another_de.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/CoreTestsActivator.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/AddContextFunction.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextDynamicTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionHigh.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionLow.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/DependenciesLeakTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/NeutralValueTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/RunAndTrackTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/StrongIterableTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionFactoryTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/PrintService.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/StringPrintService.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestOtherService.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestService.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceA.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceB.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceController.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/performance/ContextPerformanceTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTestMissingAnnotation.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RequestorTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ComponentEnabler.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceA.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceB.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceA.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceB.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceA.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceB.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/TestService.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/LocaleTransformationTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass_de.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_OTHER.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_TEST.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages_de.properties create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/javax/tests/CoreTestSuite.java create mode 100644 runtime/tests/org.eclipse.e4.core.javax.tests/test.xml diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.classpath b/runtime/tests/org.eclipse.e4.core.javax.tests/.classpath new file mode 100644 index 00000000000..675a5e2962b --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.gitignore b/runtime/tests/org.eclipse.e4.core.javax.tests/.gitignore new file mode 100644 index 00000000000..c59ea270aa5 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.gitignore @@ -0,0 +1 @@ +OSGI-INF/*.xml diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.project b/runtime/tests/org.eclipse.e4.core.javax.tests/.project new file mode 100644 index 00000000000..bc2c0c6a994 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.project @@ -0,0 +1,33 @@ + + + org.eclipse.e4.core.javax.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.resources.prefs b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..99f26c0203a --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.runtime.prefs b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 00000000000..5a0ad22d2a7 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.core.prefs b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..1e7783f372f --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,445 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullable.secondary= +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.APILeak=warning +org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=error +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled +org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 +org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 +org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0 +org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=true +org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false +org.eclipse.jdt.core.formatter.comment.indent_root_tags=false +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert +org.eclipse.jdt.core.formatter.comment.line_length=80 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=false +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=true +org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=120 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true +org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false +org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true +org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true +org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true +org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true +org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.ui.prefs b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000000..5c2f9bc5044 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,66 @@ +cleanup.use_type_arguments=false +cleanup_settings_version=2 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile +formatter_settings_version=14 +org.eclipse.jdt.ui.ondemandthreshold=99 +org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=true +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.make_local_variable_final=true +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_type_arguments=false +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_blocks=true +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=true +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true +sp_cleanup.use_type_arguments=false diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.pde.ds.annotations.prefs b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.pde.ds.annotations.prefs new file mode 100644 index 00000000000..38f9eecff8e --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/.settings/org.eclipse.pde.ds.annotations.prefs @@ -0,0 +1,7 @@ +dsVersion=V1_3 +eclipse.preferences.version=1 +enabled=true +generateBundleActivationPolicyLazy=true +path=OSGI-INF +validationErrorLevel=error +validationErrorLevel.missingImplicitUnbindMethod=error diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF b/runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..938730a37ac --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/META-INF/MANIFEST.MF @@ -0,0 +1,40 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: E4 Core Tests +Bundle-SymbolicName: org.eclipse.e4.core.javax.tests +Bundle-Version: 1.3.200.qualifier +Bundle-Vendor: Eclipse.org +Bundle-Activator: org.eclipse.e4.core.internal.tests.CoreTestsActivator +Require-Bundle: org.eclipse.osgi;bundle-version="3.6.0", + org.eclipse.equinox.preferences;bundle-version="3.3.0", + org.eclipse.e4.core.di, + org.eclipse.e4.core.di.extensions, + org.eclipse.e4.core.di.extensions.supplier, + org.eclipse.e4.core.contexts, + org.eclipse.equinox.registry;bundle-version="3.5.0", + org.eclipse.core.tests.harness;bundle-version="3.6.0", + org.eclipse.e4.core.services;bundle-version="1.1.0", + org.junit;bundle-version="4.12.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-17 +Import-Package: javax.annotation;version="[1.3.0,2.0.0)", + javax.inject;version="[1.0.0,2.0.0)", + org.osgi.service.component;version="1.3.0", + org.osgi.service.event;version="1.3.0" +Export-Package: org.eclipse.e4.core.internal.tests;x-internal:=true, + org.eclipse.e4.core.internal.tests.contexts;x-internal:=true, + org.eclipse.e4.core.internal.tests.contexts.inject;x-internal:=true, + org.eclipse.e4.core.internal.tests.contexts.performance;x-internal:=true, + org.eclipse.e4.core.internal.tests.di;x-internal:=true, + org.eclipse.e4.core.internal.tests.di.extensions;x-internal:=true, + org.eclipse.e4.core.internal.tests.manual;x-internal:=true, + org.eclipse.e4.core.internal.tests.nls;x-internal:=true, + org.eclipse.e4.core.javax.tests +Service-Component: OSGI-INF/*.xml +Eclipse-BundleShape: dir +Require-Capability: osgi.extender; + filter:="(&(osgi.extender=osgi.component)(version>=1.3)(!(version>=2.0)))", + osgi.service; + filter:="(objectClass=org.osgi.service.event.EventAdmin)"; + effective:="active" +Automatic-Module-Name: org.eclipse.e4.core.javax.tests diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle.properties new file mode 100644 index 00000000000..ad0b4b93cb0 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,11 @@ +message=BundleMessage +message_one=BundleMessageUnderscore +messageOne=BundleMessageCamelCase +message.two=BundleMessageUnderscoreDot +message.three=BundleMessageCamelCaseDot +message.four=The idea is from {0} +messageFive_Sub=BundleMessageCamelCaseAndUnderscoreOriginal +message_six__sub=BundleMessageCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=BundleMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=BundleMessageCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=BundleMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de.properties new file mode 100644 index 00000000000..c45cde6d1d7 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de.properties @@ -0,0 +1,10 @@ +message=BundleNachricht +message_one=BundleNachrichtUnderscore +messageOne=BundleNachrichtCamelCase +message.two=BundleNachrichtUnderscoreDot +message.four=Die Idee ist von {0} +messageFive_Sub=BundleNachrichtCamelCaseAndUnderscoreOriginal +message_six__sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de_ch_test.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de_ch_test.properties new file mode 100644 index 00000000000..a0582385afb --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/OSGI-INF/l10n/bundle_de_ch_test.properties @@ -0,0 +1,10 @@ +message=BundleNachrichtVariant +message_one=BundleNachrichtUnderscoreVariant +messageOne=BundleNachrichtCamelCaseVariant +message.two=BundleNachrichtUnderscoreDotVariant +message.four=Die Idee ist von {0} Variant +messageFive_Sub=BundleNachrichtCamelCaseAndUnderscoreOriginalVariant +message_six__sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedVariant +message.seven..sub=BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorifiedVariant +messageEight.Sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedVariant +message_nine._sub=BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasifiedVariant \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/README.md b/runtime/tests/org.eclipse.e4.core.javax.tests/README.md new file mode 100644 index 00000000000..c15285d1bfc --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/README.md @@ -0,0 +1,2 @@ +This is a copy of `org.eclipse.e4.core.tests`, that uses javax annotations while the original uses jakarta annotations now. +When support for javax annotations is removed from the E4-Injector, this project can be deleted entirely as well. diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/about.html b/runtime/tests/org.eclipse.e4.core.javax.tests/about.html new file mode 100644 index 00000000000..164f781a8fd --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/about.html @@ -0,0 +1,36 @@ + + + + +About + + +

About This Content

+ +

November 30, 2017

+

License

+ +

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

+ +

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

+ + + \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/build.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/build.properties new file mode 100644 index 00000000000..76d226c77dc --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/build.properties @@ -0,0 +1,24 @@ +############################################################################### +# Copyright (c) 2010, 2015 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +# Lars Vogel - Bug 474642 +############################################################################### +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + test.xml,\ + OSGI-INF/,\ + resources/,\ + about.html +src.includes = resources/,\ + about.html diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/pom.xml b/runtime/tests/org.eclipse.e4.core.javax.tests/pom.xml new file mode 100644 index 00000000000..44f12659599 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + org.eclipse.platform + eclipse.platform.runtime + 4.30.0-SNAPSHOT + ../.. + + org.eclipse.e4.core.javax.tests + 1.3.200-SNAPSHOT + eclipse-test-plugin + + org.eclipse.e4.core.javax.tests.CoreTestSuite + + + src + + + org.apache.maven.plugins + maven-resources-plugin + + + + copy-ds-component-xml + + copy-resources + + process-test-resources + + + + + ${project.build.outputDirectory}/OSGI-INF + *.xml + + + ${project.basedir}/OSGI-INF + + + + + + + diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another.properties new file mode 100644 index 00000000000..86e9d9c7baf --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another.properties @@ -0,0 +1,11 @@ +message=ResourcesMessage +message_one=ResourcesMessageUnderscore +messageOne=ResourcesMessageCamelCase +message.two=ResourcesMessageUnderscoreDot +message.three=ResourcesMessageCamelCaseDot +message.four=The idea is from {0} +messageFive_Sub=ResourcesMessageCamelCaseAndUnderscoreOriginal +message_six__sub=ResourcesMessageCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=ResourcesMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=ResourcesMessageCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=ResourcesMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another_de.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another_de.properties new file mode 100644 index 00000000000..7c4441b54a6 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/resources/another_de.properties @@ -0,0 +1,10 @@ +message=ResourcesNachricht +message_one=ResourcesNachrichtUnderscore +messageOne=ResourcesNachrichtCamelCase +message.two=ResourcesNachrichtUnderscoreDot +message.four=Die Idee ist von {0} +messageFive_Sub=ResourcesNachrichtCamelCaseAndUnderscoreOriginal +message_six__sub=ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/CoreTestsActivator.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/CoreTestsActivator.java new file mode 100644 index 00000000000..6d0c273f3e1 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/CoreTestsActivator.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.eclipse.core.runtime.preferences.IPreferencesService; +import org.eclipse.e4.core.contexts.IContextFunction; +import org.eclipse.e4.core.internal.tests.contexts.ContextFunctionHigh; +import org.eclipse.e4.core.internal.tests.contexts.ContextFunctionLow; +import org.eclipse.osgi.service.debug.DebugOptions; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.service.event.EventAdmin; +import org.osgi.util.tracker.ServiceTracker; + +public class CoreTestsActivator implements BundleActivator { + + static private CoreTestsActivator defaultInstance; + private BundleContext bundleContext; + private ServiceTracker debugTracker = null; + private ServiceTracker preferencesTracker = null; + private ServiceTracker eventAdminTracker; + + public CoreTestsActivator() { + defaultInstance = this; + } + + public static CoreTestsActivator getDefault() { + return defaultInstance; + } + + @Override + public void start(BundleContext context) throws Exception { + bundleContext = context; + registerContextFunctions(); + } + + @Override + public void stop(BundleContext context) throws Exception { + if (preferencesTracker != null) { + preferencesTracker.close(); + preferencesTracker = null; + } + if (debugTracker != null) { + debugTracker.close(); + debugTracker = null; + } + if (eventAdminTracker != null) { + eventAdminTracker.close(); + eventAdminTracker = null; + } + bundleContext = null; + } + + private void registerContextFunctions() { + { + Dictionary properties = new Hashtable<>(); + properties.put(IContextFunction.SERVICE_CONTEXT_KEY,"test.contextfunction.ranking"); + properties.put(Constants.SERVICE_RANKING, 0); + bundleContext.registerService(IContextFunction.SERVICE_NAME, new ContextFunctionLow(), properties); + } + + Dictionary properties = new Hashtable<>(); + properties.put(IContextFunction.SERVICE_CONTEXT_KEY,"test.contextfunction.ranking"); + properties.put(Constants.SERVICE_RANKING, 100); + bundleContext.registerService(IContextFunction.SERVICE_NAME, new ContextFunctionHigh(), properties); + + } + + public BundleContext getBundleContext() { + return bundleContext; + } + + public EventAdmin getEventAdmin() { + if (eventAdminTracker == null) { + if (bundleContext == null) { + return null; + } + eventAdminTracker = new ServiceTracker<>(bundleContext, EventAdmin.class.getName(), null); + eventAdminTracker.open(); + } + return eventAdminTracker.getService(); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java new file mode 100644 index 00000000000..767113bd3dd --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java @@ -0,0 +1,332 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.junit.Test; + +public class ActivationTest { + + static public class TestRAT extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + IEclipseContext activeContext = context.getActiveLeaf(); + // returns name of the context + return activeContext.get("debugString"); + } + } + + @Test + public void testContextActivation() { + IEclipseContext rootContext = EclipseContextFactory.create("root"); + rootContext.set("testRAT", new TestRAT()); + + IEclipseContext child1 = rootContext.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + IEclipseContext child12 = child1.createChild("child12"); + + IEclipseContext child2 = rootContext.createChild("child2"); + IEclipseContext child21 = child2.createChild("child21"); + IEclipseContext child22 = child2.createChild("child22"); + + assertEquals(rootContext, rootContext.getActiveLeaf()); + assertNull(rootContext.getActiveChild()); + assertEquals("root", rootContext.get("testRAT")); + + child12.activateBranch(); + assertEquals(child12, rootContext.getActiveLeaf()); + assertEquals(child1, rootContext.getActiveChild()); + assertEquals("child12", rootContext.get("testRAT")); + + assertEquals(child2, child2.getActiveLeaf()); + assertNull(child2.getActiveChild()); + assertEquals("child2", child2.get("testRAT")); + + child21.activateBranch(); + assertEquals(child21, rootContext.getActiveLeaf()); + assertEquals(child2, rootContext.getActiveChild()); + assertEquals("child21", rootContext.get("testRAT")); + assertEquals(child12, child1.getActiveLeaf()); + assertEquals(child12, child1.getActiveChild()); + assertEquals("child12", child1.get("testRAT")); + assertEquals(child21, child2.getActiveLeaf()); + assertEquals(child21, child2.getActiveChild()); + assertEquals("child21", child2.get("testRAT")); + + child21.deactivate(); + assertEquals(child2, rootContext.getActiveLeaf()); + assertEquals("child2", rootContext.get("testRAT")); + assertEquals(child12, child1.getActiveLeaf()); + assertEquals("child12", child1.get("testRAT")); + assertEquals(child2, child2.getActiveLeaf()); + assertNull(child2.getActiveChild()); + assertEquals("child2", child2.get("testRAT")); + + child22.activateBranch(); + assertEquals(child22, rootContext.getActiveLeaf()); + assertEquals("child22", rootContext.get("testRAT")); + assertEquals(child12, child1.getActiveLeaf()); + assertEquals("child12", child1.get("testRAT")); + assertEquals(child22, child2.getActiveLeaf()); + assertEquals("child22", child2.get("testRAT")); + + child11.activateBranch(); + assertEquals(child11, rootContext.getActiveLeaf()); + assertEquals("child11", rootContext.get("testRAT")); + assertEquals(child11, child1.getActiveLeaf()); + assertEquals("child11", child1.get("testRAT")); + assertEquals(child22, child2.getActiveLeaf()); + assertEquals("child22", child2.get("testRAT")); + + child11.deactivate(); + assertEquals(child1, rootContext.getActiveLeaf()); + assertEquals("child1", rootContext.get("testRAT")); + assertEquals(child1, child1.getActiveLeaf()); + assertEquals("child1", child1.get("testRAT")); + assertEquals(child22, child2.getActiveLeaf()); + assertEquals("child22", child2.get("testRAT")); + + child1.dispose(); + assertNull(rootContext.getActiveChild()); + child2.activateBranch(); + assertEquals(child22, rootContext.getActiveLeaf()); + assertEquals("child22", rootContext.get("testRAT")); + assertEquals(child22, child2.getActiveLeaf()); + assertEquals("child22", child2.get("testRAT")); + } + + @Test + public void testGetActive() { + IEclipseContext root = EclipseContextFactory.create("root"); + + IEclipseContext child1 = root.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + IEclipseContext child12 = child1.createChild("child12"); + + IEclipseContext child2 = root.createChild("child2"); + IEclipseContext child21 = child2.createChild("child21"); + IEclipseContext child22 = child2.createChild("child22"); + + child11.set("var", "1"); + child12.set("var", "2"); + child1.set("var", "3"); + child21.set("var", "4"); + child22.set("var", "5"); + child2.set("var", "6"); + root.set("var", "7"); + + // nothing is active - we get value from the node + assertEquals("3", child1.getActive("var")); + + child11.activateBranch(); + assertEquals("1", child1.getActive("var")); + child12.activateBranch(); + assertEquals("2", child1.getActive("var")); + child22.activateBranch(); + assertEquals("5", child2.getActive("var")); + } + + @Test + public void testGetActiveBug384425() { + IEclipseContext root = EclipseContextFactory.create("root"); + + IEclipseContext child1 = root.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + + IEclipseContext child2 = root.createChild("child2"); + + // nothing is active - we get value from the node + assertNull(root.getActive("var")); + assertNull(child1.getActive("var")); + assertNull(child2.getActive("var")); + + child11.activateBranch(); + child11.set("var", "1"); + + assertEquals("1", root.getActive("var")); + assertEquals("1", child1.getActive("var")); + assertNull(child2.getActive("var")); + } + + @Test + public void testGetActiveRAT() { + IEclipseContext root = EclipseContextFactory.create("root"); + + IEclipseContext child1 = root.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + IEclipseContext child12 = child1.createChild("child12"); + + IEclipseContext child2 = root.createChild("child2"); + IEclipseContext child21 = child2.createChild("child21"); + IEclipseContext child22 = child2.createChild("child22"); + + child11.set("var", "1"); + child12.set("var", "2"); + child1.set("var", "3"); + child21.set("var", "4"); + child22.set("var", "5"); + child2.set("var", "6"); + root.set("var", "7"); + + final String[] result = new String[1]; + + child1.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + result[0] = (String) context.getActive("var"); + return true; + }}); + + // nothing is active - we get value from the node + assertEquals("3", result[0]); + + child11.activateBranch(); + assertEquals("1", result[0]); + child12.activateBranch(); + assertEquals("2", result[0]); + child22.activateBranch(); + assertEquals("2", result[0]); + } + + @Test + public void testGetActiveRATNumberOfCalls() { + IEclipseContext root = EclipseContextFactory.create("root"); + + IEclipseContext child1 = root.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + IEclipseContext child12 = child1.createChild("child12"); + + IEclipseContext child2 = root.createChild("child2"); + IEclipseContext child21 = child2.createChild("child21"); + IEclipseContext child22 = child2.createChild("child22"); + + child11.set("var", "1"); + child12.set("var", "1"); + child1.set("var", "3"); + child21.set("var", "4"); + child22.set("var", "4"); + child2.set("var", "6"); + root.set("var", "7"); + + final String[] result = new String[1]; + final int[] called = new int[1]; + called[0] = 0; + + child1.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + result[0] = (String) context.getActive("var"); + called[0]++; + return true; + }}); + + // nothing is active - we get value from the node + assertEquals("3", result[0]); + assertEquals(1, called[0]); + + child11.activateBranch(); + assertEquals("1", result[0]); + assertEquals(2, called[0]); + + child12.activateBranch(); + assertEquals("1", result[0]); + assertEquals(3, called[0]); + + child22.activateBranch(); + assertEquals("1", result[0]); + assertEquals(3, called[0]); + + child21.activateBranch(); + assertEquals("1", result[0]); + assertEquals(3, called[0]); + } + + /** + * A variation of {@link #testGetActiveRATNumberOfCalls()} that + * uses distinct values in the leaf contexts. + */ + @Test + public void testGetActiveRATNumberOfCalls2() { + IEclipseContext root = EclipseContextFactory.create("root"); + + IEclipseContext child1 = root.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + IEclipseContext child12 = child1.createChild("child12"); + + IEclipseContext child2 = root.createChild("child2"); + IEclipseContext child21 = child2.createChild("child21"); + IEclipseContext child22 = child2.createChild("child22"); + + child11.set("var", "11"); + child12.set("var", "12"); + child1.set("var", "3"); + child21.set("var", "21"); + child22.set("var", "22"); + child2.set("var", "6"); + root.set("var", "7"); + + final String[] result = new String[1]; + final int[] called = new int[1]; + called[0] = 0; + + child1.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + result[0] = (String) context.getActive("var"); + called[0]++; + return true; + }}); + + // nothing is active - we get value from the node + assertEquals("3", result[0]); + assertEquals(1, called[0]); + + child11.activateBranch(); + assertEquals("11", result[0]); + assertEquals(2, called[0]); + + child12.activateBranch(); + assertEquals("12", result[0]); + assertEquals(3, called[0]); + + child22.activateBranch(); + assertEquals("12", result[0]); + assertEquals(3, called[0]); + + child21.activateBranch(); + assertEquals("12", result[0]); + assertEquals(3, called[0]); + } + + public static class ActiveInject { + //@Inject @Named("var") + public String value; + + @Inject + public void setValue(@Named("var") String value) { + this.value = value; + } + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/AddContextFunction.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/AddContextFunction.java new file mode 100644 index 00000000000..5e260552012 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/AddContextFunction.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.IContextFunction; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.osgi.service.component.annotations.Component; + + +/** + * A function provided as a declarative service. See OSGI-INF/adder.xml. + */ +@Component(service = IContextFunction.class, property = "service.context.key:String=sum") +public class AddContextFunction extends ContextFunction { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + Integer xInt = (Integer) context.get("x"); + Integer yInt = (Integer) context.get("y"); + int sum = xInt == null ? 0 : xInt.intValue(); + sum += yInt == null ? 0 : yInt.intValue(); + return Integer.valueOf(sum); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextDynamicTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextDynamicTest.java new file mode 100644 index 00000000000..4378096f02d --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextDynamicTest.java @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.internal.tests.contexts.inject.ObjectBasic; +import org.junit.Test; + +/** + * Tests for the basic context functionality + */ +public class ContextDynamicTest { + + + @Test + public void testReplaceFunctionWithStaticValue() { + IEclipseContext parent = EclipseContextFactory.create(); + IEclipseContext context = parent.createChild(); + assertNull(context.getLocal("bar")); + context.set("bar", "baz1"); + context.set("bar", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return "baz1"; + } + }); + parent.set("bar", "baz2"); + assertEquals("baz1", context.get("bar")); + context.set("bar", "baz3"); + assertEquals("baz3", context.get("bar")); + } + + /** + * Tests objects being added and removed from the context + */ + @Test + public synchronized void testAddRemove() { + Integer testInt = Integer.valueOf(123); + String testString = "abc"; + Double testDouble = Double.valueOf(1.23); + Float testFloat = Float.valueOf(12.3f); + Character testChar = Character.valueOf('v'); + + // create original context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Integer.class.getName(), testInt); + context.set(String.class.getName(), testString); + context.set(Double.class.getName(), testDouble); + context.set(Float.class.getName(), testFloat); + context.set(Character.class.getName(), testChar); + + ObjectBasic userObject = new ObjectBasic(); + ContextInjectionFactory.inject(userObject, context); + + // check basic injection + assertEquals(testString, userObject.injectedString); + assertEquals(testInt, userObject.getInt()); + assertEquals(context, userObject.context); + assertEquals(1, userObject.setMethodCalled); + assertEquals(1, userObject.setMethodCalled2); + assertEquals(testDouble, userObject.d); + assertEquals(testFloat, userObject.f); + assertEquals(testChar, userObject.c); + + // change value + Double testDouble2 = Double.valueOf(3.45); + Integer testInt2 = Integer.valueOf(123); + context.set(Double.class.getName(), testDouble2); + context.set(Integer.class.getName(), testInt2); + + // and check + assertEquals(testString, userObject.injectedString); + assertEquals(testInt2, userObject.getInt()); + assertEquals(context, userObject.context); + assertEquals(2, userObject.setMethodCalled); + assertEquals(1, userObject.setMethodCalled2); + assertEquals(testDouble2, userObject.d); + assertEquals(testFloat, userObject.f); + assertEquals(testChar, userObject.c); + + // remove element + context.remove(String.class.getName()); + context.remove(Character.class.getName()); + + // and check + assertNull(userObject.injectedString); + assertEquals(testInt2, userObject.getInt()); + assertEquals(context, userObject.context); + assertEquals(2, userObject.setMethodCalled); + assertEquals(2, userObject.setMethodCalled2); + assertEquals(testDouble2, userObject.d); + assertEquals(testFloat, userObject.f); + assertNull(userObject.c); + } + + /** + * Tests objects being added and removed from the context + */ + @Test + public synchronized void testParentAddRemove() { + Integer testInt = Integer.valueOf(123); + String testString = "abc"; + Double testDouble = Double.valueOf(1.23); + Float testFloat = Float.valueOf(12.3f); + Character testChar = Character.valueOf('v'); + + // create original context + IEclipseContext parentContext = EclipseContextFactory.create(); + parentContext.set(Integer.class.getName(), testInt); + parentContext.set(String.class.getName(), testString); + parentContext.set(Double.class.getName(), testDouble); + parentContext.set(Float.class.getName(), testFloat); + parentContext.set(Character.class.getName(), testChar); + IEclipseContext context = parentContext.createChild(); + + ObjectBasic userObject = new ObjectBasic(); + ContextInjectionFactory.inject(userObject, context); + + // check basic injection + assertEquals(testString, userObject.injectedString); + assertEquals(testInt, userObject.getInt()); + assertEquals(context, userObject.context); + assertEquals(1, userObject.setMethodCalled); + assertEquals(1, userObject.setMethodCalled2); + assertEquals(testDouble, userObject.d); + assertEquals(testFloat, userObject.f); + assertEquals(testChar, userObject.c); + + // change value + Double testDouble2 = Double.valueOf(3.45); + Integer testInt2 = Integer.valueOf(123); + context.set(Double.class.getName(), testDouble2); + context.set(Integer.class.getName(), testInt2); + + // and check + assertEquals(testString, userObject.injectedString); + assertEquals(testInt2, userObject.getInt()); + assertEquals(context, userObject.context); + assertEquals(2, userObject.setMethodCalled); + assertEquals(1, userObject.setMethodCalled2); + assertEquals(testDouble2, userObject.d); + assertEquals(testFloat, userObject.f); + assertEquals(testChar, userObject.c); + + // remove element + parentContext.remove(String.class.getName()); + parentContext.remove(Character.class.getName()); + + // and check + assertNull(userObject.injectedString); + assertEquals(testInt2, userObject.getInt()); + assertEquals(context, userObject.context); + assertEquals(2, userObject.setMethodCalled); + assertEquals(2, userObject.setMethodCalled2); + assertEquals(testDouble2, userObject.d); + assertEquals(testFloat, userObject.f); + assertNull(userObject.c); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionHigh.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionHigh.java new file mode 100644 index 00000000000..f229460b3e7 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionHigh.java @@ -0,0 +1,11 @@ +package org.eclipse.e4.core.internal.tests.contexts; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.IEclipseContext; + +public class ContextFunctionHigh extends ContextFunction { + @Override + public Object compute(IEclipseContext context) { + return "High"; + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionLow.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionLow.java new file mode 100644 index 00000000000..9e04f359f29 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ContextFunctionLow.java @@ -0,0 +1,11 @@ +package org.eclipse.e4.core.internal.tests.contexts; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.IEclipseContext; + +public class ContextFunctionLow extends ContextFunction { + @Override + public Object compute(IEclipseContext context) { + return "Low"; + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/DependenciesLeakTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/DependenciesLeakTest.java new file mode 100644 index 00000000000..93a81efed7c --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/DependenciesLeakTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stefan Mücke - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.internal.contexts.EclipseContext; +import org.junit.Before; +import org.junit.Test; + +@SuppressWarnings("restriction") +public class DependenciesLeakTest { + + final static String LEGACY_H_ID = "legacy::handler::"; //$NON-NLS-1$ + + static class HandlerSelectionFunction extends ContextFunction { + private final String commandId; + public HandlerSelectionFunction(String commandId) { + this.commandId = commandId; + } + @Override + public Object compute(IEclipseContext context, String contextKey) { + return context.get(LEGACY_H_ID + commandId); + } + @Override + public String toString() { + return "HandlerSelectionFunction [commandId=" + commandId + "]"; + } + } + + private IEclipseContext windowContext; + private IEclipseContext perspectiveContext; + private IEclipseContext partContext; + + @Before + public void setUp() throws Exception { + windowContext = EclipseContextFactory.create("Window"); + perspectiveContext = windowContext.createChild("Perspective"); + partContext = perspectiveContext.createChild("Part"); + } + + @Test + public void testBug() { + // register a handler + Object handler = ""; + windowContext.set("legacy::handler::foo.bar", handler); // fake activate legacy handler + windowContext.set("foo.bar", new HandlerSelectionFunction("foo.bar")); + + // there may be no listeners initially + assertNoListeners(windowContext); + assertNoListeners(perspectiveContext); + assertNoListeners(partContext); + + // cause a ValueComputation to be created + Object object = partContext.get("foo.bar"); + assertEquals(object, handler); + + // now invalidate the name; this should notify the part context + windowContext.set("foo.bar", null); + //windowContext.remove("foo.bar"); + + // all ValueComputation listeners must have been removed + assertNoListeners(windowContext); + assertNoListeners(perspectiveContext); + assertNoListeners(partContext); + } + + @Test + public void testInvalidateDirectly() { + windowContext.set("x", 42); + windowContext.set("y", 11); + windowContext.set("some.handler", new AddContextFunction()); + assertNoListeners(windowContext); + assertNoListeners(perspectiveContext); + assertNoListeners(partContext); + + Object object = partContext.get("some.handler"); + assertEquals(object, 53); + + windowContext.set("some.handler", null); // invalidate + assertNoListeners(windowContext); + assertNoListeners(perspectiveContext); + assertNoListeners(partContext); + } + + private void assertNoListeners(IEclipseContext context) { + EclipseContext c = (EclipseContext) context; + try { + assertTrue(c.getListeners().isEmpty()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java new file mode 100644 index 00000000000..fe70d2d3143 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/EclipseContextTest.java @@ -0,0 +1,397 @@ +/******************************************************************************* + * Copyright (c) 2009, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.eclipse.e4.core.di.IInjector; +import org.eclipse.e4.core.internal.contexts.EclipseContext; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.FrameworkUtil; + +@SuppressWarnings("restriction") +public class EclipseContextTest { + + private static class ComputedValueBar extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return context.get("bar"); + } + } + + private IEclipseContext context; + private IEclipseContext parentContext; + + private int runCounter; + + @Before + public void setUp() throws Exception { + parentContext = EclipseContextFactory.create("EclipseContextTest" + "-parent"); + context = parentContext.createChild("EclipseContextTest"); + runCounter = 0; + } + + @Test + public void testContainsKey() { + assertFalse("1.0", context.containsKey("function")); + assertFalse("1.1", context.containsKey("separator")); + + context.set("separator", ","); + assertTrue("2.1", context.containsKey("separator")); + + // null value is still a value + context.set("separator", null); + assertTrue("3.0", context.containsKey("separator")); + + context.remove("separator"); + assertFalse("4.0", context.containsKey("separator")); + } + + @Test + public void testGet() { + assertNull(context.get("foo")); + context.set("foo", "bar"); + assertEquals("bar", context.get("foo")); + assertNull(parentContext.get("foo")); + context.remove("foo"); + assertNull(context.get("foo")); + parentContext.set("foo", "bar"); + assertEquals("bar", context.get("foo")); + context.set("foo", new ComputedValueBar()); + assertNull(context.get("foo")); + context.set("bar", "baz"); + assertEquals("baz", context.get("foo")); + } + + @Test + public void testGetLocal() { + assertNull(context.getLocal("foo")); + context.set("foo", "bar"); + assertEquals("bar", context.getLocal("foo")); + assertNull(parentContext.getLocal("foo")); + context.remove("foo"); + assertNull(context.getLocal("foo")); + parentContext.set("foo", "bar"); + assertNull(context.getLocal("foo")); + context.set("foo", new ComputedValueBar()); + assertNull(context.getLocal("foo")); + context.set("bar", "baz"); + assertEquals("baz", context.getLocal("foo")); + } + + /** + * Tests that a context no longer looks up values from its parent when disposed. + */ + @Test + public void testDisposeRemovesParentReference() { + assertNull(context.get("foo")); + parentContext.set("foo", "bar"); + assertEquals("bar", context.get("foo")); + context.dispose(); + assertNull(context.get("foo")); + assertFalse(((EclipseContext) parentContext).getChildren().iterator().hasNext()); + } + + @Test + public void testDisposeClearsNotifyOnDisposalSet() { + ((EclipseContext) context).notifyOnDisposal(context -> runCounter++); + context.dispose(); + assertEquals(1, runCounter); + context.dispose(); + assertEquals(1, runCounter); + } + + /** + * Tests handling of a context function defined in the parent that uses values defined in the + * child + */ + @Test + public void testContextFunctionInParent() { + IEclipseContext parent = EclipseContextFactory.create(); + final IEclipseContext child = parent.createChild(); + parent.set("sum", new AddContextFunction()); + parent.set("x", Integer.valueOf(3)); + parent.set("y", Integer.valueOf(3)); + child.set("x", Integer.valueOf(1)); + child.set("y", Integer.valueOf(1)); + assertEquals(6, ((Integer) parent.get("sum")).intValue()); + assertEquals(2, ((Integer) child.get("sum")).intValue()); + child.set("x", Integer.valueOf(5)); + assertEquals(6, ((Integer) parent.get("sum")).intValue()); + assertEquals(6, ((Integer) child.get("sum")).intValue()); + child.remove("x"); + assertEquals(6, ((Integer) parent.get("sum")).intValue()); + assertEquals(4, ((Integer) child.get("sum")).intValue()); + parent.set("x", Integer.valueOf(10)); + assertEquals(13, ((Integer) parent.get("sum")).intValue()); + assertEquals(11, ((Integer) child.get("sum")).intValue()); + } + + @Test + public void testRunAndTrack() { + final Object[] value = new Object[1]; + context.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + runCounter++; + value[0] = context.get("foo"); + return true; + } + }); + assertEquals(1, runCounter); + assertEquals(null, value[0]); + context.set("foo", "bar"); + assertEquals(2, runCounter); + assertEquals("bar", value[0]); + context.remove("foo"); + assertEquals(3, runCounter); + assertEquals(null, value[0]); + context.set("foo", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return context.get("bar"); + } + }); + assertEquals(4, runCounter); + assertEquals(null, value[0]); + context.set("bar", "baz"); + assertEquals(5, runCounter); + assertEquals("baz", value[0]); + context.set("bar", "baf"); + assertEquals(6, runCounter); + assertEquals("baf", value[0]); + context.remove("bar"); + assertEquals(7, runCounter); + assertEquals(null, value[0]); + parentContext.set("bar", "bam"); + assertEquals(8, runCounter); + assertEquals("bam", value[0]); + } + + /** + * Tests registering a single run and track instance multiple times with the same context. + */ + @Test + public void testRegisterRunAndTrackTwice() { + final Object[] value = new Object[1]; + RunAndTrack runnable = new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + runCounter++; + value[0] = context.get("foo"); + return true; + } + }; + context.runAndTrack(runnable); + assertEquals(1, runCounter); + context.runAndTrack(runnable); + assertEquals(2, runCounter); + assertEquals(null, value[0]); + context.set("foo", "bar"); + assertEquals(3, runCounter); + assertEquals("bar", value[0]); + context.remove("foo"); + assertEquals(4, runCounter); + + } + + @Test + public void testRunAndTrackMultipleValues() { + IEclipseContext parent = EclipseContextFactory.create("ParentContext"); + final IEclipseContext child = parent.createChild("ChildContext"); + parent.set("parentValue", "x"); + child.set("childValue", "x"); + RunAndTrack runnable = new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + runCounter++; + if (runCounter < 2) { + child.get("childValue"); + return true; + } + if (runCounter < 3) { + child.get("parentValue"); + return true; + } + return false; + } + }; + child.runAndTrack(runnable); + assertEquals(1, runCounter); + child.set("childValue", "z"); + assertEquals(2, runCounter); + parent.set("parentValue", "z"); + assertEquals(3, runCounter); + } + + @Test + public void testModify() { + IEclipseContext grandParent = EclipseContextFactory.create(); + IEclipseContext parent = grandParent.createChild(); + IEclipseContext child = parent.createChild(); + + child.set("a", "a1"); + parent.set("b", "b2"); + grandParent.set("c", "c3"); + + child.declareModifiable("a"); + parent.declareModifiable("b"); + grandParent.declareModifiable("c"); + + // test pre-conditions + assertNull(grandParent.get("b")); + assertEquals("b2", parent.get("b")); + assertEquals("b2", child.get("b")); + assertNull(child.getLocal("b")); + + // modify value on the middle node via its child + child.modify("b", "abc"); + + assertFalse(grandParent.containsKey("b")); + assertEquals("abc", parent.get("b")); + assertEquals("abc", child.get("b")); + assertNull(child.getLocal("b")); + + // modifying non-exist values adds it to the context + child.modify("d", "123"); + + assertFalse(grandParent.containsKey("d")); + assertFalse(parent.containsKey("d")); + assertNull(parent.get("d")); + assertEquals("123", child.get("d")); + + // edge conditions: modify value in the top node + grandParent.modify("c", "cNew"); + assertTrue(grandParent.containsKey("c")); + assertEquals("cNew", grandParent.get("c")); + assertNull(parent.getLocal("c")); + assertNull(child.getLocal("c")); + assertTrue(child.containsKey("c")); + + // edge condition: modify value in the leaf node + child.modify("a", "aNew"); + assertTrue(child.containsKey("a")); + assertFalse(parent.containsKey("a")); + assertFalse(grandParent.containsKey("a")); + assertEquals("aNew", child.get("a")); + assertNull(parent.get("a")); + + // test access rules + child.set("aNo", "a1"); + parent.set("bNo", "b2"); + grandParent.set("cNo", "c3"); + + boolean exception = false; + try { + child.modify("bNo", "new"); + } catch (IllegalArgumentException e) { + exception = true; + } + assertTrue(exception); + + exception = false; + try { + grandParent.modify("cNo", "new"); + } catch (IllegalArgumentException e) { + exception = true; + } + assertTrue(exception); + + exception = false; + try { + child.modify("aNo", "new"); + } catch (IllegalArgumentException e) { + exception = true; + } + assertTrue(exception); + } + + @Test + public void testRemoveValueComputationOnDispose() { + IEclipseContext parent = EclipseContextFactory.create("ParentContext"); + IEclipseContext child = parent.createChild("ChildContext"); + parent.set("x", Integer.valueOf(1)); + parent.set("y", Integer.valueOf(1)); + parent.set("sum", new AddContextFunction()); + + child.get("sum"); + assertEquals(1, listenersCount(child)); + child.dispose(); + assertEquals(0, listenersCount(parent)); + } + + @Test + public void testNullInheritance() { + IEclipseContext parent = EclipseContextFactory.create("ParentContext"); + IEclipseContext child = parent.createChild("ChildContext"); + parent.set("x", Integer.valueOf(1)); + child.set("x", null); + assertNull(child.get("x")); + } + + @Test + public void testGetCFNotAValue() { + IEclipseContext context = EclipseContextFactory.create("ParentContext"); + context.set("x", new ContextFunction() { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + return IInjector.NOT_A_VALUE; + } + }); + + // must call several times as the underlying ValueComputation wrapper is + // created on the first time, but re-used for subsequent calls. + assertNull(context.get("x")); + assertNull(context.get("x")); + assertNull(context.get("x")); + context.dispose(); + } + + @Test + public void testGetCFNotAValueToParent() { + IEclipseContext parent = EclipseContextFactory.create("ParentContext"); + IEclipseContext child = parent.createChild(); + parent.set("x", Integer.valueOf(1)); + child.set("x", new ContextFunction() { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + return IInjector.NOT_A_VALUE; + } + }); + + assertEquals(1, child.get("x")); + parent.dispose(); + } + + @Test + public void testContextFunctionOrdering() { + IEclipseContext osgiContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()); + assertEquals("High",osgiContext.get("test.contextfunction.ranking")); + } + + private int listenersCount(IEclipseContext context) { + return ((EclipseContext) context).getListeners().size(); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/NeutralValueTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/NeutralValueTest.java new file mode 100644 index 00000000000..66ac56ba490 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/NeutralValueTest.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2021 Joerg Kubitz. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Joerg Kubitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.e4.core.internal.contexts.ConcurrentNeutralValueMap; +import org.eclipse.e4.core.internal.contexts.ConcurrentNeutralValueMap.Value; +import org.junit.Test; + +@SuppressWarnings("restriction") +public class NeutralValueTest { + + @Test + public void testConcurrentNeutralValueMap() { + ConcurrentNeutralValueMap map = new ConcurrentNeutralValueMap<>(Double.NaN); + map.put("nix", null); // modify + map.put("2", 2.0); // modify + map.put("3", 3.0); // modify + map.put("4", 4.0); // modify + map.put("garnix", null); // modify + assertTrue(map.containsKey("garnix")); + map.remove("garnix"); + + assertTrue(map.containsKey("nix")); + assertTrue(map.containsKey("2")); + assertFalse(map.containsKey("1")); + assertFalse(map.containsKey("garnix")); + + assertEquals(4, map.size()); + + assertFalse(map.isEmpty()); + + assertEquals(null, map.get("nix")); + assertEquals(null, map.get("1")); + assertEquals(Double.valueOf(2.0), map.get("2")); + assertEquals(Double.valueOf(3.0), map.get("3")); + assertEquals(Double.valueOf(4.0), map.get("4")); + + Set keys = new HashSet<>(); + Set values = new HashSet<>(); + map.forEach((k, v) -> keys.add(k)); + map.forEach((k, v) -> values.add(v)); + assertEquals(Set.of("nix", "2", "3", "4"), keys); + assertTrue(values.contains(null)); + assertTrue(values.contains(2.0)); + + assertTrue(map.getValue("nix").isPresent()); + assertFalse(map.getValue("1").isPresent()); + assertTrue(map.getValue("2").isPresent()); + assertTrue(map.getValue("3").isPresent()); + assertTrue(map.getValue("4").isPresent()); + + { + Value v = map.getValue("nix"); + assertTrue(v.isPresent()); + assertEquals(null, v.unwrapped()); + } + { + Value v = map.getValue("1"); + assertFalse(v.isPresent()); + assertEquals(null, v.unwrapped()); + } + { + Value v = map.getValue("2"); + assertTrue(v.isPresent()); + assertEquals(Double.valueOf(2.0), v.unwrapped()); + } + + { + Value v = map.putAndGetOld("5", 5555.0); // modify + assertFalse(v.isPresent()); + assertEquals(null, v.unwrapped()); + assertEquals(Double.valueOf(5555.0), map.get("5")); + } + { + Value v = map.putAndGetOld("5", 5.0); // modify + assertTrue(v.isPresent()); + assertEquals(Double.valueOf(5555.0), v.unwrapped()); + assertEquals(Double.valueOf(5.0), map.get("5")); + } + map.putIfAbsent("5", 5555.0); // modify + assertEquals(Double.valueOf(5.0), map.get("5")); + map.remove("5"); // modify + assertFalse(map.containsKey("5")); + + { + Value v = map.putAndGetOld("five", null); // modify + assertFalse(v.isPresent()); + assertEquals(null, v.unwrapped()); + assertEquals(null, map.get("five")); + } + { + Value v = map.putAndGetOld("five", 5.0); // modify + assertTrue(v.isPresent()); + assertEquals(null, v.unwrapped()); + assertEquals(Double.valueOf(5.0), map.get("five")); + } + { + map.putIfAbsent("five", null); // modify + Value v = map.getValue("five"); + assertTrue(v.isPresent()); + assertEquals(Double.valueOf(5.0), v.unwrapped()); + } + map.remove("five"); // modify + { + map.putIfAbsent("five", null); // modify + Value v = map.getValue("five"); + assertTrue(v.isPresent()); + assertEquals(null, v.unwrapped()); + } + map.remove("five"); // modify + assertFalse(map.containsKey("five")); + + map.clear(); // modify + assertEquals(0, map.size()); + assertTrue(map.isEmpty()); + } + + @Test + public void testToString() { + ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(); + map1.put("0", 0f); + map1.put("NULL", null); + map1.put("nothing", null); + map1.put("1", 1f); + map1.put("~2", 2.1f); + assertTrue(map1.toString().contains("0=0.0")); + assertTrue(map1.toString().contains("1=1.0")); + assertTrue(map1.toString().contains("~2=2.1")); + assertTrue(map1.toString().contains("NULL=null")); + assertTrue(map1.toString().contains("nothing=null")); + } + + @Test + public void testCustomToString() { + ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(Float.NaN); + map1.put("0", 0f); + map1.put("NULL", null); + assertTrue(map1.toString().contains("0=0.0")); + assertTrue(map1.toString().contains("NULL=NaN")); + } + + @Test + public void testEquals() { + { + ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(); + ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>(); + map1.put("0", 0f); + map1.put("NULL", null); + map2.put("NULL", null); + map2.put("0", 0f); + assertEquals(map1.hashCode(), map2.hashCode()); + assertEquals(map1, map2); + } + { + ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(); + ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>(); + map1.put("0", 0f); + map1.put("1", 1f); + map1.put("NULL", null); + map2.put("NULL", null); + map2.put("0", 0f); + assertNotEquals(map1.hashCode(), map2.hashCode()); + assertNotEquals(map1, map2); + } + { + ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(Float.NaN); + ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>(Float.NaN); + map1.put("0", 0f); + map1.put("NULL", null); + map2.put("NULL", null); + map2.put("0", 0f); + assertEquals(map1.hashCode(), map2.hashCode()); + assertEquals(map1, map2); + } + { + ConcurrentNeutralValueMap map1 = new ConcurrentNeutralValueMap<>(Float.NaN); + ConcurrentNeutralValueMap map2 = new ConcurrentNeutralValueMap<>(Float.NaN); + map1.put("0", 0f); + map1.put("1", 1f); + map1.put("NULL", null); + map2.put("NULL", null); + map2.put("0", 0f); + assertNotEquals(map1.hashCode(), map2.hashCode()); + assertNotEquals(map1, map2); + } + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java new file mode 100644 index 00000000000..3476abb11c2 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java @@ -0,0 +1,387 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass; +import org.junit.Test; + +/** + * Test for changing a context's parent. + */ +public class ReparentingTest { + + + /** + * Tests handling of a context function defined in the parent when the parent is changed to no + * longer have the function. + */ + @Test + public void testContextFunctionInParentRemove() { + IEclipseContext parent = EclipseContextFactory.create("parent"); + final IEclipseContext child = parent.createChild("child"); + parent.set("sum", new AddContextFunction()); + parent.set("x", Integer.valueOf(3)); + parent.set("y", Integer.valueOf(3)); + child.set("x", Integer.valueOf(1)); + child.set("y", Integer.valueOf(1)); + assertEquals(6, ((Integer) parent.get("sum")).intValue()); + assertEquals(2, ((Integer) child.get("sum")).intValue()); + child.setParent(EclipseContextFactory.create()); + assertEquals(6, ((Integer) parent.get("sum")).intValue()); + assertNull("Expected null but was: " + child.get("sum"), child.get("sum")); + } + + /** + * Tests handling of a context function defined in the parent when the parent is changed to have + * the function + */ + @Test + public void testContextFunctionInParentAdd() { + // setup + IEclipseContext parent = EclipseContextFactory.create(); + final IEclipseContext child = parent.createChild(); + child.set("x", Integer.valueOf(1)); + child.set("y", Integer.valueOf(1)); + assertEquals(null, parent.get("sum")); + assertEquals(null, child.get("sum")); + + // switch parent + IEclipseContext newParent = EclipseContextFactory.create(); + child.setParent(newParent); + newParent.set("sum", new AddContextFunction()); + assertEquals(0, ((Integer) newParent.get("sum")).intValue()); + assertEquals(2, ((Integer) child.get("sum")).intValue()); + + // changed values in parent shouldn't affect child + newParent.set("x", Integer.valueOf(3)); + newParent.set("y", Integer.valueOf(3)); + assertEquals(6, ((Integer) newParent.get("sum")).intValue()); + assertEquals(2, ((Integer) child.get("sum")).intValue()); + } + + @Test + public void testContextFunctionNullBecomeParent() { + final IEclipseContext child = EclipseContextFactory.create(); + child.set("sum", new AddContextFunction()); + assertEquals(0, ((Integer) child.get("sum")).intValue()); + IEclipseContext parent = EclipseContextFactory.create(); + parent.set("x", Integer.valueOf(3)); + parent.set("y", Integer.valueOf(3)); + child.setParent(parent); + assertEquals(6, ((Integer) child.get("sum")).intValue()); + + } + + @Test + public void testContextFunctionParentBecomeNull() { + IEclipseContext parent = EclipseContextFactory.create(); + final IEclipseContext child = parent.createChild(); + parent.set("x", Integer.valueOf(3)); + parent.set("y", Integer.valueOf(3)); + child.set("sum", new AddContextFunction()); + assertEquals(6, ((Integer) child.get("sum")).intValue()); + child.setParent(null); + assertEquals(0, ((Integer) child.get("sum")).intValue()); + } + + @Test + public void testContextFunctionSwitchParent() { + IEclipseContext parent = EclipseContextFactory.create(); + final IEclipseContext child = parent.createChild(); + parent.set("x", Integer.valueOf(3)); + parent.set("y", Integer.valueOf(3)); + child.set("sum", new AddContextFunction()); + assertEquals(6, ((Integer) child.get("sum")).intValue()); + IEclipseContext newParent = EclipseContextFactory.create(); + newParent.set("x", Integer.valueOf(1)); + newParent.set("y", Integer.valueOf(1)); + child.setParent(newParent); + assertEquals(2, ((Integer) child.get("sum")).intValue()); + } + + /** + * Tests a child switching from a null parent to a non-null parent. + */ + @Test + public void testRunAndTrackNullBecomesParent() { + final String[] value = new String[1]; + final IEclipseContext child = EclipseContextFactory.create(); + child.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + value[0] = (String) child.get("x"); + return true; + } + }); + assertEquals(null, value[0]); + IEclipseContext parent = EclipseContextFactory.create(); + parent.set("x", "newParent"); + child.setParent(parent); + assertEquals("newParent", value[0]); + } + + /** + * Tests a child switching from a non-null parent to a null parent. + */ + @Test + public void testRunAndTrackParentBecomeNull() { + final String[] value = new String[1]; + IEclipseContext parent = EclipseContextFactory.create(); + final IEclipseContext child = parent.createChild(); + parent.set("x", "oldParent"); + child.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + value[0] = (String) child.get("x"); + return true; + } + }); + assertEquals("oldParent", value[0]); + child.setParent(null); + assertNull(value[0]); + } + + @Test + public void testRunAndTrackSwitchParent() { + final String[] value = new String[1]; + IEclipseContext parent = EclipseContextFactory.create(); + final IEclipseContext child = parent.createChild(); + parent.set("x", "oldParent"); + child.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + value[0] = (String) child.get("x"); + return true; + } + }); + assertEquals("oldParent", value[0]); + IEclipseContext newParent = EclipseContextFactory.create(); + newParent.set("x", "newParent"); + child.setParent(newParent); + assertEquals("newParent", value[0]); + } + + /** + * Tests an object consuming simple values from a parent context, and a parent change causes a + * change in simple values. TODO: Still fails + */ + @Test + public void testInjectSwitchParent() { + + IEclipseContext oldParent = EclipseContextFactory.create(); + oldParent.set("String", "oldField"); + oldParent.set(String.class.getName(), "old"); + oldParent.set(Float.class.getName(), Float.valueOf(12.3f)); + IEclipseContext newParent = EclipseContextFactory.create(); + newParent.set("String", "newField"); + newParent.set(String.class.getName(), "new"); + newParent.set(Float.class.getName(), Float.valueOf(34.5f)); + IEclipseContext child = oldParent.createChild(); + + ObjectSuperClass object = new ObjectSuperClass(); + ContextInjectionFactory.inject(object, child); + assertEquals(1, object.setStringCalled); + assertEquals("old", object.getStringViaMethod()); + + child.setParent(newParent); + assertEquals("new", object.getStringViaMethod()); + assertEquals(2, object.setStringCalled); + + } + + /** + * Tests an object consuming services from a grandparent. A parent switch where the grandparent + * stays unchanged should ideally not cause changes for the injected object. + */ + @Test + public void testInjectSwitchParentSameGrandparent() { + IEclipseContext grandpa = EclipseContextFactory.create(); + grandpa.set("String", "field"); + grandpa.set(String.class.getName(), "s"); + grandpa.set(Float.class.getName(), Float.valueOf(12.3f)); + + IEclipseContext oldParent = grandpa.createChild(); + IEclipseContext newParent = grandpa.createChild(); + IEclipseContext child = oldParent.createChild(); + + ObjectSuperClass object = new ObjectSuperClass(); + ContextInjectionFactory.inject(object, child); + assertEquals(1, object.setStringCalled); + + child.setParent(newParent); + assertEquals(1, object.setStringCalled); + } + + @Test + public void testUpdateSameParent() { + final Boolean[] called = new Boolean[1] ; + IEclipseContext parent = EclipseContextFactory.create("parent"); + IEclipseContext newParent = EclipseContextFactory.create("newParent"); + IEclipseContext child = parent.createChild("child"); + parent.set("x", "1"); + newParent.set("x", "2"); + + child.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + called[0] = true; + context.get("x"); // creates a link + return true; + } + }); + called[0] = false; + + // make sure setting parent to the same value does not trigger updates + child.setParent(parent); + assertFalse(called[0]); + + child.setParent(newParent); + assertTrue(called[0]); + } + + static public class TestService { + // empty + } + + @Test + public void testUpdateSameParentCalculated() { + final int[] testServiceCount = new int[1]; + testServiceCount[0] = 0; + IEclipseContext parentContext = EclipseContextFactory.create("parent"); + parentContext.set(TestService.class.getName(), new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + testServiceCount[0]++; + return ContextInjectionFactory.make(TestService.class, context); + } + }); + + IEclipseContext childContext = parentContext.createChild("child"); + childContext.get(TestService.class); + assertEquals(1, testServiceCount[0]); + + childContext.setParent(childContext.getParent()); + assertEquals(1, testServiceCount[0]); + } + + @Test + public void testBug468048_contextFunction() { + IEclipseContext p1 = EclipseContextFactory.create("parent1"); + p1.set("sample", new ContextFunction() { + @Override + public Object compute(IEclipseContext context) { + return Integer.valueOf(1); + } + }); + + IEclipseContext p2 = EclipseContextFactory.create("parent2"); + p2.set("sample", new ContextFunction() { + @Override + public Object compute(IEclipseContext context) { + return Integer.valueOf(2); + } + }); + + final IEclipseContext intermed = p1.createChild("intermed"); + + final IEclipseContext leaf = intermed.createChild("leaf"); + assertEquals(Integer.valueOf(1), leaf.get("sample")); + intermed.setParent(p2); + assertEquals(Integer.valueOf(2), leaf.get("sample")); + } + + @Test + public void testBug468048_injection() { + IEclipseContext p1 = EclipseContextFactory.create("parent1"); + p1.set("sample", new ContextFunction() { + @Override + public Object compute(IEclipseContext context) { + return Integer.valueOf(1); + } + }); + + IEclipseContext p2 = EclipseContextFactory.create("parent2"); + p2.set("sample", new ContextFunction() { + @Override + public Object compute(IEclipseContext context) { + return Integer.valueOf(2); + } + }); + + final IEclipseContext intermed = p1.createChild("intermed"); + + final IEclipseContext leaf = intermed.createChild("leaf"); + Bug468048 b = ContextInjectionFactory.make(Bug468048.class, leaf); + + assertEquals(Integer.valueOf(1), b.sample); + intermed.setParent(p2); + assertEquals(Integer.valueOf(2), b.sample); + } + + @Test + public void testContextFunctionSwitchParent_2() { + IEclipseContext superParent = EclipseContextFactory.create("root"); + + IEclipseContext parent = superParent.createChild("parent-1"); + final IEclipseContext child = parent.createChild("child-1"); + child.set("x", Integer.valueOf(3)); + child.set("y", Integer.valueOf(3)); + + superParent.set("sum", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + if (context != child) { + throw new IllegalStateException("Invalid context state"); + } + return (Integer) context.get("x") + (Integer) context.get("y"); + } + }); + + Bug541498 bug = ContextInjectionFactory.make(Bug541498.class, child); + assertEquals(Integer.valueOf(6), bug.value); + + IEclipseContext newParent = superParent.createChild("parent-2"); + child.setParent(newParent); + + assertEquals(Integer.valueOf(6), bug.value); + } + + public static class Bug541498 { + @Inject + @Named("sum") + Integer value; + } + + public static class Bug468048 { + @Inject + @Named("sample") + public Integer sample; + + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/RunAndTrackTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/RunAndTrackTest.java new file mode 100644 index 00000000000..96eded7070b --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/RunAndTrackTest.java @@ -0,0 +1,433 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.junit.After; +import org.junit.Test; + +/** + * Tests for {@link org.eclipse.e4.core.RunAndTrack.context.IRunAndTrack}. + */ +public class RunAndTrackTest { + + private static final class TestRAT extends RunAndTrack { + + + private final String varName; + private Object varValue; + private int calls = 0; + + public TestRAT(String varName) { + this.varName = varName; + } + + @Override + public boolean changed(IEclipseContext context) { + ++calls; + varValue = context.get(varName); + return true; + } + + public int getCalls() { + return calls; + } + + public Object getVarValue() { + return varValue; + } + + public void resetCalls() { + calls = 0; + } + + } + + private static class ActivePartLookupFunction extends ContextFunction { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + IEclipseContext childContext = (IEclipseContext) context.getLocal(ACTIVE_CHILD); + if (childContext != null) { + return childContext.get(ACTIVE_PART); + } + return context.get(INTERNAL_LOCAL_PART); + } + + } + + static final String ACTIVE_CHILD = "activeChild"; + + static final String ACTIVE_PART = "activePart"; + + static final String ACTIVE_PART_ID = "activePartId"; + + static final String INTERNAL_LOCAL_PART = "localPart"; + + private final List createdContexts = new ArrayList<>(); + + private IEclipseContext createContext(IEclipseContext parentContext, String level) { + IEclipseContext childContext = parentContext.createChild(level); + createdContexts.add(childContext); + return childContext; + } + + private IEclipseContext getGlobalContext() { + IEclipseContext serviceContext = EclipseContextFactory + .getServiceContext(CoreTestsActivator.getDefault().getBundleContext()); + // global initialization and setup, usually done by workbench + IEclipseContext appContext = createContext(serviceContext, "globalContext"); + + appContext.set("globalContext", appContext); + + return appContext; + } + + private IEclipseContext[] createNextLevel(IEclipseContext parent, String prefix, int num) { + assertTrue(num > 0); + IEclipseContext[] contexts = new IEclipseContext[num]; + for (int i = 0; i < num; i++) { + contexts[i] = createContext(parent, prefix + i); + contexts[i].set(INTERNAL_LOCAL_PART, prefix + i); + } + parent.set(ACTIVE_CHILD, contexts[0]); + return contexts; + } + + @After + public void tearDown() throws Exception { + for (IEclipseContext context : createdContexts) { + context.dispose(); + } + createdContexts.clear(); + } + + @Test + public void testActiveChain() throws Exception { + final IEclipseContext workbenchContext = getGlobalContext(); + workbenchContext.set("activePart", new ActivePartLookupFunction()); + final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1); + createNextLevel(windows[0], "part", 2); + assertEquals("part0", workbenchContext.get(ACTIVE_PART)); + } + + @Test + public void testActiveChange() throws Exception { + final IEclipseContext workbenchContext = getGlobalContext(); + workbenchContext.set("activePart", new ActivePartLookupFunction()); + final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1); + final IEclipseContext[] parts = createNextLevel(windows[0], "part", 2); + assertEquals("part0", workbenchContext.get(ACTIVE_PART)); + + windows[0].set(ACTIVE_CHILD, parts[1]); + assertEquals("part1", workbenchContext.get(ACTIVE_PART)); + } + + /** + * There was a failing scenario in the legacy workbench support. This captures the hierarchy and + * function (without any workbench level references). It should be updated when we figure out + * the failing scenario :-) + * + * @throws Exception + */ + @Test + public void testRunAndTrackComplex() throws Exception { + final IEclipseContext workbenchContext = getGlobalContext(); + workbenchContext.set("activePart", new ActivePartLookupFunction()); + final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1); + windows[0].runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + final Object part = windows[0].get(ACTIVE_PART); + windows[0].set(ACTIVE_PART_ID, part); + return true; + } + + @Override + public String toString() { + return ACTIVE_PART_ID; + } + }); + + final IEclipseContext[] mainSashes = createNextLevel(windows[0], "mainSash", 2); + createNextLevel(mainSashes[1], "editorArea", 1); + final IEclipseContext[] viewSashes = createNextLevel(mainSashes[0], "viewSashes", 2); + + // create package explorer stack + final IEclipseContext[] packageStack = createNextLevel(viewSashes[0], "packageStack", 1); + final IEclipseContext[] packageViews = createNextLevel(packageStack[0], "packageViews", 3); + assertNotNull(packageViews); + assertEquals("packageViews0", windows[0].get(ACTIVE_PART)); + assertEquals("packageViews0", windows[0].get(ACTIVE_PART_ID)); + + // create problems stack + final IEclipseContext[] problemsStack = createNextLevel(viewSashes[1], "problemsStack", 1); + final IEclipseContext[] problemsViews = createNextLevel(problemsStack[0], "problemViews", 5); + assertNotNull(problemsViews); + assertEquals("packageViews0", windows[0].get(ACTIVE_PART)); + assertEquals("packageViews0", windows[0].get(ACTIVE_PART_ID)); + + assertEquals("problemViews0", problemsStack[0].get(ACTIVE_PART)); + // this won't change since it is a "runAndTrack" at the window context + // level + assertEquals("packageViews0", problemsStack[0].get(ACTIVE_PART_ID)); + + // set the "problems view" active, propagating the information up + // the active chain. + problemsStack[0].set(ACTIVE_CHILD, problemsViews[0]); + viewSashes[1].set(ACTIVE_CHILD, problemsStack[0]); + mainSashes[0].set(ACTIVE_CHILD, viewSashes[1]); + windows[0].set(ACTIVE_CHILD, mainSashes[0]); + workbenchContext.set(ACTIVE_CHILD, windows[0]); + + assertEquals("problemViews0", windows[0].get(ACTIVE_PART)); + assertEquals("problemViews0", windows[0].get(ACTIVE_PART_ID)); + + assertEquals("packageViews0", packageStack[0].get(ACTIVE_PART)); + assertEquals("problemViews0", packageStack[0].get(ACTIVE_PART_ID)); + } + + @Test + public void testRunAndTrackSimple() throws Exception { + final IEclipseContext workbenchContext = getGlobalContext(); + workbenchContext.set("activePart", new ActivePartLookupFunction()); + final IEclipseContext[] windows = createNextLevel(workbenchContext, "window", 1); + windows[0].runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + final Object part = windows[0].get(ACTIVE_PART); + windows[0].set(ACTIVE_PART_ID, part); + return true; + } + + @Override + public String toString() { + return ACTIVE_PART_ID; + } + }); + + final IEclipseContext[] parts = createNextLevel(windows[0], "part", 2); + assertEquals("part0", workbenchContext.get(ACTIVE_PART)); + assertEquals("part0", windows[0].get(ACTIVE_PART_ID)); + + windows[0].set(ACTIVE_CHILD, parts[1]); + assertEquals("part1", windows[0].get(ACTIVE_PART)); + assertEquals("part1", windows[0].get(ACTIVE_PART_ID)); + } + + /** + * Test how a RAT responds to a change hidden from it; changed value is == to child value + */ + @Test + public void testSetHiddenValueToChildObject() { + final String newRootValue = "child"; + + doHiddenValueChangeTest(newRootValue); + } + + /** + * Test how a RAT responds to a change hidden from it; changed value is != to child value + */ + @Test + public void testSetHiddenValueToDifferentObject() { + final String newRootValue = "other"; + + doHiddenValueChangeTest(newRootValue); + } + + /** + * Test how a RAT responds to a change hidden from it; changed value is != to child value (but is .equals()) + */ + @Test + public void testSetHiddenValueToObjectEqualToChild() { + // avoid compiler's pushing all my strings into a single string pool + final String newRootValue = new String("child"); + + doHiddenValueChangeTest(newRootValue); + } + + /** + * Test how a RAT responds to a change hidden from it; changed value is == to root value + */ + @Test + public void testSetHiddenValueToRootObject() { + final String newRootValue = "root"; + + doHiddenValueChangeTest(newRootValue); + } + + /** + * Test how a RAT responds to a change hidden from it; changed value is != to root value (but is .equals()) + */ + @Test + public void testSetHiddenValueToEqualRootObject() { + // avoid compiler's pushing all my strings into a single string pool + final String newRootValue = new String("root"); + + doHiddenValueChangeTest(newRootValue); + } + + /** + * Test how a RAT responds to a change hidden from it; changed value is == to root value + */ + @Test + public void testSetHiddenValueToNull() { + final String newRootValue = null; + + doHiddenValueChangeTest(newRootValue); + } + + /** + * Perform a hidden value test that verifies that the test RAT does not run, and + * that has last seen the initial value in the child context (namely "child"). + * @param newRootValue the new value for the variable 'v' in the root context. + * @see #doHiddenValueChangeTest(ITestAction, Object, int) + */ + void doHiddenValueChangeTest(final String newRootValue) { + doHiddenValueChangeTest((IEclipseContext root, String var) -> { + root.set(var, newRootValue); + }, "child", 0); + } + + /** + * Interface defining function + * + */ + private interface ITestAction { + + void execute(IEclipseContext root, String var); + + } + /** + * Create a two level hierarchy of contexts, each defining a variable 'v' with values 'root' and 'child', respectively. + * Create and install a RAT on the child context that is dependent on 'v'. + * Run testAction. + * Tests whether the RAT ran the expected number of times, + * and tests last value of 'v' that the RAT saw. + * @param testAction the context action to perform as part of the test + * @param expectedValue the expected last value of variable 'v' that the RAT saw. + * @param expectedRATCalls the expected number of times the RAT was run in response to testAction + */ + void doHiddenValueChangeTest(ITestAction testAction, Object expectedValue, int expectedRATCalls) { + final IEclipseContext root = getGlobalContext(); + final IEclipseContext child = root.createChild("child"); + + root.set("v", "root"); + child.set("v", "child"); + final TestRAT testRAT = new TestRAT("v"); + + // install the RAT + child.runAndTrack(testRAT); + assertEquals("child", testRAT.getVarValue()); + assertEquals(1, testRAT.getCalls()); + + testRAT.resetCalls(); + // set the new root value + testAction.execute(root, "v"); + assertEquals(expectedValue, testRAT.getVarValue()); + assertEquals(expectedRATCalls, testRAT.getCalls()); + } + + /** + * Test that a variable change in a context hidden from a RAT in + * a child context does not re-run the RAT. + */ + @Test + public void testRemoveHiddenVariable() { + doHiddenValueChangeTest((IEclipseContext root, String var) -> { + root.remove(var); + }, "child", 0); + } + + /** + * Test that setting a context variable to it's existing + * value does not re-run dependent RATs + */ + @Test + public void testSetContextVarToSameObject() { + doSingleContextChangeTest((IEclipseContext root, String var) -> { + root.set(var, "root"); + }, "root", 0); + } + + /** + * Test that setting a context variable to a value that {@link Object#equals(Object) equals} + * the current value, but is same object DOES re-run dependent RATs. + */ + @Test + public void testSetContextVarToEqualObject() { + doSingleContextChangeTest((IEclipseContext root, String var) -> { + root.set(var, new String("root")); + }, "root", 1); + } + + /** + * Test that setting a context variable to a different object, not equal to the + * current value re-runs dependent RATs. + */ + @Test + public void testSetContextVarToOtherObject() { + doSingleContextChangeTest((IEclipseContext root, String var) -> { + root.set(var, "other"); + }, "other", 1); + } + + /** + * Test that removing a context variable re-runs dependent RATs. + */ + @Test + public void testRemoveContextVar() { + doSingleContextChangeTest((root, var) -> root.remove(var), null, 1); + + } + + /** + * Creates a context, sets a variable 'v' to "root", creates a RAT dependent on 'v' in the context, + * then executes testAction and tests whether the RAT ran the expected number of times, + * and tests last value of 'v' that the RAT saw. + * @param testAction the context action to perform as part of the test + * @param expectedValue the expected last value of variable 'v' that the RAT saw. + * @param expectedRATCalls the expected number of times the RAT was run in response to testAction + */ + private void doSingleContextChangeTest(ITestAction testAction, Object expectedValue, int expectedRATCalls) { + final IEclipseContext root = getGlobalContext(); + + root.set("v", "root"); + + final TestRAT testRAT = new TestRAT("v"); + // install the RAT + root.runAndTrack(testRAT); + assertEquals("root", testRAT.getVarValue()); + assertEquals(1, testRAT.getCalls()); + + testRAT.resetCalls(); + testAction.execute(root, "v"); + assertEquals(expectedRATCalls, testRAT.getCalls()); + assertEquals(expectedValue, testRAT.getVarValue()); + + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/StrongIterableTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/StrongIterableTest.java new file mode 100644 index 00000000000..3e86a21f46f --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/StrongIterableTest.java @@ -0,0 +1,273 @@ +/******************************************************************************* + * Copyright (c) 2021 Joerg Kubitz. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Joerg Kubitz - initial API and implementation + *******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.function.Supplier; +import java.util.stream.StreamSupport; + +import org.eclipse.e4.core.internal.contexts.StrongIterable; +import org.junit.Test; + +@SuppressWarnings("restriction") +public class StrongIterableTest { + + @Test + public void testStrongIterableDeque() { + testStrongIterable(ConcurrentLinkedDeque::new); + } + + @Test + public void testStrongIterableQueue() { + testStrongIterable(ConcurrentLinkedQueue::new); + } + + void testStrongIterable(Supplier>> constructor) { + testIterate(constructor.get()); + testRemoveWhileIterate(constructor.get()); + testRemoveAll(constructor.get()); + testRemoveByClear(constructor.get()); + testNextWithoutHasNext(constructor.get()); + } + + private void testNextWithoutHasNext(Collection> iterable) { + WeakReference EMPTY1 = new WeakReference<>(null); + WeakReference EMPTY2 = new WeakReference<>(null); + WeakReference ONE = new WeakReference<>(1); + WeakReference TWO = new WeakReference<>(2); + WeakReference THREE = new WeakReference<>(3); + iterable.add(EMPTY1); // ignored + iterable.add(ONE); + iterable.add(TWO); + iterable.add(EMPTY2); // ignored + iterable.add(THREE); + StrongIterable strongIterable = new StrongIterable<>(iterable); + { + Iterator i = strongIterable.iterator(); + assertEquals(1, i.next().intValue()); + assertEquals(2, i.next().intValue()); + assertEquals(3, i.next().intValue()); + try { + i.next(); + } catch (NoSuchElementException e) { + assertNotNull(e); + } + } + { + Iterator i = strongIterable.iterator(); + assertEquals(1, i.next().intValue()); + assertEquals(3L, count(strongIterable)); + assertEquals(3L, poorMansCount(strongIterable)); + i.remove(); + assertEquals(2L, count(strongIterable)); + assertEquals(2L, poorMansCount(strongIterable)); + assertEquals(2, i.next().intValue()); + i.remove(); + assertEquals(3, i.next().intValue()); + i.remove(); + try { + i.next(); + } catch (NoSuchElementException e) { + assertNotNull(e); + } + } + assertEquals(0L, count(strongIterable)); + assertEquals(0L, poorMansCount(strongIterable)); + } + + void testRemoveWhileIterate(Collection> iterable) { + WeakReference ONE = new WeakReference<>(1); + WeakReference TWO = new WeakReference<>(2); + WeakReference THREE = new WeakReference<>(3); + iterable.add(ONE); + iterable.add(TWO); + iterable.add(THREE); + + assertEquals(3L, poorMansCount(iterable)); + StrongIterable strongIterable = new StrongIterable<>(iterable); + { + Iterator i = strongIterable.iterator(); + assertEquals(3L, count(strongIterable)); + assertEquals(3L, poorMansCount(strongIterable)); + + assertTrue(i.hasNext()); + assertEquals(1, i.next().intValue()); + assertTrue(i.hasNext()); + assertEquals(2, i.next().intValue()); + i.remove(); // remove TWO + assertEquals(2L, count(strongIterable)); + assertEquals(2L, poorMansCount(strongIterable)); + assertTrue(i.hasNext()); + assertEquals(3, i.next().intValue()); + i.remove(); // remove THREE + assertEquals(1L, count(strongIterable)); + assertEquals(1L, poorMansCount(strongIterable)); + assertFalse(i.hasNext()); + try { + i.next(); + } catch (NoSuchElementException e) { + assertNotNull(e); + } + } + } + + void testRemoveAll(Collection> iterable) { + WeakReference ONE = new WeakReference<>(1); + WeakReference TWO = new WeakReference<>(2); + WeakReference THREE = new WeakReference<>(3); + iterable.add(ONE); + iterable.add(TWO); + iterable.add(THREE); + + StrongIterable strongIterable = new StrongIterable<>(iterable); + assertEquals(3L, count(strongIterable)); + for (Iterator i = strongIterable.iterator(); i.hasNext();) { + i.next(); + i.remove(); + } + assertEquals(0L, count(strongIterable)); + assertEquals(0L, poorMansCount(strongIterable)); + } + + void testRemoveByClear(Collection> iterable) { + WeakReference ONE = new WeakReference<>(1); + WeakReference TWO = new WeakReference<>(2); + WeakReference THREE = new WeakReference<>(3); + iterable.add(ONE); + iterable.add(TWO); + iterable.add(THREE); + + StrongIterable strongIterable = new StrongIterable<>(iterable); + assertEquals(3L, count(strongIterable)); + for (Reference ref : iterable) { + ref.clear(); + } + assertEquals(0L, count(strongIterable)); + } + + void testIterate(Collection> iterable) { + WeakReference EMPTY1 = new WeakReference<>(null); + WeakReference EMPTY2 = new WeakReference<>(null); + WeakReference ONE = new WeakReference<>(1); + WeakReference TWO = new WeakReference<>(2); + WeakReference THREE = new WeakReference<>(3); + iterable.add(EMPTY1); // ignored + iterable.add(ONE); + iterable.add(TWO); + iterable.add(EMPTY2); // ignored + iterable.add(THREE); + + StrongIterable strongIterable = new StrongIterable<>(iterable); + { + Iterator i = strongIterable.iterator(); + assertEquals(3L, count(strongIterable)); + assertTrue(i.hasNext()); + assertEquals(1, i.next().intValue()); + assertTrue(i.hasNext()); + assertEquals(2, i.next().intValue()); + assertTrue(i.hasNext()); + assertEquals(3, i.next().intValue()); + assertFalse(i.hasNext()); + try { + i.next(); + } catch (NoSuchElementException e) { + assertNotNull(e); + } + } + for (Integer strong : strongIterable) { + assertNotNull(strong); + } + + assertTrue(iterable.remove(TWO)); // remove + + for (Integer strong : strongIterable) { + assertNotNull(strong); + } + { + Iterator i = strongIterable.iterator(); + assertEquals(2L, count(strongIterable)); + assertTrue(i.hasNext()); + assertEquals(1, i.next().intValue()); + assertTrue(i.hasNext()); + assertEquals(3, i.next().intValue()); + assertFalse(i.hasNext()); + try { + i.next(); + } catch (NoSuchElementException e) { + assertNotNull(e); + } + } + + ONE.clear(); // remove on iterate + + { + Iterator i = strongIterable.iterator(); + assertEquals(1L, count(strongIterable)); + assertTrue(i.hasNext()); + assertEquals(3, i.next().intValue()); + assertFalse(i.hasNext()); + try { + i.next(); + } catch (NoSuchElementException e) { + assertNotNull(e); + } + for (Integer strong : strongIterable) { + assertNotNull(strong); + } + } + + THREE.clear(); // remove on iterate + + { + Iterator i = strongIterable.iterator(); + assertEquals(0L, count(strongIterable)); + assertFalse(i.hasNext()); + try { + i.next(); + } catch (NoSuchElementException e) { + assertNotNull(e); + } + for (Integer strong : strongIterable) { + assertNotNull(strong); + } + } + } + + private long count(Iterable i) { + return StreamSupport.stream(i.spliterator(), false).count(); + } + + private long poorMansCount(Iterable i) { + long count = -1; + try { + for (Iterator it = i.iterator();; it.next()) { + count++; + } + } catch (NoSuchElementException expected) { + } + return count; + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java new file mode 100644 index 00000000000..9b83bdcb0e1 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java @@ -0,0 +1,221 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.Active; +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +public class ActivationInjectionTest { + + static public class TestRAT extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + IEclipseContext activeContext = context.getActiveLeaf(); + // returns name of the context + return "_" + activeContext.get("debugString") + "_"; + } + } + + static public class TestObject { + + public String name; + + @Inject + public TestObject() { + // + } + + @Inject + public void setActiveContextName(@Named("testRAT") String name) { + this.name = name; + } + } + + @Test + public void testContextActivation() { + IEclipseContext rootContext = EclipseContextFactory.create("root"); + rootContext.set("testRAT", new TestRAT()); + + IEclipseContext child1 = rootContext.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + IEclipseContext child12 = child1.createChild("child12"); + + IEclipseContext child2 = rootContext.createChild("child2"); + IEclipseContext child21 = child2.createChild("child21"); + IEclipseContext child22 = child2.createChild("child22"); + + TestObject testObject = ContextInjectionFactory.make(TestObject.class, rootContext); + + child12.activateBranch(); + assertEquals(child12, rootContext.getActiveLeaf()); + assertEquals("_child12_", testObject.name); + + child21.activateBranch(); + assertEquals(child21, rootContext.getActiveLeaf()); + assertEquals("_child21_", testObject.name); + + child21.deactivate(); + assertEquals(child2, rootContext.getActiveLeaf()); + assertEquals("_child2_", testObject.name); + + child22.activateBranch(); + assertEquals(child22, rootContext.getActiveLeaf()); + assertEquals("_child22_", testObject.name); + + child11.activateBranch(); + assertEquals(child11, rootContext.getActiveLeaf()); + assertEquals("_child11_", testObject.name); + + child11.deactivate(); + assertEquals(child1, rootContext.getActiveLeaf()); + assertEquals("_child1_", testObject.name); + + child1.dispose(); + child2.activateBranch(); + assertEquals(child22, rootContext.getActiveLeaf()); + assertEquals("_child22_", testObject.name); + } + + static public class TestObjectInject { + public String name; + @Inject + public TestObjectInject() { + // + } + @Inject + public void setActiveContextName(@Active @Named("debugString") String name) { + this.name = "_" + name + "_"; + } + } + + @Test + public void testActivationInjection() { + IEclipseContext rootContext = EclipseContextFactory.create("root"); + + IEclipseContext child1 = rootContext.createChild("child1"); + IEclipseContext child11 = child1.createChild("child11"); + IEclipseContext child12 = child1.createChild("child12"); + + IEclipseContext child2 = rootContext.createChild("child2"); + IEclipseContext child21 = child2.createChild("child21"); + IEclipseContext child22 = child2.createChild("child22"); + + TestObjectInject testObject = ContextInjectionFactory.make(TestObjectInject.class, rootContext); + + child12.activateBranch(); + assertEquals(child12, rootContext.getActiveLeaf()); + assertEquals("_child12_", testObject.name); + + child21.activateBranch(); + assertEquals(child21, rootContext.getActiveLeaf()); + assertEquals("_child21_", testObject.name); + + child21.deactivate(); + assertEquals(child2, rootContext.getActiveLeaf()); + assertEquals("_child2_", testObject.name); + + child22.activateBranch(); + assertEquals(child22, rootContext.getActiveLeaf()); + assertEquals("_child22_", testObject.name); + + child11.activateBranch(); + assertEquals(child11, rootContext.getActiveLeaf()); + assertEquals("_child11_", testObject.name); + + child11.deactivate(); + assertEquals(child1, rootContext.getActiveLeaf()); + assertEquals("_child1_", testObject.name); + + child1.dispose(); + child2.activateBranch(); + assertEquals(child22, rootContext.getActiveLeaf()); + assertEquals("_child22_", testObject.name); + } + + static public class TestInject { + @Optional @Inject @Active + public Integer number; + } + + @Test + public void testInjection() { + IEclipseContext rootContext = EclipseContextFactory.create("root"); + + IEclipseContext child1 = rootContext.createChild("child1"); + child1.set(Integer.class, Integer.valueOf(1)); + IEclipseContext child11 = child1.createChild("child11"); + child11.set(Integer.class, Integer.valueOf(2)); + IEclipseContext child12 = child1.createChild("child12"); + child12.set(Integer.class, Integer.valueOf(3)); + + IEclipseContext child2 = rootContext.createChild("child2"); + child2.set(Integer.class, Integer.valueOf(4)); + IEclipseContext child21 = child2.createChild("child21"); + child21.set(Integer.class, Integer.valueOf(5)); + IEclipseContext child22 = child2.createChild("child22"); + child22.set(Integer.class, Integer.valueOf(6)); + + TestInject testObjectRoot = ContextInjectionFactory.make(TestInject.class, rootContext); + TestInject testObjectChild1 = ContextInjectionFactory.make(TestInject.class, child1); + TestInject testObjectChild2 = ContextInjectionFactory.make(TestInject.class, child2); + + child12.activateBranch(); + assertEquals(Integer.valueOf(3), testObjectRoot.number); + assertEquals(Integer.valueOf(3), testObjectChild1.number); + assertEquals(Integer.valueOf(4), testObjectChild2.number); + + child21.activateBranch(); + assertEquals(Integer.valueOf(5), testObjectRoot.number); + assertEquals(Integer.valueOf(3), testObjectChild1.number); + assertEquals(Integer.valueOf(5), testObjectChild2.number); + + child21.deactivate(); + assertEquals(Integer.valueOf(4), testObjectRoot.number); + assertEquals(Integer.valueOf(3), testObjectChild1.number); + assertEquals(Integer.valueOf(4), testObjectChild2.number); + + child22.activateBranch(); + assertEquals(Integer.valueOf(6), testObjectRoot.number); + assertEquals(Integer.valueOf(3), testObjectChild1.number); + assertEquals(Integer.valueOf(6), testObjectChild2.number); + + child11.activateBranch(); + assertEquals(Integer.valueOf(2), testObjectRoot.number); + assertEquals(Integer.valueOf(2), testObjectChild1.number); + assertEquals(Integer.valueOf(6), testObjectChild2.number); + + child11.deactivate(); + assertEquals(Integer.valueOf(1), testObjectRoot.number); + assertEquals(Integer.valueOf(1), testObjectChild1.number); + assertEquals(Integer.valueOf(6), testObjectChild2.number); + + child1.dispose(); + child2.activateBranch(); + assertEquals(Integer.valueOf(6), testObjectRoot.number); + assertEquals(Integer.valueOf(6), testObjectChild2.number); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java new file mode 100644 index 00000000000..4aaf0282406 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java @@ -0,0 +1,367 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +import junit.framework.AssertionFailedError; +/** + * Tests for the basic context injection functionality + */ +public class AnnotationsInjectionTest { + + + @Test + public void testContextSetOneArg() { + class TestData { + // empty + } + class Injected { + int contextSetCalled = 0; + int setMethodCalled = 0; + + public TestData value; + + @Inject + public void settings(IEclipseContext context) { + contextSetCalled++; + } + + @Inject + public void injectedMethod(@Named("testing123") TestData arg) { + setMethodCalled++; + value = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing123", methodValue); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + assertEquals(1, object.setMethodCalled); + assertEquals(1, object.contextSetCalled); + + TestData methodValue2 = new TestData(); + context.set("testing123", methodValue2); + assertEquals(2, object.setMethodCalled); + assertEquals(methodValue2, object.value); + assertEquals(1, object.contextSetCalled); + } + + @Test + public void testPostConstruct() { + class TestData { + // empty + } + class Injected { + int postConstructCalled = 0; + int setMethodCalled = 0; + public TestData value; + + @PostConstruct + public void init() { + postConstructCalled++; + } + + @Inject + public void setData(TestData arg) { + setMethodCalled++; + value = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set(TestData.class, methodValue); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + assertEquals(1, object.setMethodCalled); + assertEquals(1, object.postConstructCalled); + + TestData methodValue2 = new TestData(); + context.set(TestData.class, methodValue2); + assertEquals(2, object.setMethodCalled); + assertEquals(1, object.postConstructCalled); + assertEquals(methodValue2, object.value); + } + + /** + * Tests basic context injection + */ + @Test + public synchronized void testInjection() { + Integer testInt = Integer.valueOf(123); + String testString = "abc"; + Double testDouble = Double.valueOf(1.23); + Float testFloat = Float.valueOf(12.3f); + Character testChar = Character.valueOf('v'); + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Integer.class, testInt); + context.set(String.class, testString); + context.set(Double.class, testDouble); + context.set(Float.class, testFloat); + context.set(Character.class, testChar); + + ObjectBasic userObject = new ObjectBasic(); + ContextInjectionFactory.inject(userObject, context); + + // check field injection + assertEquals(testString, userObject.injectedString); + assertEquals(testInt, userObject.getInt()); + assertEquals(context, userObject.context); + + // check method injection + assertEquals(1, userObject.setMethodCalled); + assertEquals(1, userObject.setMethodCalled2); + assertEquals(testDouble, userObject.d); + assertEquals(testFloat, userObject.f); + assertEquals(testChar, userObject.c); + + // check post processing + assertTrue(userObject.finalized); + } + + /** + * Tests that fields are injected before methods. + */ + @Test + public void testFieldMethodOrder() { + final AssertionFailedError[] error = new AssertionFailedError[1]; + class TestData { + // empty + } + class Injected { + @Inject @Named("valueField") + Object injectedField; + Object methodValue; + + @Inject + public void injectedMethod(@Optional @Named("valueMethod") Object arg) { + try { + assertTrue(injectedField != null); + } catch (AssertionFailedError e) { + error[0] = e; + } + methodValue = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + TestData fieldValue = new TestData(); + TestData methodValue = new TestData(); + context.set("valueField", fieldValue); + context.set("valueMethod", methodValue); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + if (error[0] != null) { + throw error[0]; + } + assertEquals(fieldValue, object.injectedField); + assertEquals(methodValue, object.methodValue); + + // removing method value, the field should still have value + context.remove("valueMethod"); + if (error[0] != null) { + throw error[0]; + } + assertEquals(fieldValue, object.injectedField); + assertNull(object.methodValue); + + context.dispose(); + if (error[0] != null) { + throw error[0]; + } + } + + @Test + public void testOptionalInjection() { + Integer testInt = Integer.valueOf(123); + IEclipseContext context = EclipseContextFactory.create(); + context.set(Integer.class, testInt); + + OptionalAnnotations userObject = new OptionalAnnotations(); + ContextInjectionFactory.inject(userObject, context); + + assertEquals(0, userObject.methodOptionalCalled); + assertEquals(1, userObject.methodRequiredCalled); + assertEquals(testInt, userObject.i); + assertNull(userObject.s); + assertNull(userObject.d); + assertNull(userObject.f); + + // add optional services + String testString = "abc"; + Double testDouble = Double.valueOf(1.23); + Float testFloat = Float.valueOf(12.3f); + context.set(String.class, testString); + context.set(Double.class, testDouble); + context.set(Float.class, testFloat); + + assertEquals(1, userObject.methodOptionalCalled); + assertEquals(2, userObject.methodRequiredCalled); + assertEquals(testInt, userObject.i); + assertEquals(testString, userObject.s); + assertEquals(testDouble, userObject.d); + assertEquals(testFloat, userObject.f); + } + + @Test + public void testOptionalInvoke() { + + class TestObject { + public int called = 0; + + @Execute + public String something(@Optional String param) { + called++; + return param; + } + } + + IEclipseContext context = EclipseContextFactory.create(); + Object notAnObject = new Object(); + TestObject testObject = new TestObject(); + context.set(String.class.getName(), testObject); + + Object result = ContextInjectionFactory.invoke(testObject, Execute.class, context, notAnObject); + assertNull(result); + assertEquals(1, testObject.called); + + String string = "sample"; + context.set(String.class, string); + result = ContextInjectionFactory.invoke(testObject, Execute.class, context, notAnObject); + assertEquals(string, result); + assertEquals(2, testObject.called); + } + + /** + * Tests that a class with multiple inherited post-construct / pre-destroy methods. + */ + @Test + public void testInheritedSpecialMethods() { + IEclipseContext context = EclipseContextFactory.create(); + context.set(Integer.class, Integer.valueOf(123)); + context.set(String.class, "abc"); + context.set(Float.class, Float.valueOf(12.3f)); + + ObjectSubClass userObject = new ObjectSubClass(); + ContextInjectionFactory.inject(userObject, context); + assertEquals(1, userObject.superPostConstructCount); + assertEquals(1, userObject.subPostConstructCount); + assertEquals(0, userObject.superPreDestroyCount); + assertEquals(0, userObject.subPreDestroyCount); + assertEquals(0, userObject.overriddenPreDestroyCount); + + context.set(Float.class, Float.valueOf(45.6f)); + assertEquals(1, userObject.superPostConstructCount); + assertEquals(1, userObject.subPostConstructCount); + assertEquals(0, userObject.superPreDestroyCount); + assertEquals(0, userObject.subPreDestroyCount); + assertEquals(0, userObject.overriddenPreDestroyCount); + + context.dispose(); + assertEquals(1, userObject.superPreDestroyCount); + assertEquals(1, userObject.subPreDestroyCount); + assertEquals(1, userObject.overriddenPreDestroyCount); + } + + @Test + public void testInvoke() { + class TestData { + public String value; + + public TestData(String tmp) { + value = tmp; + } + } + class Injected { + public String myString; + + public Injected() { + // placeholder + } + + @Execute + public String something(@Named("testing123") TestData data) { + myString = data.value; + return "true"; + } + } + IEclipseContext context = EclipseContextFactory.create(); + + TestData methodValue = new TestData("abc"); + context.set("testing123", methodValue); + Injected object = new Injected(); + assertNull(object.myString); + + assertEquals("true", ContextInjectionFactory.invoke(object, Execute.class, context, null)); + assertEquals("abc", object.myString); + } + + @Test + public void testPreDestroy() { + class TestData { + // empty + } + class Injected { + int preDestoryCalled = 0; + public TestData value; + + @Inject + public TestData directFieldInjection; + + @PreDestroy + public void aboutToClose() { + preDestoryCalled++; + assertNotNull(value); + assertNotNull(directFieldInjection); + } + + @Inject + public void setData(TestData arg) { + value = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set(TestData.class, methodValue); + + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + assertNotNull(object.value); + assertNotNull(object.directFieldInjection); + + context.dispose(); + + assertEquals(1, object.preDestoryCalled); + assertNotNull(object.value); + assertNotNull(object.directFieldInjection); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java new file mode 100644 index 00000000000..085d6cf738a --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/Bug317183Test.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertTrue; + +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.junit.Test; + +public class Bug317183Test { + + @Test + public void testX() { + IEclipseContext appContext = EclipseContextFactory.create(); + IEclipseContext windowContext = appContext.createChild(); + IEclipseContext partContextA = windowContext.createChild(); + IEclipseContext partContextB = windowContext.createChild(); + + partContextA.activateBranch(); + + RunAndTrackImpl impl = new RunAndTrackImpl(); + windowContext.runAndTrack(impl); + + impl.called = false; + + partContextA.dispose(); + partContextB.activate(); + assertTrue(impl.called); // this fails + } + + @Test + public void testY() { + IEclipseContext appContext = EclipseContextFactory.create(); + IEclipseContext windowContext = appContext.createChild(); + IEclipseContext partContextA = windowContext.createChild(); + IEclipseContext partContextB = windowContext.createChild(); + IEclipseContext partContextC = windowContext.createChild(); + + partContextA.activateBranch(); + + RunAndTrackImpl impl = new RunAndTrackImpl(); + windowContext.runAndTrack(impl); + + partContextB.activate(); + partContextA.dispose(); + + impl.called = false; + + partContextC.activate(); + assertTrue(impl.called); // this fails + } + + static class RunAndTrackImpl extends RunAndTrack { + + boolean called = false; + + @Override + public boolean changed(IEclipseContext context) { + context.getActiveLeaf(); + called = true; + return true; + } + + } + +} + diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java new file mode 100644 index 00000000000..7e6ea12038c --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +/** + * See bug 296337: duplicate disposal of an object + */ +public class ComplexDisposalTest { + + public static class MyTest { + private int count = 0; + + @Inject + @Named("aString") + String string; + + public int getCount() { + return count; + } + + @PreDestroy + void preDestroy() { + count++; + } + } + + public static class TestFunction extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return ContextInjectionFactory.make(MyTest.class, context); + } + } + + @Test + public void testU() { + IEclipseContext parentContext = EclipseContextFactory.create(); + parentContext.set("aString", ""); + parentContext.set(MyTest.class.getName(), new TestFunction()); + IEclipseContext context = parentContext.createChild(); + + MyTest test = context.get(MyTest.class); + + assertEquals(0, test.getCount()); + context.dispose(); + assertEquals("Context disposed, @PreDestroy should've been called", 1, test.getCount()); + parentContext.dispose(); + assertEquals("Parent context disposed, @PreDestroy should not have been called again", 1, test.getCount()); + } + + @Test + public void testV() { + IEclipseContext parentContext = EclipseContextFactory.create(); + parentContext.set("aString", ""); + IEclipseContext context = parentContext.createChild(); + + MyTest test = ContextInjectionFactory.make(MyTest.class, context); + + assertEquals(0, test.getCount()); + context.dispose(); + assertEquals("Context disposed, @PreDestroy should've been called", 1, test.getCount()); + parentContext.dispose(); + assertEquals("Parent context disposed, @PreDestroy should not have been called again", 1, test.getCount()); + } + + @Test + public void testW() { + IEclipseContext parentContext = EclipseContextFactory.create(); + parentContext.set("aString", ""); + IEclipseContext context = parentContext.createChild(); + + MyTest test = new MyTest(); + ContextInjectionFactory.inject(test, context); + + assertEquals(0, test.getCount()); + context.dispose(); + assertEquals("Context disposed, @PreDestroy should've been called", 1, test.getCount()); + parentContext.dispose(); + assertEquals("Parent context disposed, @PreDestroy should not have been called again", 1, test.getCount()); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java new file mode 100644 index 00000000000..1f2b8c82e81 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +public class ContextFunctionDynamicsTest { + + private static final String SELECTION = "selection"; //$NON-NLS-1$ + + static class InjectTarget { + Object input; + + @Inject + @Optional + void setInput(@Named(SELECTION) Object input) { + this.input = input; + } + } + + /** + * Changing context function should update injected values + */ + @Test + public void testChangeICF() { + IEclipseContext context1 = EclipseContextFactory.create("context1"); + IEclipseContext context2 = context1.createChild("context2"); + + context1.set(SELECTION, new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return "func1"; + } + }); + + InjectTarget target = new InjectTarget(); + ContextInjectionFactory.inject(target, context2); + + assertEquals("func1", target.input); + + context1.set(SELECTION, new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return "func2"; + } + }); + + assertEquals("func2", target.input); + } + + /** + * Overriding context function with a regular value on a child node + */ + @Test + public void testOverrideICF() { + IEclipseContext context1 = EclipseContextFactory.create("context1"); + IEclipseContext context2 = context1.createChild("context2"); + IEclipseContext context3 = context2.createChild("context3"); + + context1.set(SELECTION, new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return "func1"; + } + }); + + InjectTarget target = new InjectTarget(); + ContextInjectionFactory.inject(target, context3); + + assertEquals("func1", target.input); + + Object o = new Object(); + context2.set(SELECTION, o); + + assertEquals(o, target.input); + } + + /** + * Tests updates in a chain of 4 contexts + */ + @Test + public void testLongChain() { + IEclipseContext context1 = EclipseContextFactory.create("context1"); + IEclipseContext context2 = context1.createChild("context2"); + IEclipseContext context3 = context2.createChild("context3"); + IEclipseContext context4 = context3.createChild("context4"); + + // ICF set on top context + context1.set(SELECTION, new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return "func1"; + } + }); + + InjectTarget target = new InjectTarget(); + ContextInjectionFactory.inject(target, context4); + + assertEquals("func1", target.input); + + // Override ICF set on the 2nd context + context2.set(SELECTION, new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return "func2"; + } + }); + + assertEquals("func2", target.input); + + // Override removed + context2.remove(SELECTION); + assertEquals("func1", target.input); + + // Override simple value set on 3rd context + context3.set(SELECTION, "abc"); + assertEquals("abc", target.input); + + // Simple value override removed from 3rd context + context3.remove(SELECTION); + assertEquals("func1", target.input); + } + + + + @Test + public void testBug315109() throws Exception { + IEclipseContext appContext = EclipseContextFactory.create(); + IEclipseContext windowContext = appContext.createChild(); + IEclipseContext partContext = windowContext.createChild(); + + partContext.activateBranch(); + + appContext.set(SELECTION, new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + IEclipseContext parent = context.getParent(); + while (parent != null) { + context = parent; + parent = context.getParent(); + } + return context.getActiveLeaf().get("out.selection"); + } + }); + + InjectTarget target = new InjectTarget(); + ContextInjectionFactory.inject(target, partContext); + + assertNull("No selection has been set, should be null", target.input); //$NON-NLS-1$ + + Object o = new Object(); + windowContext.set(SELECTION, o); + + assertEquals( + "A selection was set into the window, should have been injected into the part", //$NON-NLS-1$ + o, target.input); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java new file mode 100644 index 00000000000..7b832082b77 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +/** + * Tests for injection handling of context dispose, and handling disposal of + * injected objects. + */ +public class ContextInjectionDisposeTest { + + @Test + public void testContextDisposedNoArg() { + class Injected { + + boolean disposeInvoked = false; + + @SuppressWarnings("unused") + @Inject + private String Field; + + @PreDestroy + public void dispose() { + disposeInvoked = true; + } + } + + IEclipseContext context = EclipseContextFactory.create(); + context.set(String.class, "hello"); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + context.dispose(); + assertTrue(object.disposeInvoked); + } + + @Test + public void testDisposeContext() { + class Injected { + boolean disposeInvoked = false; + + @Inject + Object Field; + String methodValue; + + @PreDestroy + public void dispose() { + disposeInvoked = true; + } + + @Inject + public void InjectedMethod(String arg) { + methodValue = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + Object fieldValue = new Object(); + Object methodValue = "abc"; + context.set(Object.class, fieldValue); + context.set(String.class.getName(), methodValue); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + + assertEquals(fieldValue, object.Field); + assertEquals(methodValue, object.methodValue); + + // disposing context calls @PreDestory, but does not clear injected + // values + context.dispose(); + assertNotNull(object.Field); + assertNotNull(object.methodValue); + assertTrue(object.disposeInvoked); + } + + @Test + public void testReleaseObject() { + class Injected { + boolean disposeInvoked = false; + + @Inject + Integer Field; + Object methodValue; + + @PreDestroy + public void dispose() { + disposeInvoked = true; + } + + @Inject + public void InjectedMethod(@Optional String arg) { + methodValue = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + Integer fieldValue = Integer.valueOf(123); + String methodValue = "abc"; + context.set(Integer.class, fieldValue); + context.set(String.class, methodValue); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + + assertEquals(fieldValue, object.Field); + assertEquals(methodValue, object.methodValue); + + // releasing should have the same effect on the single object as + // disposing the context does. + ContextInjectionFactory.uninject(object, context); + + assertEquals(fieldValue, object.Field); + assertNull(object.methodValue); + assertTrue(object.disposeInvoked); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionFactoryTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionFactoryTest.java new file mode 100644 index 00000000000..873a1c6f921 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionFactoryTest.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.junit.Before; +import org.junit.Test; + +public class ContextInjectionFactoryTest { + + static class TestObject { + + private int executed = 0; + + private int executedWithParams = 0; + + @Execute + public void execute() { + executed++; + } + + @CanExecute + public void executeWithParams(String string) { + executedWithParams++; + } + + public int getExecuted() { + return executed; + } + + public int getExecutedWithParams() { + return executedWithParams; + } + + } + + static class TestConstructorObjectBasic { + public boolean defaultConstructorCalled = false; + + public TestConstructorObjectBasic() { + defaultConstructorCalled = true; + } + } + + private TestObject testObject; + private IEclipseContext context; + + @Before + public void setUp() throws Exception { + testObject = new TestObject(); + context = EclipseContextFactory.create(); + } + + @Test + public void testInvoke() throws Exception { + ContextInjectionFactory.invoke(testObject, Execute.class, context, null); + + assertEquals(1, testObject.getExecuted()); + assertEquals(0, testObject.getExecutedWithParams()); + } + + @Test + public void testInvokeWithParameters() throws Exception { + context.set(String.class.getName(), ""); + + ContextInjectionFactory.invoke(testObject, CanExecute.class, context, null); + + assertEquals(0, testObject.getExecuted()); + assertEquals(1, testObject.getExecutedWithParams()); + } + + /** + * If no other constructors are available, the default constructor should be used + */ + @Test + public void testConstructorInjectionBasic() { + IEclipseContext context = EclipseContextFactory.create(); + // add an extra argument for the inner class constructors + context.set(ContextInjectionFactoryTest.class.getName(), this); + + Object basicResult = ContextInjectionFactory + .make(TestConstructorObjectBasic.class, context); + assertNotNull(basicResult); + assertTrue(basicResult instanceof TestConstructorObjectBasic); + assertTrue(((TestConstructorObjectBasic) basicResult).defaultConstructorCalled); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java new file mode 100644 index 00000000000..b9d9ebd0e85 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.junit.Test; + +/** + * Tests for the basic context injection functionality + */ +public class ContextInjectionTest { + + + /** + * Test trivial method injection and finalize method with context as an argument + */ + @Test + public void testContextSetOneArg() { + class TestData { + } + class Injected { + int contextSetCalled = 0; + int setMethodCalled = 0; + + public TestData value; + + @Inject + public void contextSet(IEclipseContext context) { + contextSetCalled++; + } + + @Inject + public void InjectedMethod(TestData arg) { + setMethodCalled++; + value = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set(TestData.class.getName(), methodValue); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + assertEquals(1, object.setMethodCalled); + assertEquals(1, object.contextSetCalled); + + TestData methodValue2 = new TestData(); + context.set(TestData.class.getName(), methodValue2); + assertEquals(2, object.setMethodCalled); + assertEquals(methodValue2, object.value); + assertEquals(1, object.contextSetCalled); + } + + /** + * Test filnalize method - no args + */ + @Test + public void testContextSetZeroArgs() { + class TestData { + } + class Injected { + int contextSetCalled = 0; + int setMethodCalled = 0; + + public TestData value; + + @Inject + public void contextSet() { + contextSetCalled++; + } + + @Inject + public void InjectedMethod(TestData arg) { + setMethodCalled++; + value = arg; + } + } + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set(TestData.class.getName(), methodValue); + Injected object = new Injected(); + ContextInjectionFactory.inject(object, context); + assertEquals(1, object.setMethodCalled); + assertEquals(1, object.contextSetCalled); + + TestData methodValue2 = new TestData(); + context.set(TestData.class.getName(), methodValue2); + assertEquals(2, object.setMethodCalled); + assertEquals(methodValue2, object.value); + assertEquals(1, object.contextSetCalled); + } + + /** + * Tests basic context injection + */ + @Test + public synchronized void testInjection() { + Integer testInt = Integer.valueOf(123); + String testString = "abc"; + Double testDouble = Double.valueOf(1.23); + Float testFloat = Float.valueOf(12.3f); + Character testChar = Character.valueOf('v'); + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Integer.class, testInt); + context.set(String.class, testString); + context.set(Double.class, testDouble); + context.set(Float.class, testFloat); + context.set(Character.class, testChar); + + ObjectBasic userObject = new ObjectBasic(); + ContextInjectionFactory.inject(userObject, context); + + // check field injection + assertEquals(testString, userObject.injectedString); + assertEquals(testInt, userObject.getInt()); + // assertEquals(context, userObject.context); + + // check method injection + assertEquals(1, userObject.setMethodCalled); + assertEquals(1, userObject.setMethodCalled2); + assertEquals(testDouble, userObject.d); + assertEquals(testFloat, userObject.f); + assertEquals(testChar, userObject.c); + + // check post processing + assertTrue(userObject.finalized); + } + + /** + * Tests injection of objects from parent context + */ + @Test + public synchronized void testInjectionFromParent() { + Integer testInt = Integer.valueOf(123); + String testString = "abc"; + Double testDouble = Double.valueOf(1.23); + Float testFloat = Float.valueOf(12.3f); + Character testChar = Character.valueOf('v'); + + // create parent context + IEclipseContext parentContext = EclipseContextFactory.create(); + parentContext.set(Integer.class.getName(), testInt); + parentContext.set(String.class.getName(), testString); + + // create child context + IEclipseContext context = parentContext.createChild(); + context.set(Double.class.getName(), testDouble); + context.set(Float.class.getName(), testFloat); + context.set(Character.class.getName(), testChar); + + ObjectBasic userObject = new ObjectBasic(); + ContextInjectionFactory.inject(userObject, context); + + // check field injection + assertEquals(testString, userObject.injectedString); + assertEquals(testInt, userObject.getInt()); + // assertEquals(context, userObject.context); + + // check method injection + assertEquals(1, userObject.setMethodCalled); + assertEquals(1, userObject.setMethodCalled2); + assertEquals(testDouble, userObject.d); + assertEquals(testFloat, userObject.f); + assertEquals(testChar, userObject.c); + + // check post processing + assertTrue(userObject.finalized); + } + + /** + * Tests injection into classes with inheritance + */ + @Test + public synchronized void testInjectionAndInheritance() { + Integer testInt = Integer.valueOf(123); + String testString = "abc"; + Float testFloat = Float.valueOf(12.3f); + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Integer.class.getName(), testInt); + context.set(String.class.getName(), testString); + context.set(Float.class.getName(), testFloat); + + ObjectSubClass userObject = new ObjectSubClass(); + ContextInjectionFactory.inject(userObject, context); + + // check inherited portion + assertEquals(testString, userObject.getString()); + // assertEquals(context, userObject.getContext()); + assertEquals(testString, userObject.getStringViaMethod()); + assertEquals(1, userObject.setStringCalled); + + // check declared portion + assertEquals(testInt, userObject.getInteger()); + assertEquals(testFloat, userObject.getObjectViaMethod()); + assertEquals(1, userObject.setObjectCalled); + + // make sure overridden injected method was called only once + assertEquals(1, userObject.setOverriddenCalled); + + // check post processing + assertEquals(1, userObject.getFinalizedCalled()); + } + + static public class BaseOverrideTest { + public String selectionString; + public String inputString; + public boolean finishCalled = false; + + @Inject + public void setSelection(String selectionString) { + this.selectionString = selectionString; + } + + @Inject + public void setInput(String inputString) { + this.inputString = inputString; + } + + @PostConstruct + public void finish() { + finishCalled = true; + } + } + + static public class OverrideTest extends BaseOverrideTest { + public Integer selectionNum; + public String inputStringSubclass; + public Double inputDouble; + public Boolean arg; + public boolean finishOverrideCalled = false; + + @Inject + public void setSelection(Integer selectionNum) { + this.selectionNum = selectionNum; + } + + @Inject + public void setInput(String inputString, Double inputDouble) { + this.inputStringSubclass = inputString; + this.inputDouble = inputDouble; + + } + + @PostConstruct + public void finish(Boolean arg) { + finishOverrideCalled = true; + this.arg = arg; + } + } + + /** + * Tests injection of similar, but not overridden methods + */ + @Test + public synchronized void testInjectionCloseOverride() { + Integer testInt = Integer.valueOf(123); + String testString = "abc"; + Double testDouble = Double.valueOf(12.3); + Boolean testBoolean = Boolean.TRUE; + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Integer.class, testInt); + context.set(String.class, testString); + context.set(Double.class, testDouble); + context.set(Boolean.class, testBoolean); + + OverrideTest userObject = new OverrideTest(); + ContextInjectionFactory.inject(userObject, context); + + // check inherited portion + assertEquals(testString, userObject.selectionString); + assertEquals(testString, userObject.inputString); + assertTrue(userObject.finishCalled); + + // check similar methods portion + assertEquals(testInt, userObject.selectionNum); + assertEquals(testString, userObject.inputStringSubclass); + assertEquals(testDouble, userObject.inputDouble); + assertTrue(userObject.finishOverrideCalled); + } + + @Test + public void testBug374421() { + try { + IEclipseContext context = EclipseContextFactory.create(); + context.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + IEclipseContext staticContext = EclipseContextFactory.create(); + ContextInjectionFactory.make(Object.class, context, staticContext); + return true; + } + }); + } catch (StackOverflowError e) { + fail("See bug 374421 for details."); + } + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java new file mode 100644 index 00000000000..e28429fdc71 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.internal.contexts.EclipseContext; +import org.junit.Test; + +@SuppressWarnings("restriction") +public class DisposingReferencedContextTest { + + static class MandatoryTarget { + @Inject @Named("object") + Object object; + + @Inject + void setActiveContext(@Named(EclipseContext.ACTIVE_CHILD) IEclipseContext partContext) { + if (partContext != null) { + partContext.get("someVar"); + } + } + } + + static class OptionalTarget { + @Inject @Named("object") + Object object; + + @Inject + void setActiveContext(@Optional @Named(EclipseContext.ACTIVE_CHILD) IEclipseContext partContext) { + if (partContext != null) { + partContext.get("someVar"); + } + } + } + + @Test + public void testContextDisposeCausesCompleteUninjection_Mandatory_True() { + testContextDisposeCausesCompleteUninjection_Mandatory(true); + } + + @Test + public void testContextDisposeCausesCompleteUninjection_Mandatory_False() { + testContextDisposeCausesCompleteUninjection_Mandatory(false); + } + + @Test + public void testContextDisposeCausesCompleteUninjection_Optional_True() { + testContextDisposeCausesCompleteUninjection_Optional(true); + } + + @Test + public void testContextDisposeCausesCompleteUninjection_Optional_False() { + testContextDisposeCausesCompleteUninjection_Optional(false); + } + + private void testContextDisposeCausesCompleteUninjection_Mandatory(boolean disposeFirst) { + IEclipseContext windowContext = EclipseContextFactory.create("windowContext"); + IEclipseContext partContext = windowContext.createChild("partContext"); + + partContext.activate(); + + Object o = new Object(); + windowContext.set("object", o); + + MandatoryTarget target = new MandatoryTarget(); + ContextInjectionFactory.inject(target, windowContext); + assertEquals("The object should have been injected", o, target.object); + + partContext.dispose(); + + assertEquals("The object should not have been uninjected", o, target.object); + } + + private void testContextDisposeCausesCompleteUninjection_Optional(boolean disposeFirst) { + IEclipseContext windowContext = EclipseContextFactory.create(); + IEclipseContext partContext = windowContext.createChild(); + + partContext.activate(); + + Object o = new Object(); + windowContext.set("object", o); + + OptionalTarget target = new OptionalTarget(); + ContextInjectionFactory.inject(target, windowContext); + assertEquals("The object should have been injected", o, target.object); + + partContext.dispose(); + + assertEquals("The object should not have been uninjected", o, target.object); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java new file mode 100644 index 00000000000..50b1adbea35 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.InvocationTargetException; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +public class ExtraDependenciesTest { + + static public class TestObject { + + public String string; + public Integer integer; + public String other; + + public boolean disposed = false; + + @Inject + public void injectedMethod(@Named("arg1") String strValue, @Named("arg2") Integer intValue, IEclipseContext context) { + string = strValue; + integer = intValue; + if (context == null) { + other = null; + return; + } + IEclipseContext otherContext = (IEclipseContext) context.get("otherContext"); + if (otherContext == null) { + other = null; + } else { + other = (String) otherContext.get("arg3"); + } + } + + @PreDestroy + public void finita() { + disposed = true; + } + } + + @Test + public void testExtraDependencies() throws InvocationTargetException, InstantiationException { + IEclipseContext context = EclipseContextFactory.create(); + context.set("arg1", "abc"); + context.set("arg2", Integer.valueOf (123)); + + IEclipseContext otherContext = EclipseContextFactory.create(); + otherContext.set("arg3", "other"); + + context.set("otherContext", otherContext); + + TestObject object = ContextInjectionFactory.make(TestObject.class, context); + + // check that initial values are properly injected + assertEquals("abc", object.string); + assertEquals(Integer.valueOf(123), object.integer); + assertEquals("other", object.other); + + // modify argument value to cause update - bug 308650 + context.set("arg2", Integer.valueOf (789)); + + // change the "other" value; should not be propagated + otherContext.set("arg3", "wrong"); + assertEquals("other", object.other); + + // dispose the other context; should not cause disposal of the test object + otherContext.dispose(); + assertEquals("other", object.other); + assertFalse(object.disposed); + + // remove "other" context, should not be propagated + context.remove("otherContext"); + assertEquals("other", object.other); + + // check that changes in the method arguments are propagated + context.set("arg1", "xyz"); + context.set("arg2", Integer.valueOf (456)); + assertEquals("xyz", object.string); + assertEquals(Integer.valueOf(456), object.integer); + assertNull(object.other); + + // check that disposal of the injected context causes disposal of the injected object + context.dispose(); + assertTrue(object.disposed); + assertNotNull(object.string); + assertNotNull(object.integer); + assertNull(object.other); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java new file mode 100644 index 00000000000..210d385c459 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2011, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +/** + * Tests for the generics context injection functionality + */ +public class GenericsInjectionTest { + + static public class Animal { + } + + static public class Bird extends Animal { + } + + static public class Feeder { + } + + static public class BirdHouse extends Feeder { + } + + static public class TestNamedObject { + public Feeder field; + + @Inject + public void setFeeder(@Named("test") Feeder value) { + field = value; + } + } + + static public class TestGenericObject { + public Feeder field; + + @Inject + public void setFeeder(Feeder value) { + field = value; + } + } + + @Test + public synchronized void testNamedInjection() { + Animal testAnimal = new Animal(); + Bird testBird = new Bird(); + BirdHouse testBirdHouse = new BirdHouse(); + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Animal.class, testAnimal); + context.set(Bird.class, testBird); + context.set("test", testBirdHouse); + + TestNamedObject userObject = new TestNamedObject(); + ContextInjectionFactory.inject(userObject, context); + + // check field injection + assertEquals(testBirdHouse, userObject.field); + } + + @Test + public synchronized void testGenericInjection() { + Animal testAnimal = new Animal(); + Bird testBird = new Bird(); + BirdHouse testBirdHouse = new BirdHouse(); + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Animal.class, testAnimal); + context.set(Bird.class, testBird); + context.set(Feeder.class, testBirdHouse); // note that BirdHouse is + // added as Feeder class + + TestGenericObject userObject = new TestGenericObject(); + ContextInjectionFactory.inject(userObject, context); + + // check field injection + assertEquals(testBirdHouse, userObject.field); + } + + static public interface Interface { + } + + static public class Implementation implements Interface { + } + + static public class InterfaceTarget { + @Inject + public Interface field; + } + + @Test + public void testInterfaceGenericInjection() { + Implementation implementation = new Implementation(); + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Interface.class, implementation); + + InterfaceTarget target = new InterfaceTarget(); + ContextInjectionFactory.inject(target, context); + + // check field injection + assertEquals(implementation, target.field); + } + + static public class Superclass { + } + + static public class Subclass extends Superclass { + } + + static public class ClassTarget { + @Inject + public Superclass field; + } + + @Test + public void testClassGenericInjection() { + Subclass implementation = new Subclass(); + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(Superclass.class, implementation); + + ClassTarget target = new ClassTarget(); + ContextInjectionFactory.inject(target, context); + + // check field injection + assertEquals(implementation, target.field); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java new file mode 100644 index 00000000000..90e34d498bb --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 vogella GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lars Vogel - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +/** + * Tests for the type erasure in lists + */ +public class GenericsListTest { + + static public class TestNamedObject { + public List field; + + @Inject + public void setList(List value) { + field = value; + } + + public String combineIt() { + StringBuilder stringBuilder = new StringBuilder(); + for (String string : field) { + stringBuilder.append(string); + } + return stringBuilder.toString(); + } + } + + @Test + @SuppressWarnings("rawtypes") + public void testRawListInjection() { + + List list = new ArrayList(); + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(List.class, list); + + TestNamedObject userObject = new TestNamedObject(); + ContextInjectionFactory.inject(userObject, context); + + // check field injection + assertEquals(list, userObject.field); + } + + @Test(expected = ClassCastException.class) + public void testTypeErasure() { + + List list = new ArrayList<>(); + list.add(1); + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(List.class, list); + + TestNamedObject userObject = new TestNamedObject(); + ContextInjectionFactory.inject(userObject, context); + // check field injection, should be successful because + // of the type erasure + assertEquals(list, userObject.field); + + userObject.combineIt(); + } + + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java new file mode 100644 index 00000000000..ad0eb3e41e9 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.GroupUpdates; +import org.junit.Test; + +public class GroupedUpdatesTest { + + + static class InjectTarget { + public int countMain = 0; + public int countSecondary = 0; + + public String s1; + public String s2; + + public void resetCounters() { + countMain = 0; + countSecondary = 0; + } + } + + + static class InjectTargetImmediate extends InjectTarget { + @Inject + void setInfo(@Named("string1") String s, @Named("string2") String s2) { + countMain++; + this.s1 = s; + this.s2 = s2; + } + @Inject + void setInfoSecondary(@Named("string2") String s2) { + countSecondary++; + this.s2 = s2; + } + } + + static class InjectTargetWait extends InjectTarget { + @Inject @GroupUpdates + void setInfo(@Named("string1") String s, @Named("string2") String s2) { + countMain++; + this.s1 = s; + this.s2 = s2; + } + + @Inject @GroupUpdates + void setInfoSecondary(@Named("string2") String s2) { + countSecondary++; + this.s2 = s2; + } + } + + @Test + public void testNoGrouping() { + IEclipseContext context = EclipseContextFactory.create(); + context.set("string1", "x"); + context.set("string2", "y"); + + InjectTarget target = new InjectTargetImmediate(); + ContextInjectionFactory.inject(target, context); + assertEquals(1, target.countMain); + + target.resetCounters(); + + // I want these two sets to be one transaction + context.set("string1", "a"); + context.set("string2", "b"); + assertEquals(2, target.countMain); + assertEquals(1, target.countSecondary); + context.processWaiting(); + assertEquals(2, target.countMain); + assertEquals(1, target.countSecondary); + } + + @Test + public void testGrouping() { + final IEclipseContext context = EclipseContextFactory.create(); + context.set("string1", "x"); + context.set("string2", "y"); + + InjectTarget target = new InjectTargetWait(); + ContextInjectionFactory.inject(target, context); + assertEquals(1, target.countMain); + + target.resetCounters(); + + context.set("string1", "a"); + context.set("string2", "b"); + + assertEquals(0, target.countMain); + assertEquals(0, target.countSecondary); + + context.processWaiting(); + + assertEquals(1, target.countMain); + assertEquals(1, target.countSecondary); + + // do it again to make sure we properly cleared waiting updates + context.processWaiting(); + assertEquals(1, target.countMain); + assertEquals(1, target.countSecondary); + + // now with 3 updates + target.resetCounters(); + context.set("string1", "x"); + context.set("string2", "y"); + context.set("string2", "z"); + context.set("string1", "delta"); + + assertEquals(0, target.countMain); + assertEquals(0, target.countSecondary); + + context.processWaiting(); + + assertEquals(1, target.countMain); + assertEquals(1, target.countSecondary); + + assertEquals(target.s1, "delta"); + assertEquals(target.s2, "z"); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java new file mode 100644 index 00000000000..c94cb865cec --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java @@ -0,0 +1,277 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + * Daniel Kruegler - Bug 493697 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +/** + * Tests for the context injection functionality using 2 contexts + */ +public class InjectStaticContextTest { + static class TestClass { + public IEclipseContext injectedContext; + public String aString; + public String bString; + public String cString; + + public String aConstructorString; + public String bConstructorString; + + public int postConstructCalled = 0; + public int preDestroyCalled = 0; + + @Inject + public void contextSet(@Optional IEclipseContext context) { + injectedContext = context; + } + + @Inject + public void setA(@Optional @Named("a") String aString) { + this.aString = aString; + } + + @Inject + public void setB(@Named("b") String bString) { + this.bString = bString; + } + + @Inject + public void setC(@Named("c") String cString) { + this.cString = cString; + } + + @Inject + public void InjectedMethod(@Named("aConstructor") String aString, @Named("bConstructor") String bString) { + aConstructorString = aString; + bConstructorString = bString; + } + + @PostConstruct + public void init() { + postConstructCalled++; + } + + @PreDestroy + public void dispose() { + preDestroyCalled++; + } + } + + static class TestInvokeClass { + public String aString; + public String bString; + + public IEclipseContext context; + + @Execute + public String testMethod(@Named("a") String aString, @Named("b") String bString, IEclipseContext context) { + this.aString = aString; + this.bString = bString; + this.context = context; + return aString + bString; + } + } + + @Test + public void testStaticMake() { + IEclipseContext trackedContext = EclipseContextFactory.create(); + trackedContext.set("a", "abc"); + trackedContext.set("aConstructor", "abcConstructor"); + trackedContext.set("b", "bbc"); + + IEclipseContext staticContext = EclipseContextFactory.create(); + staticContext.set("b", "123"); // local values override + staticContext.set("bConstructor", "123Constructor"); + staticContext.set("c", "xyz"); + + TestClass testObject = ContextInjectionFactory.make(TestClass.class, trackedContext, staticContext); + + assertEquals(trackedContext, testObject.injectedContext); + assertEquals("abcConstructor", testObject.aConstructorString); + assertEquals("123Constructor", testObject.bConstructorString); + assertEquals("abc", testObject.aString); + assertEquals("123", testObject.bString); + assertEquals("xyz", testObject.cString); + assertEquals(1, testObject.postConstructCalled); + assertEquals(0, testObject.preDestroyCalled); + + // modify local context -> should have no effect + staticContext.set("b", "_123_"); + staticContext.set("bConstructor", "_123Constructor_"); + staticContext.set("c", "_xyz_"); + + assertEquals("abcConstructor", testObject.aConstructorString); + assertEquals("123Constructor", testObject.bConstructorString); + assertEquals("abc", testObject.aString); + assertEquals("123", testObject.bString); + assertEquals("xyz", testObject.cString); + assertEquals(1, testObject.postConstructCalled); + assertEquals(0, testObject.preDestroyCalled); + + // dispose local context -> should have no effect + staticContext.dispose(); + + assertEquals("abcConstructor", testObject.aConstructorString); + assertEquals("123Constructor", testObject.bConstructorString); + assertEquals("abc", testObject.aString); + assertEquals("123", testObject.bString); + assertEquals("xyz", testObject.cString); + assertEquals(1, testObject.postConstructCalled); + assertEquals(0, testObject.preDestroyCalled); + + // modify parent context -> should propagate + trackedContext.set("a", "_abc_"); + trackedContext.set("b", "_bbc_"); + + assertEquals("_abc_", testObject.aString); + assertEquals("123", testObject.bString); + + // uninject from the parent context + ContextInjectionFactory.uninject(testObject, trackedContext); + + assertNull(testObject.injectedContext); + assertNull(testObject.aString); + + assertEquals(1, testObject.postConstructCalled); + assertEquals(1, testObject.preDestroyCalled); + + // further changes should have no effect + trackedContext.set("a", "+abc+"); + assertNull(testObject.aString); + + trackedContext.dispose(); + assertEquals(1, testObject.postConstructCalled); + assertEquals(1, testObject.preDestroyCalled); + } + + @Test + public void testStaticInject() { + IEclipseContext trackedContext = EclipseContextFactory.create(); + trackedContext.set("a", "abc"); + trackedContext.set("aConstructor", "abcConstructor"); + trackedContext.set("b", "bbc"); + + IEclipseContext staticContext = EclipseContextFactory.create(); + staticContext.set("b", "123"); // local values override + staticContext.set("bConstructor", "123Constructor"); + staticContext.set("c", "xyz"); + + TestClass testObject = new TestClass(); + + assertNull(testObject.injectedContext); + assertNull(testObject.aConstructorString); + assertNull(testObject.bConstructorString); + assertNull(testObject.aString); + assertNull(testObject.bString); + assertNull(testObject.cString); + assertEquals(0, testObject.postConstructCalled); + assertEquals(0, testObject.preDestroyCalled); + + ContextInjectionFactory.inject(testObject, trackedContext, staticContext); + + assertEquals(trackedContext, testObject.injectedContext); + assertEquals("abcConstructor", testObject.aConstructorString); + assertEquals("123Constructor", testObject.bConstructorString); + assertEquals("abc", testObject.aString); + assertEquals("123", testObject.bString); + assertEquals("xyz", testObject.cString); + assertEquals(1, testObject.postConstructCalled); + assertEquals(0, testObject.preDestroyCalled); + + // modify local context -> should have no effect + staticContext.set("b", "_123_"); + staticContext.set("bConstructor", "_123Constructor_"); + staticContext.set("c", "_xyz_"); + + assertEquals("abcConstructor", testObject.aConstructorString); + assertEquals("123Constructor", testObject.bConstructorString); + assertEquals("abc", testObject.aString); + assertEquals("123", testObject.bString); + assertEquals("xyz", testObject.cString); + assertEquals(1, testObject.postConstructCalled); + assertEquals(0, testObject.preDestroyCalled); + + // dispose local context -> should have no effect + staticContext.dispose(); + + assertEquals("abcConstructor", testObject.aConstructorString); + assertEquals("123Constructor", testObject.bConstructorString); + assertEquals("abc", testObject.aString); + assertEquals("123", testObject.bString); + assertEquals("xyz", testObject.cString); + assertEquals(1, testObject.postConstructCalled); + assertEquals(0, testObject.preDestroyCalled); + + // modify parent context -> should propagate + trackedContext.set("a", "_abc_"); + trackedContext.set("b", "_bbc_"); + + assertEquals("_abc_", testObject.aString); + assertEquals("123", testObject.bString); + + // uninject from the parent context + ContextInjectionFactory.uninject(testObject, trackedContext); + + assertNull(testObject.injectedContext); + assertNull(testObject.aString); + + assertEquals(1, testObject.postConstructCalled); + assertEquals(1, testObject.preDestroyCalled); + + // further changes should have no effect + trackedContext.set("a", "+abc+"); + assertNull(testObject.aString); + + trackedContext.dispose(); + assertEquals(1, testObject.postConstructCalled); + assertEquals(1, testObject.preDestroyCalled); + } + + @Test + public void testStaticInvoke() { + IEclipseContext trackedContext = EclipseContextFactory.create("main"); + trackedContext.set("a", "abc"); + + IEclipseContext staticContext = EclipseContextFactory.create("static"); + staticContext.set("b", "123"); + + TestInvokeClass testObject = new TestInvokeClass(); + assertNull(testObject.aString); + assertNull(testObject.bString); + + Object result = ContextInjectionFactory.invoke(testObject, Execute.class, trackedContext, staticContext, null); + + assertEquals("abc123", result); + + assertEquals("abc", testObject.aString); + assertEquals("123", testObject.bString); + + assertEquals(trackedContext, testObject.context); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java new file mode 100644 index 00000000000..05cb99cd326 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertTrue; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +public class InjectionOrderTest { + + public static class InjectTargetMethod { + + boolean nonNull = false; + + Object o; + + @Inject + void set(@Named("inject") Object o) { + this.o = o; + } + + @PreDestroy + void pd() { + // methods should always be uninjected after @PD is called + nonNull = o != null; + } + } + + public static class InjectTargetField { + + boolean nonNull = false; + + @Inject @Named("inject") + Object o; + + @PreDestroy + void pd() { + // fields should always be uninjected after @PD is called + nonNull = o != null; + } + } + + /** + * Tests to ensure that the injection/uninjection order of fields is correct. + *

+ * See bug 304859. + *

+ */ + @Test + public void testDisposeMethod() throws Exception { + // create a context + IEclipseContext appContext = EclipseContextFactory.create(); + // set a value + appContext.set("inject", "a"); + + // instantiate the object + InjectTargetMethod injectTargetMethod = ContextInjectionFactory.make(InjectTargetMethod.class, appContext); + // change the requested value so another injection occurs + appContext.set("inject", "b"); + + // now we dispose the context + appContext.dispose(); + + // check that the second 'set' invocation did not alter the order of notifications + assertTrue("@PreDestroy was incorrectly called after the method was uninjected", injectTargetMethod.nonNull); + } + + /** + * Tests to ensure that the injection/uninjection order of methods is correct. + *

+ * See bug 304859. + *

+ */ + @Test + public void testDisposeField() throws Exception { + // create a context + IEclipseContext appContext = EclipseContextFactory.create(); + // set a value + appContext.set("inject", "a"); + + // instantiate the object + InjectTargetField injectTargetField = ContextInjectionFactory.make(InjectTargetField.class, appContext); + // change the requested value so another injection occurs + appContext.set("inject", "b"); + + // now we dispose the context + appContext.dispose(); + + assertTrue("@PreDestroy was incorrectly called after the field was uninjected", injectTargetField.nonNull); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java new file mode 100644 index 00000000000..57f7bf08e1e --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests updates of injected values and calls to runnables + */ +public class InjectionUpdateTest { + + private IEclipseContext c1; // common root + private IEclipseContext c21; // dependents of root - path 1 + private IEclipseContext c22; // dependents of root - path 2 + + static public class PropagationTest { + + public int called = 0; + public String in; + + @Inject + public PropagationTest() { + // placeholder + } + + @Inject + public void setCalculated(@Named("calculated") String string) { + called++; + in = string; + } + } + + @Before + public void setUp() throws Exception { + c1 = EclipseContextFactory.create("c1"); + c1.set("id", "c1"); + + c21 = c1.createChild("c21"); + c21.set("id", "c21"); + c1.set("c21", c21); + + c22 = c1.createChild("c22"); + c22.set("id", "c22"); + c1.set("c22", c22); + } + + @Test + public void testPropagation() { + c1.set("base", "abc"); + + c21.set("derived1", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + String baseString = (String) context.get("base"); + return baseString.charAt(0) + "_"; + }}); + + c22.set("derived2", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + String baseString = (String) context.get("base"); + return "_" + baseString.charAt(baseString.length() - 1); + }}); + + c1.set("calculated", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + IEclipseContext context21 = (IEclipseContext) context.get("c21"); + String derived1 = (String) context21.get("derived1"); + + IEclipseContext context22 = (IEclipseContext) context.get("c22"); + String derived2 = (String) context22.get("derived2"); + return derived1 + derived2; + }}); + + PropagationTest testObject = ContextInjectionFactory.make(PropagationTest.class, c1); + assertNotNull(testObject); + assertEquals(1, testObject.called); + assertEquals("a__c", testObject.in); + + c1.set("base", "123"); // this should result in only one injection call + assertEquals(2, testObject.called); + assertEquals("1__3", testObject.in); + + c1.set("base", "xyz"); + assertEquals(3, testObject.called); + assertEquals("x__z", testObject.in); + } + + public static class InjectTarget { + private static final String KEY = "key"; + + @Inject + private IEclipseContext context; + + @PostConstruct + void pc() { + context.containsKey(KEY); + } + + public void modify() { + context.set(KEY, null); + } + } + + @Test + public void testNestedUpdatesPostConstruct() throws Exception { + IEclipseContext appContext = EclipseContextFactory.create(); + appContext.set(InjectTarget.class.getName(), new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return ContextInjectionFactory + .make(InjectTarget.class, context); + } + }); + + InjectTarget targetA = appContext.get(InjectTarget.class); + targetA.modify(); + + InjectTarget targetB = appContext.get(InjectTarget.class); + assertEquals(targetA, targetB); + assertSame(targetA, targetB); + } + + public static class InjectTarget2 { + private static final String KEY = "key"; //$NON-NLS-1$ + + @Inject + private IEclipseContext context; + + public Object key; + + @Inject + public InjectTarget2(@Optional @Named("key") Object key) { + this.key = key; + } + + public void modify() { + context.set(KEY, null); + } + } + + @Test + public void testNestedUpdatesConstructor() throws Exception { + IEclipseContext appContext = EclipseContextFactory.create(); + appContext.set(InjectTarget2.class.getName(), new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return ContextInjectionFactory.make(InjectTarget2.class, + context); + } + }); + + InjectTarget2 targetA = appContext.get(InjectTarget2.class); + targetA.modify(); + + InjectTarget2 targetB = appContext.get(InjectTarget2.class); + assertEquals(targetA, targetB); + assertSame(targetA, targetB); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java new file mode 100644 index 00000000000..704c8a20007 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +/** + * Tests for the context injection functionality using 2 contexts + */ +public class InvokeInRATTest { + + static class TestHandler { + + public Object active; + public Object selected; + + @CanExecute + public void testEnablement(@Optional @Named("active") Object active, @Optional @Named("selected") Object selected) { + this.active = active; + this.selected = selected; + } + } + + @Test + public void testStaticInvoke() { + IEclipseContext context = EclipseContextFactory.create(); + final int[] count = new int[1]; + + context.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + TestHandler handler = (TestHandler) context.get("handlerA"); + if (handler != null) { + ContextInjectionFactory.invoke(handler, CanExecute.class, context); + count[0]++; + } + return true; // continue to be notified + }}); + + // check that updates are propagated + context.set("active", Integer.valueOf(123)); + context.set("selected", "abc"); + TestHandler handler = new TestHandler(); + context.set("handlerA", handler); + + assertEquals(Integer.valueOf(123), handler.active); + assertEquals("abc", handler.selected); + + // check handler replacement + count[0] = 0; + TestHandler newHandler = new TestHandler(); + context.set("handlerA", newHandler); + assertEquals(1, count[0]); + + assertEquals(Integer.valueOf(123), newHandler.active); + assertEquals("abc", newHandler.selected); + + // change values in the context; values should not be propagated to handlers + context.set("active", Integer.valueOf(456)); + context.set("selected", "xyz"); + + assertEquals(Integer.valueOf(123), handler.active); + assertEquals("abc", handler.selected); + assertEquals(Integer.valueOf(123), newHandler.active); + assertEquals("abc", newHandler.selected); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java new file mode 100644 index 00000000000..d8a01110d4e --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; + +/** + * Test class to check injection mechanism + */ +public class ObjectBasic { + + // Injected directly + @Inject @Optional + public String injectedString; + @Inject + private Integer injectedInteger; + + // Injected indirectly + public Double d; + public Float f; + public Character c; + public IEclipseContext context; + + // Test status + public boolean finalized = false; + public boolean disposed = false; + public int setMethodCalled = 0; + public int setMethodCalled2 = 0; + + public ObjectBasic() { + // placeholder + } + + @Inject + public void objectViaMethod(Double d) { + setMethodCalled++; + this.d = d; + } + + @Inject + public void arguments(Float f, @Optional Character c) { + setMethodCalled2++; + this.f = f; + this.c = c; + } + + @PostConstruct + public void postCreate(IEclipseContext context) { + this.context = context; + finalized = true; + } + + @PreDestroy + public void dispose(IEclipseContext context) { + if (this.context != context) + throw new IllegalArgumentException("Unexpected context"); + this.context = null; + disposed = true; + } + + public Integer getInt() { + return injectedInteger; + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java new file mode 100644 index 00000000000..c1417a1e59d --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +/** + * Test class to check injection mechanism into classes with inheritance + */ +public class ObjectSubClass extends ObjectSuperClass { + @Inject + /* package */Integer Integer; + + private Object myObject; + + public int setObjectCalled = 0; + public int setSubFinalized = 0; + public int postConstructSetObjectCalled; + public int postConstructSetOverriddenCalled; + public int subPostConstructCount; + public int subPreDestroyCount; + public int overriddenPreDestroyCount; + + public ObjectSubClass() { + super(); + } + + @Inject + public void ObjectViaMethod(Float f) { + myObject = f; + setObjectCalled++; + } + + @Override + @Inject + public void OverriddenMethod(Float f) { + setOverriddenCalled++; + } + + @Override + @Inject + public void contextSet(IEclipseContext context) { + super.contextSet(context); + setSubFinalized++; + } + + public Integer getInteger() { + return Integer; + } + + public Object getObjectViaMethod() { + return myObject; + } + + public int getFinalizedCount() { + return setSubFinalized; + } + + public int getOverriddenCount() { + return setOverriddenCalled; + } + + @PostConstruct + public void subPostConstruct() { + postConstructSetObjectCalled = setObjectCalled; + postConstructSetStringCalled = setStringCalled; + postConstructSetOverriddenCalled = setOverriddenCalled; + subPostConstructCount++; + } + + @PreDestroy + public void subPreDestroy() { + subPreDestroyCount++; + } + + @Override + @PreDestroy + public void overriddenPreDestroy() { + overriddenPreDestroyCount++; + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java new file mode 100644 index 00000000000..f144558d2bc --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +/** + * Test class to check injection mechanism into classes with inheritance + */ +public class ObjectSuperClass { + + protected IEclipseContext context; + @Inject + private String String; + private String myString; + + public int postConstructSetStringCalled; + public int setFinalizedCalled = 0; + public int setStringCalled = 0; + public int superPostConstructCount; + public int superPreDestroyCount; + public int setOverriddenCalled = 0; + + public ObjectSuperClass() { + // placeholder + } + + @Inject + public void contextSet(IEclipseContext context) { + this.context = context; + setFinalizedCalled++; + } + + public IEclipseContext getContext() { + return context; + } + + public int getFinalizedCalled() { + return setFinalizedCalled; + } + + public String getString() { + return String; + } + + public String getStringViaMethod() { + return myString; + } + + @Inject + public void OverriddenMethod(Float f) { + setOverriddenCalled++; + } + + @Inject + public void StringViaMethod(String string) { + myString = string; + setStringCalled++; + } + + @PostConstruct + public void superPostConstruct() { + // record setter invocation counts at time of post construct invocation + postConstructSetStringCalled = setStringCalled; + superPostConstructCount++; + } + + @PreDestroy + public void superPreDestroy() { + superPreDestroyCount++; + } + + @PreDestroy() + public void overriddenPreDestroy() { + // + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java new file mode 100644 index 00000000000..1edb3cabffc --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; + +public class OptionalAnnotations { + + @Inject @Optional + public Float f = null; + + public Double d; + public String s = "ouch"; + public Integer i; + + public int methodOptionalCalled = 0; + public int methodRequiredCalled = 0; + + public OptionalAnnotations() { + // placehodler + } + + @Inject @Optional + public void methodOptional(Double d) { + this.d = d; + methodOptionalCalled++; + } + + @Inject + public void methodRequired(@Optional String s, Integer i) { + this.s = s; + this.i = i; + methodRequiredCalled++; + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java new file mode 100644 index 00000000000..33ce50ed91f --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +public class ParentContextDisposalTest { + static class Target { + int pc = 0; + int pd = 0; + + @Inject + @Named("o") + Object o; + + @PostConstruct + void pc() { + pc++; + } + + @PreDestroy + void pd() { + pd++; + } + } + + @Test + public void testParentContextDisposal() { + IEclipseContext context = EclipseContextFactory.create(); + IEclipseContext child = context.createChild(); + child.set("o", new Object()); + + Target target = ContextInjectionFactory.make(Target.class, child); + assertEquals(1, target.pc); + + context.dispose(); + assertEquals(1, target.pd); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/PrintService.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/PrintService.java new file mode 100644 index 00000000000..45a1a0647de --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/PrintService.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +/** + * A toy service implementation that prints a message. + */ +public interface PrintService { + public static final String SERVICE_NAME = PrintService.class.getName(); + + public void print(String message); +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java new file mode 100644 index 00000000000..44dae9927cd --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.IInjector; +import org.eclipse.e4.core.di.InjectorFactory; +import org.eclipse.e4.core.di.annotations.Execute; +import org.junit.Test; + + +/** + * Testing provider interface + */ +public class ProviderInjectionTest { + + static public class TestData { + + public String data; + + @Inject + public TestData(String tmp) { + data = tmp; + } + } + + static public class TestInvokeClass { + public Provider provider; + public TestInvokeClass() { + // placeholder + } + @Execute + public int execute(Provider arg) { + provider = arg; + return 1; + } + } + + static public class TestConstructorClass { + public Provider provider; + + @Inject + public TestConstructorClass(Provider provider) { + this.provider = provider; + } + } + + @Test + public synchronized void testInvokeWithProvider() { + + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(String.class.getName(), "abc"); + IInjector injector = InjectorFactory.getDefault(); + injector.addBinding(TestData.class); + + TestInvokeClass userObject = new TestInvokeClass(); + assertEquals(1, ContextInjectionFactory.invoke(userObject, Execute.class, context, null)); + + assertNotNull(userObject.provider.get()); + assertEquals("abc", userObject.provider.get().data); + } + + @Test + public synchronized void testConstructorWithProvider() { + // create context + IEclipseContext context = EclipseContextFactory.create(); + context.set(String.class.getName(), "abc"); + IInjector injector = InjectorFactory.getDefault(); + injector.addBinding(TestData.class); + + TestConstructorClass userObject = ContextInjectionFactory.make(TestConstructorClass.class, context); + + assertNotNull(userObject); + assertNotNull(userObject.provider); + assertNotNull(userObject.provider.get()); + assertEquals("abc", userObject.provider.get().data); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java new file mode 100644 index 00000000000..84e6ce88bdb --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java @@ -0,0 +1,394 @@ +/******************************************************************************* + * Copyright (c) 2009, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.eclipse.osgi.service.debug.DebugOptions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; + +/** + * Tests for contexts used in OSGi services. + */ +public class ServiceContextTest { + static class Crayon { + @Inject + IPaletteService palette; + + String msg; + + public void draw() { + if (palette == null) { + msg = "I'm out of ink!"; + } else { + msg = "My ink is " + palette.getColor(); + } + } + } + + static enum Color { + RED, BLUE, YELLOW, GREEN, ORANGE, PURPLE; + } + + interface IPaletteService { + public Color getColor(); + } + + static class PaletteImpl implements IPaletteService { + private final Color color; + + PaletteImpl(Color color) { + this.color = color; + } + + @Override + public Color getColor() { + return color; + } + } + + static class Printer { + @Inject @Optional + PrintService printer; + + public void print(String message) { + if (printer != null) { + printer.print(message); + } + } + } + + static class TestBean { + @Inject + @Optional + TestService testService; + + @Inject + @Optional + TestOtherService testOtherService; + } + + private IEclipseContext context; + private final List> registrations = new ArrayList<>(); + + @Before + public void setUp() throws Exception { + //don't use the global shared service context to avoid contamination across tests + BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext(); + context = EclipseContextFactory.getServiceContext(bundleContext); + registrations.clear(); + } + + @After + public void tearDown() throws Exception { + // Consumers must not dispose OSGi context as it is reused + //context.dispose(); + for (ServiceRegistration reg : registrations) { + try { + reg.unregister(); + } catch (IllegalStateException e) { + //ignore + } + } + registrations.clear(); + context = null; + } + + @Test + public void testDeclarativeService() { + assertTrue(context.containsKey("sum")); + assertEquals(0, context.get("sum")); + context.set("x", 1); + context.set("y", 2); + int result = (Integer) context.get("sum"); + assertEquals("1.0", 3, result); + context.set("x", 5); + result = (Integer) context.get("sum"); + assertEquals("1.0", 7, result); + } + + /** + * Tests accessing OSGi services through a child context that is not aware of them. + */ + @Test + public void testServiceContextAsParent() { + IEclipseContext child = context.createChild( "child"); + DebugOptions service = (DebugOptions) child.get(DebugOptions.class.getName()); + assertNotNull(service); + } + + @Test + public void testServiceInjection() { + ServiceRegistration reg1 = null; + ServiceRegistration reg2 = null; + try { + Printer userObject = new Printer(); + + StringPrintService stringPrint1 = new StringPrintService(); + BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext(); + reg1 = bundleContext.registerService(PrintService.SERVICE_NAME, stringPrint1, null); + + ContextInjectionFactory.inject(userObject, context); + userObject.print("test"); + assertEquals("1.0", "test", stringPrint1.toString()); + + // now remove the service + reg1.unregister(); + reg1 = null; + userObject.print("another test"); + // the string should be unchanged + assertEquals("1.1", "test", stringPrint1.toString()); + assertNull("1.2", userObject.printer); + + // register a different service implementation + StringPrintService stringPrint2 = new StringPrintService(); + reg2 = bundleContext.registerService(PrintService.SERVICE_NAME, stringPrint2, null); + userObject.print("yet another test"); + // the second string should have the value + assertEquals("2.0", "test", stringPrint1.toString()); + assertEquals("2.1", "yet another test", stringPrint2.toString()); + reg2.unregister(); + reg2 = null; + assertNull("2.2", userObject.printer); + } finally { + if (reg1 != null) { + reg1.unregister(); + reg1 = null; + } + if (reg2 != null) { + reg2.unregister(); + reg2 = null; + } + } + } + + @Test + public void testServiceAddition() { + ServiceRegistration reg1 = null; + try { + Printer userObject = new Printer(); + ContextInjectionFactory.inject(userObject, context); + + StringPrintService stringPrint1 = new StringPrintService(); + BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext(); + reg1 = bundleContext.registerService(PrintService.SERVICE_NAME, stringPrint1, null); + + userObject.print("test"); + assertEquals("1.0", "test", stringPrint1.toString()); + } finally { + if (reg1 != null) { + reg1.unregister(); + reg1 = null; + } + } + } + + protected void ensureUnregistered(ServiceRegistration reg) { + registrations.add(reg); + } + + /** + * Tests that OSGi services are released when their context is disposed. + */ + @Test + public void testServiceRemovalOnContextDispose() { + StringPrintService stringPrint1 = new StringPrintService(); + BundleContext bundleContext = CoreTestsActivator.getDefault() + .getBundleContext(); + Bundle otherBundle = null; + for (Bundle b : bundleContext.getBundles()) { + if (b.getSymbolicName().equals("org.eclipse.core.tests.harness")) { + otherBundle = b; + break; + } + } + assertNotNull(otherBundle); + IEclipseContext otherServiceContext = EclipseContextFactory + .getServiceContext(otherBundle.getBundleContext()); + ServiceRegistration reg1 = bundleContext.registerService( + PrintService.SERVICE_NAME, stringPrint1, null); + try { + ServiceReference ref = reg1.getReference(); + + PrintService service = (PrintService) otherServiceContext + .get(PrintService.SERVICE_NAME); + assertEquals("1.0", stringPrint1, service); + assertEquals("1.1", 1, ref.getUsingBundles().length); + service = null; + otherServiceContext.dispose(); + assertNull("2.0", ref.getUsingBundles()); + } finally { + reg1.unregister(); + } + } + + @Test + public void testRecursiveServiceRemoval() { + BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext(); + ServiceRegistration reg1 = bundleContext.registerService(PrintService.SERVICE_NAME, new StringPrintService(), null); + final IEclipseContext child = context.createChild(); + final IEclipseContext child2 = context.createChild(); + child.get(PrintService.SERVICE_NAME); + child2.get(PrintService.SERVICE_NAME); + ensureUnregistered(reg1); + final boolean[] done = new boolean[] {false}; + context.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + if (context.get(PrintService.SERVICE_NAME) == null) { + child.dispose(); + done[0] = true; + } + return true; + } + }); + reg1.unregister(); + } + + @Test + public void testServiceExample() { + BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext(); + ServiceRegistration reg = bundleContext.registerService(IPaletteService.class.getName(), new PaletteImpl(Color.BLUE), null); + IEclipseContext context = EclipseContextFactory.getServiceContext(bundleContext); + Crayon crayon = new Crayon(); + ContextInjectionFactory.inject(crayon, context); + crayon.draw(); + reg.unregister(); + crayon.draw(); + } + + @Test + public void testOptionalReferences() throws InterruptedException { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context); + TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext); + + assertNull(bean.testService); + + ServiceReference ref = context.getServiceReference(TestServiceController.class); + TestServiceController controller = context.getService(ref); + try { + controller.enableTestServiceA(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNotNull(bean.testService); + assertSame(TestServiceA.class, bean.testService.getClass()); + assertNotNull(bean.testOtherService); + assertSame(TestServiceA.class, bean.testOtherService.getClass()); + + controller.enableTestServiceB(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNotNull(bean.testService); + assertSame(TestServiceB.class, bean.testService.getClass()); + assertNotNull(bean.testOtherService); + assertSame(TestServiceB.class, bean.testOtherService.getClass()); + + controller.disableTestServiceB(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNotNull(bean.testService); + assertSame(TestServiceA.class, bean.testService.getClass()); + assertNotNull(bean.testOtherService); + assertSame(TestServiceA.class, bean.testOtherService.getClass()); + + controller.disableTestServiceA(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNull(bean.testService); + assertNull(bean.testOtherService); + } finally { + controller.disableTestServiceA(); + controller.disableTestServiceB(); + // give the service registry and the injection some time to ensure + // clear state after this test + Thread.sleep(100); + } + } + + @Test + public void testServiceRanking() throws InterruptedException { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context); + TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext); + + assertNull(bean.testService); + + ServiceReference ref = context.getServiceReference(TestServiceController.class); + TestServiceController controller = context.getService(ref); + try { + controller.enableTestServiceB(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNotNull(bean.testService); + assertSame(TestServiceB.class, bean.testService.getClass()); + assertNotNull(bean.testOtherService); + assertSame(TestServiceB.class, bean.testOtherService.getClass()); + + // enable a service with a lower ranking + controller.enableTestServiceA(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNotNull(bean.testService); + // we expect that still the highest ranked service is injected + assertSame(TestServiceB.class, bean.testService.getClass()); + assertNotNull(bean.testOtherService); + assertSame(TestServiceB.class, bean.testOtherService.getClass()); + + controller.disableTestServiceB(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNotNull(bean.testService); + assertSame(TestServiceA.class, bean.testService.getClass()); + assertNotNull(bean.testOtherService); + assertSame(TestServiceA.class, bean.testOtherService.getClass()); + + controller.disableTestServiceA(); + // give the service registry and the injection some time + Thread.sleep(100); + assertNull(bean.testService); + assertNull(bean.testOtherService); + } finally { + controller.disableTestServiceA(); + controller.disableTestServiceB(); + // give the service registry and the injection some time to ensure + // clear state after this test + Thread.sleep(100); + } + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/StringPrintService.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/StringPrintService.java new file mode 100644 index 00000000000..d96b059442c --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/StringPrintService.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +/** + * + */ +public class StringPrintService implements PrintService { + private final StringBuilder buf = new StringBuilder(); + + @Override + public void print(String message) { + buf.append(message); + } + + @Override + public String toString() { + return buf.toString(); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java new file mode 100644 index 00000000000..5c3bfa99048 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.InvocationTargetException; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +public class TestConstructorInjection { + + static class TestConstructorObject { + + public boolean defaultConstructorCalled = false; + public boolean constructorIntStrCalled = false; + public boolean constructorIntBoolCalled = false; + public boolean injectedMethodCalled = false; + public boolean nonInjectedMethodCalled = false; + + @Inject + private Character c; + + public Integer i; + public String s; + public Boolean b; + public Double d; + public Float f; + + public boolean orderCorrect = true; + + public TestConstructorObject() { + defaultConstructorCalled = true; + } + + public TestConstructorObject(Integer i, String s) { + constructorIntStrCalled = true; + this.i = i; + this.s = s; + } + + @Inject + public TestConstructorObject(Integer i, Boolean b) { + constructorIntBoolCalled = true; + this.i = i; + this.b = b; + // the constructor should be called first + if ((c != null) || (d != null) || (f != null)) { + orderCorrect = false; + } + } + + @Inject + public void injectedMethod(Double d, Float f) { + injectedMethodCalled = true; + this.d = d; + this.f = f; + // the method injection after constructor and field injection + if ((c == null) || (i == null) || (b == null)) { + orderCorrect = false; + } + } + + public void nonInjectedMethod(Double d) { + nonInjectedMethodCalled = true; + this.d = d; + } + + public Character getChar() { + return c; + } + } + + @Test + public void testConstructorInjection() throws InvocationTargetException, InstantiationException { + IEclipseContext context = EclipseContextFactory.create(); + Integer intValue = Integer.valueOf(123); + context.set(Integer.class.getName(), intValue); + Boolean boolValue = Boolean.TRUE; + context.set(Boolean.class.getName(), boolValue); + Double doubleValue = Double.valueOf(1.23); + context.set(Double.class.getName(), doubleValue); + Float floatValue = Float.valueOf(12.3f); + context.set(Float.class.getName(), floatValue); + Character charValue = Character.valueOf('v'); + context.set(Character.class.getName(), charValue); + + Object result = ContextInjectionFactory.make(TestConstructorObject.class, context); + assertNotNull(result); + assertTrue(result instanceof TestConstructorObject); + + TestConstructorObject testObject = ((TestConstructorObject) result); + + assertFalse(testObject.defaultConstructorCalled); + assertFalse(testObject.constructorIntStrCalled); + assertTrue(testObject.constructorIntBoolCalled); + assertTrue(testObject.injectedMethodCalled); + assertFalse(testObject.nonInjectedMethodCalled); + assertTrue(testObject.orderCorrect); + + assertEquals(intValue, testObject.i); + assertEquals(boolValue, testObject.b); + assertEquals(doubleValue, testObject.d); + assertEquals(floatValue, testObject.f); + assertEquals(charValue, testObject.getChar()); + assertNull(testObject.s); + + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestOtherService.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestOtherService.java new file mode 100644 index 00000000000..b983f30846a --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestOtherService.java @@ -0,0 +1,5 @@ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +public interface TestOtherService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestService.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestService.java new file mode 100644 index 00000000000..11f52fabd22 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestService.java @@ -0,0 +1,5 @@ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +public interface TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceA.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceA.java new file mode 100644 index 00000000000..aa1eac4f02d --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceA.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import org.osgi.service.component.annotations.Component; + +@Component(enabled = false) +public class TestServiceA implements TestService, TestOtherService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceB.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceB.java new file mode 100644 index 00000000000..32df30315d7 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceB.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import org.osgi.service.component.annotations.Component; + +@Component(enabled = false, property = "service.ranking:Integer=5") +public class TestServiceB implements TestService, TestOtherService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceController.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceController.java new file mode 100644 index 00000000000..6873ed63683 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestServiceController.java @@ -0,0 +1,32 @@ +package org.eclipse.e4.core.internal.tests.contexts.inject; + +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; + +@Component(service = TestServiceController.class) +public class TestServiceController { + + ComponentContext context; + + @Activate + void activate(ComponentContext context) { + this.context = context; + } + + public void enableTestServiceA() { + this.context.enableComponent(TestServiceA.class.getName()); + } + + public void disableTestServiceA() { + this.context.disableComponent(TestServiceA.class.getName()); + } + + public void enableTestServiceB() { + this.context.enableComponent(TestServiceB.class.getName()); + } + + public void disableTestServiceB() { + this.context.disableComponent(TestServiceB.class.getName()); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/performance/ContextPerformanceTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/performance/ContextPerformanceTest.java new file mode 100644 index 00000000000..b4ee9129ac4 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/contexts/performance/ContextPerformanceTest.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.contexts.performance; + +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.preferences.IPreferencesService; +import org.eclipse.core.tests.harness.PerformanceTestRunner; +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.eclipse.osgi.service.datalocation.Location; +import org.eclipse.osgi.service.debug.DebugOptions; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * + */ +public class ContextPerformanceTest extends TestCase { + + IEclipseContext parentContext, context; + + public static Test suite() { + return new TestSuite(ContextPerformanceTest.class); + // TestSuite suite = new TestSuite(); + // suite.addTest(new ContextPerformanceTest("testSetValueRunAndTrack")); + // return suite; + } + + public ContextPerformanceTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + parentContext = EclipseContextFactory.getServiceContext(CoreTestsActivator.getDefault().getBundleContext()); + context = parentContext.createChild(getName()); + + // add some values to the contexts + for (int i = 0; i < 100; i++) { + context.set("Value-" + i, Integer.valueOf(i)); + } + // do some additional service lookups on non-existent keys + for (int i = 0; i < 1000; i++) { + context.get("NonExistentValue-" + i); + } + + // lookup some OSGi services + context.get(DebugOptions.class.getName()); + context.get(IAdapterManager.class.getName()); + context.get(IExtensionRegistry.class.getName()); + context.get(IPreferencesService.class.getName()); + context.get(Location.class.getName()); + } + + public void testLookup() { + new PerformanceTestRunner() { + @Override + protected void test() { + context.get("something"); + } + }.run(this, 10, 600000); + } + + public void testLookupContextFunction() { + context.set("somefunction", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return "result"; + } + }); + new PerformanceTestRunner() { + @Override + protected void test() { + context.get("somefunction"); + } + }.run(this, 10, 5000000); + } + + public void testSetContextFunction() { + context.set("somefunction", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return context.get("something"); + } + }); + new PerformanceTestRunner() { + int i = 0; + + @Override + protected void test() { + context.set("something", "value-" + i++); + } + }.run(this, 10, 600000); + } + + /** + * Tests setting a value in a context that a RAT is listening to. This test mimics what occurs + * when handlers change in e4. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=305038 + */ + public void testSetValueRunAndTrack() { + context.set("somefunction", new ContextFunction() { + @Override + public Object compute(IEclipseContext context, String contextKey) { + // make sure this function has a large number of dependencies + for (int i = 0; i < 1000; i++) { + context.get("NonExistentValue-" + i); + } + return context.get("something"); + } + }); + context.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + context.get("somefunction"); + return true; + } + }); + new PerformanceTestRunner() { + int i = 0; + + @Override + protected void test() { + context.set("something", "value-" + i++); + } + }.run(this, 10, 400); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java new file mode 100644 index 00000000000..f5453437c5f --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2012, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274, 496305 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.InjectionException; +import org.eclipse.e4.core.di.annotations.Creatable; +import org.junit.Before; +import org.junit.Test; + +public class AutoConstructWithCreatableTest { + + private IEclipseContext context; + + @Creatable + static class Dependent1 { + @Inject + public Dependent1() { + // placeholder + } + } + + static class Dependent2 { + @Inject + public Dependent2() { + // placeholder + } + } + + static class Consumer1 { + @Inject + public Consumer1(Dependent1 dep) { + // placeholder + } + } + + static class Consumer2 { + @Inject + public Consumer2(Dependent2 dep) { + // placeholder + } + } + + @Before + public void createContext() { + context = EclipseContextFactory.create(); + } + + /** + * Checks that classes with @Creatable are auto-constructed + */ + @Test + public void testCreatableIsCreated() { + Consumer1 consumer1 = ContextInjectionFactory.make(Consumer1.class, context); + assertNotNull(consumer1); + + boolean exception = false; + try { + ContextInjectionFactory.make(Consumer2.class, context); + } catch (InjectionException e) { + exception = true; // expected + } + assertTrue(exception); + + context.set(Dependent2.class, new Dependent2()); + Consumer2 consumer2 = ContextInjectionFactory.make(Consumer2.class, context); + assertNotNull(consumer2); + } + + /** + * Checks that only classes with @Creatable are auto-constructed + */ + @Test(expected = InjectionException.class) + public void testNonCreatableInstanceAreNotCreated() { + ContextInjectionFactory.make(Consumer2.class, context); + // should not be reached as exception is thrown + assertTrue(false); + } + + @Test // ensure "normal" dependency injection + public void testNonCreatableInstancesAreUsedFromContext() { + context.set(Dependent2.class, new Dependent2()); + Consumer2 consumer2 = ContextInjectionFactory.make(Consumer2.class, context); + assertNotNull(consumer2); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java new file mode 100644 index 00000000000..ef24fe0d6a9 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.di.extensions.EventTopic; +import org.junit.Test; +/** + * Checks that injected objects that do not have normal links + * established to the context are still notified on context + * disposal. + * (No links: nothing was actually injected; or only IEclipseContext was injected; + * or constructor injection was used.) + * See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=301462 . + */ +public class DisposeClassLinkTest { + + public static class MyTest { + private int count = 0; + + public int getCount() { + return count; + } + + @PreDestroy + void preDestroy() { + count++; + } + } + + public static class InjectionObject { + + @Inject + IEclipseContext context; + + int postConstruct = 0; + int preDestroy = 0; + + @PostConstruct + void construct() { + postConstruct++; + } + + @PreDestroy + void destroy() { + preDestroy++; + } + } + + public static class TestBug430041 { + int preDestroy = 0; + + @Inject + @Optional + public void inject(@EventTopic("Bla") String bla) { + + } + + @PreDestroy + void destroy() { + preDestroy++; + } + } + + @Test + public void testMake() throws Exception { + IEclipseContext context = EclipseContextFactory.create(); + MyTest test = ContextInjectionFactory.make(MyTest.class, context); + + assertEquals(0, test.getCount()); + context.dispose(); + assertEquals(1, test.getCount()); + } + + @Test + public void testDisposeParent() throws Exception { + IEclipseContext parentContext = EclipseContextFactory.create(); + IEclipseContext context = parentContext.createChild(); + MyTest test = ContextInjectionFactory.make(MyTest.class, context); + + assertEquals(0, test.getCount()); + context.dispose(); + assertEquals(1, test.getCount()); + parentContext.dispose(); + assertEquals(1, test.getCount()); + } + + @Test + public void testInject() throws Exception { + IEclipseContext parentContext = EclipseContextFactory.create(); + IEclipseContext context = parentContext.createChild(); + MyTest test = new MyTest(); + ContextInjectionFactory.inject(test, context); + + assertEquals(0, test.getCount()); + context.dispose(); + assertEquals(1, test.getCount()); + } + + @Test + public void testDisposeParentFirst() throws Exception { + IEclipseContext parentContext = EclipseContextFactory.create(); + IEclipseContext context = parentContext.createChild(); + MyTest test = new MyTest(); + ContextInjectionFactory.inject(test, context); + + assertEquals(0, test.getCount()); + context.dispose(); + assertEquals(1, test.getCount()); + parentContext.dispose(); + assertEquals(1, test.getCount()); + } + + @Test + public void testInjectedWithContext() throws Exception { + IEclipseContext context = EclipseContextFactory.create(); + + InjectionObject obj = ContextInjectionFactory.make(InjectionObject.class, context); + + assertEquals("The object has been injected with the context", context, obj.context); + assertEquals("@PostConstruct should have been called once", 1, obj.postConstruct); + assertEquals("@PreDestroy should not have been called", 0, obj.preDestroy); + + context.dispose(); + + assertNotNull(obj.context); + assertEquals("@PostConstruct should only have been called once", 1, obj.postConstruct); + assertEquals("@PreDestroy should have been called during uninjection", 1, obj.preDestroy); + } + + @Test + public void testBug430041() { + IEclipseContext context = EclipseContextFactory.create(); + TestBug430041 obj = ContextInjectionFactory.make(TestBug430041.class, context); + context.dispose(); + assertEquals(1, obj.preDestroy); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java new file mode 100644 index 00000000000..978e86dc110 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + +/** + * Checks injection of arrays + */ +public class InjectArraysTest { + + static class TestClass { + @Inject @Named("test_array_String") + public String[] stringArray; + + @Inject + public Integer[] integerArray; + + + public int[] intArray; + public char[] charAray; + + @Inject + public void set(@Named("test_array_int") int[] intArray, @Named("test_array_char") char[] charAray) { + this.intArray = intArray; + this.charAray = charAray; + } + } + + @Test + public void testArrayInjection() { + String[] arrayString = new String[] { "abc", "xyz", "ttt" }; + Integer[] arrayInteger = new Integer[] { 5, 6, 7 }; + int[] arrayInt = new int[] { 1, 2, 3 }; + char[] arrayChar = new char[] { 'a', 'b', 'c' }; + + IEclipseContext context = EclipseContextFactory.create(); + context.set("test_array_String", arrayString); + context.set(Integer[].class, arrayInteger); + context.set("test_array_int", arrayInt); + context.set("test_array_char", arrayChar); + + TestClass testClass = ContextInjectionFactory.make(TestClass.class, context); + checkArraysEqual(arrayString, testClass.stringArray); + checkArraysEqual(arrayInteger, testClass.integerArray); + checkArraysEqual(arrayInt, testClass.intArray); + checkArraysEqual(arrayChar, testClass.charAray); + } + + private void checkArraysEqual(Object array1, Object array2) { + assertNotNull(array2); + assertEquals(array1, array2); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java new file mode 100644 index 00000000000..16a8afdadfc --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertEquals; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +/** + * Checks conversion of primitive types + */ +public class InjectBaseTypeTest { + + static class TestClass { + @Inject @Named("test_int") + public int intField; + + @Inject @Named("test_int_optional") @Optional + public int intFieldOptional; + + @Inject @Named("test_long") + public long longField; + + @Inject @Named("test_float") + public float floatField; + + @Inject @Named("test_double") + public double doubleField; + + @Inject @Named("test_short") + public short shortField; + + @Inject @Named("test_byte") + public byte byteField; + + @Inject @Optional @Named("test_boolean") + public boolean booleanField; + + @Inject @Named("test_char") + public char charField; + + public int intArg; + public char charArg; + public boolean booleanArg; + + @Inject + public void set(@Named("test_int") int intArg, @Named("test_char") char charArg, @Named("test_boolean") boolean booleanArg) { + this.intArg = intArg; + this.charArg = charArg; + this.booleanArg = booleanArg; + } + + } + + @Test + public void testPrimitiveTypes() { + IEclipseContext context = EclipseContextFactory.create(); + context.set("test_int", 12); + context.set("test_long", 124564523466L); + context.set("test_float", 12.34f); + context.set("test_double", 12.34534534563463466546d); + context.set("test_short", (short)10); + context.set("test_byte", (byte)55); + context.set("test_boolean", true); + context.set("test_char", 'a'); + + TestClass testClass = ContextInjectionFactory.make(TestClass.class, context); + + assertEquals(12, testClass.intField); + assertEquals(0, testClass.intFieldOptional); + assertEquals(124564523466L, testClass.longField); + assertEquals(12.34f, testClass.floatField, 0); + assertEquals(12.34534534563463466546d, testClass.doubleField, 0); + assertEquals((short)10, testClass.shortField); + assertEquals((byte)55, testClass.byteField); + assertEquals(true, testClass.booleanField); + assertEquals('a', testClass.charField); + + assertEquals(12, testClass.intArg); + assertEquals('a', testClass.charArg); + assertEquals(true, testClass.booleanArg); + + // test end-of-life reset of values + ContextInjectionFactory.uninject(testClass, context); + + // optional fields are reset to default; + // non-optional keep their values + assertEquals(12, testClass.intField); + assertEquals(0, testClass.intFieldOptional); // optional + assertEquals(124564523466L, testClass.longField); + assertEquals(12.34f, testClass.floatField, 0); + assertEquals(12.34534534563463466546d, testClass.doubleField, 0); + assertEquals((short)10, testClass.shortField); + assertEquals((byte)55, testClass.byteField); + assertEquals(false, testClass.booleanField); // optional + assertEquals('a', testClass.charField); + + assertEquals(12, testClass.intArg); + assertEquals('a', testClass.charArg); + assertEquals(true, testClass.booleanArg); + + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java new file mode 100644 index 00000000000..71b00e7dbb6 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2018 BestSolution.at and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Tom Schindl - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.InjectionException; +import org.eclipse.e4.core.di.annotations.Execute; +import org.junit.Test; + +public class InjectBridgeTest { + static class Base { + public void testInject(T value) { + + } + + public void testInvoke(T value) { + + } + } + + static class Concrete extends Base { + @Inject + @Override + public void testInject(String value) { + } + + @Override + @Execute + public void testInvoke(String value) { + + } + } + + @Test + public void testInjection() { + IEclipseContext context = EclipseContextFactory.create(); + context.set(String.class, "Value"); + + ContextInjectionFactory.make(Concrete.class, context); + } + + @Test(expected = InjectionException.class) + public void testInjectionFail() { + IEclipseContext context = EclipseContextFactory.create(); + context.set(Object.class, "Value"); + + ContextInjectionFactory.make(Concrete.class, context); + } + + @Test + public void testInvokation() { + IEclipseContext context = EclipseContextFactory.create(); + context.set(String.class, "Value"); + + ContextInjectionFactory.invoke(new Concrete(), Execute.class, context); + } + + @Test(expected = InjectionException.class) + public void testInvokationFail() { + IEclipseContext context = EclipseContextFactory.create(); + context.set(Object.class, "Value"); + ContextInjectionFactory.invoke(new Concrete(), Execute.class, context); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java new file mode 100644 index 00000000000..753d88e0b55 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.InjectionException; +import org.junit.Test; + +public class InjectionOrderTest { + + public interface ITestObject { + + } + + static public class InjectUnsatisfied { + + @Inject + ITestObject object; + + static public int count = 0; + + @PostConstruct + public void postConstruct() { + count++; + object.toString(); + } + + @PreDestroy + public void preDestroy() { + count++; + object.toString(); + } + } + + /** + * Make sure special methods are not getting called in case injection failed + */ + @Test + public void testSpecialMethodOnFailure() { + IEclipseContext appContext = EclipseContextFactory.create(); + boolean exception = false; + try { + ContextInjectionFactory.make(InjectUnsatisfied.class, appContext); + } catch (InjectionException e) { + exception = true; + } + assertTrue(exception); + appContext.dispose(); + assertEquals(0, InjectUnsatisfied.count); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java new file mode 100644 index 00000000000..1cc34cbc93c --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2011, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.lang.ref.WeakReference; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.junit.Test; + +/** + * Test that we don't hold on to the values calculated during injection. + * This test relies on VM performing garbage collection in System.gc(). + * The actual VM processing of GC requests is up to the implementation + * so this test might not work on all VMs or might become invalid on + * future VMs. + */ +public class InjectionResultLeakTest { + + static class PartConsumer { + Object part; + + @Inject + void setPart(@Optional @Named("testGC") Object part) { + this.part = part; + } + } + + @Test + public void testLeaks() { + IEclipseContext context = EclipseContextFactory.create(); + WeakReference ref; + + Object part = new Object(); + ref = new WeakReference<>(part); + assertEquals(part, ref.get()); + + context.set("testGC", part); + + PartConsumer consumer = ContextInjectionFactory.make( + PartConsumer.class, context); + assertEquals(part, consumer.part); + + part = null; // another "let's help GC" statement + context.remove("testGC"); + + assertNull(consumer.part); + + // gc a few times + System.runFinalization(); + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + System.gc(); + + // partA should have been gc'd + assertNull("The object should have been garbage collected", ref.get()); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTest.java new file mode 100644 index 00000000000..440ec4e4fe0 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTest.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.di.annotations.Execute; +import org.junit.Test; + +public class InvokeTest { + + /** + * Superclass + */ + static class TestSuperclass { + public int saveCount = 0; + @Execute + void something() { + saveCount++; + } + } + + /** + * Subclass + */ + static class TestSubclass extends TestSuperclass { + } + + /** + * Checks that superclass methods are called + */ + @Test + public void testSuperclassMethods() { + TestSubclass editor = new TestSubclass(); + ContextInjectionFactory.invoke(editor, Execute.class, EclipseContextFactory + .create()); + assertEquals(1, editor.saveCount); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTestMissingAnnotation.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTestMissingAnnotation.java new file mode 100644 index 00000000000..805bb33db0e --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/InvokeTestMissingAnnotation.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2014, 2016 vogella GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lars Vogel - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.di.InjectionException; +import org.eclipse.e4.core.di.annotations.Execute; +import org.junit.Test; + +/** + * Tests that that no method is called, it the @Execute annotation is not + * present and that an exception is thrown from the DI framework + */ +public class InvokeTestMissingAnnotation { + + /** + * Class to invoke for the test + */ + static class TestSuperclass { + public int saveCount = 0; + + // @Execute annotation missing on purpose + void execute() { + saveCount++; + } + } + + /** + * Checks that no methods is called and that an execution is thrown + */ + @Test(expected = InjectionException.class) + public void testCallMethodsWithMissingAnnotation() { + TestSuperclass editor = new TestSuperclass(); + ContextInjectionFactory.invoke(editor, Execute.class, EclipseContextFactory.create()); + } + + /** + * Checks that no methods is called and that no execution is thrown if a + * default is provide + */ + @Test + public void testCallMethodsWithMissingAnnotationNoExecution() { + TestSuperclass editor = new TestSuperclass(); + ContextInjectionFactory.invoke(editor, Execute.class, + EclipseContextFactory.create(), this); + + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java new file mode 100644 index 00000000000..1a57e37b3d9 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2011, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.InjectionException; +import org.junit.Test; + +public class RecursiveObjectCreationTest { + + static public class CheckSelfInject { + + public CheckSelfInject other; + + @Inject + public CheckSelfInject(CheckSelfInject other) { + this.other = other; + } + } + + /** + * Checks a simple case of constructor needing the same class + */ + @Test + public void testSelfInject() { + IEclipseContext context = EclipseContextFactory.create(); + boolean exceptionReceived = false; + try { + CheckSelfInject testInstance = ContextInjectionFactory.make(CheckSelfInject.class, context); + assertNotNull(testInstance); // unreachable + } catch (InjectionException e) { + exceptionReceived = true; + } + assertTrue(exceptionReceived); + } + + /////////////////////////////////////////////////////////////////////// + + static public class TestOuterClass { + + public class TestInnerClassInject { + @Inject + public TestInnerClassInject() { + // placeholder + } + } + + public TestInnerClassInject innerInject; + + @Inject + public TestOuterClass() { + // placeholder + } + + @PostConstruct + public void init(IEclipseContext context) { + innerInject = ContextInjectionFactory.make(TestInnerClassInject.class, context); + } + } + + /** + * Checks inner class using outer class which is still being created + */ + @Test + public void testNested() { + IEclipseContext context = EclipseContextFactory.create(); + boolean exceptionReceived = false; + try { + TestOuterClass outer = ContextInjectionFactory.make(TestOuterClass.class, context); + assertNotNull(outer); // unreachable + } catch (InjectionException e) { + exceptionReceived = true; + } + assertTrue(exceptionReceived); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RequestorTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RequestorTest.java new file mode 100644 index 00000000000..00f05581053 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/RequestorTest.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2013, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.lang.reflect.Field; + +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.InjectorFactory; +import org.eclipse.e4.core.internal.contexts.ContextObjectSupplier; +import org.eclipse.e4.core.internal.di.FieldRequestor; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +@SuppressWarnings("restriction") +public class RequestorTest { + public Object field; + public IEclipseContext context; + + @Test + public void testHashCode() throws Exception { + Field field = getClass().getField("field"); + assertNotNull(field); + FieldRequestor requestor = new FieldRequestor(field, + InjectorFactory.getDefault(), + ContextObjectSupplier.getObjectSupplier(context, + InjectorFactory.getDefault()), null, this, false); + int hash = requestor.hashCode(); + requestor.getReference().clear(); + assertEquals(hash, requestor.hashCode()); + } + + @Before + public void setUp() throws Exception { + context = EclipseContextFactory.create("RequestorTest"); + } + + @After + public void tearDown() throws Exception { + context.dispose(); + } + + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ComponentEnabler.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ComponentEnabler.java new file mode 100644 index 00000000000..84288f476d5 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ComponentEnabler.java @@ -0,0 +1,32 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; + +@Component(service = ComponentEnabler.class) +public class ComponentEnabler { + + ComponentContext context; + + @Activate + void activate(ComponentContext context) { + this.context = context; + } + + public void enableDisabledServiceA() { + this.context.enableComponent("DisabledServiceA"); + } + + public void disableDisabledServiceA() { + this.context.disableComponent("DisabledServiceA"); + } + + public void enableDisabledServiceB() { + this.context.enableComponent("DisabledServiceB"); + } + + public void disableDisabledServiceB() { + this.context.disableComponent("DisabledServiceB"); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceA.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceA.java new file mode 100644 index 00000000000..02f9a9d6536 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceA.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import org.osgi.service.component.annotations.Component; + +@Component(name = "DisabledServiceA", enabled = false, property = { "component=disabled" }) +public class DisabledServiceA implements TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceB.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceB.java new file mode 100644 index 00000000000..7f2f8640178 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/DisabledServiceB.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import org.osgi.service.component.annotations.Component; + +@Component(name = "DisabledServiceB", enabled = false, property = { "component=disabled", "service.ranking:Integer=5" }) +public class DisabledServiceB implements TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java new file mode 100644 index 00000000000..98801febfc4 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Dictionary; +import java.util.Hashtable; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.di.extensions.EventTopic; +import org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier; +import org.eclipse.e4.core.di.suppliers.IObjectDescriptor; +import org.eclipse.e4.core.di.suppliers.IRequestor; +import org.eclipse.e4.core.internal.di.osgi.ProviderHelper; +import org.eclipse.e4.core.internal.tests.di.extensions.InjectionEventTest.EventAdminHelper; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceRegistration; + +@SuppressWarnings("restriction") +public class ExtendedSupplierInjectionTests { + static final String TOPIC = "org/eclipse/e4/core/tests/di/extensions/ExtendedSupplierInjectionTests"; + static final String TOPIC_430041 = "org/eclipse/e4/core/tests/di/extensions/ExtendedSupplierInjectionTests430041"; + + static class EventTestObject { + static int count = 0; + + Object injectedObject; + + @Inject + @Optional + void dontExecute(@EventTopic(TOPIC) Object x) { + count++; + injectedObject = x; + } + } + + static class EventTestObject_430041 { + static int count = 0; + + Object injectedObject; + + private boolean destroyed; + + @Inject + @Optional + void dontExecute(@EventTopic(TOPIC_430041) Object x) { + count++; + injectedObject = x; + } + + @PreDestroy + void goDown() { + this.destroyed = true; + } + } + + private EventAdminHelper helper; + + @Before + public void setUp() { + InjectionEventTest.ensureEventAdminStarted(); + BundleContext bundleContext = FrameworkUtil.getBundle(getClass()) + .getBundleContext(); + IEclipseContext localContext = EclipseContextFactory + .getServiceContext(bundleContext); + helper = ContextInjectionFactory.make( + EventAdminHelper.class, localContext); + } + + /* Ensure extended suppliers are looked up first */ + @Test + public void testBug398728() { + IEclipseContext context = EclipseContextFactory.create(); + context.set(Object.class, new Object()); + + assertEquals(0, EventTestObject.count); + + EventTestObject target = ContextInjectionFactory.make( + EventTestObject.class, context); + // should be 0 since we haven't posted an event with this topic yet + assertEquals(0, EventTestObject.count); + + helper.sendEvent(TOPIC, "event1data"); + + assertEquals(1, EventTestObject.count); + assertEquals("event1data", target.injectedObject); + } + + @Test + public void testBug430041() { + IEclipseContext context = EclipseContextFactory.create(); + context.set(Object.class, new Object()); + + assertEquals(0, EventTestObject_430041.count); + + EventTestObject_430041 target = ContextInjectionFactory.make( + EventTestObject_430041.class, context); + context.set(EventTestObject_430041.class, target); + // should be 0 since we haven't posted an event with this topic yet + assertEquals(0, EventTestObject_430041.count); + + helper.sendEvent(TOPIC_430041, "event1data"); + + assertEquals(1, EventTestObject_430041.count); + assertEquals("event1data", target.injectedObject); + + context.dispose(); + assertTrue(target.destroyed); + + helper.sendEvent(TOPIC_430041, "event1data_disposed"); + + assertEquals(1, EventTestObject_430041.count); + assertEquals("event1data", target.injectedObject); + } + + /** bug 428837: ensure suppliers are ranked by service.ranking */ + @Test + public void testSupplierOrdering() { + BundleContext bc = FrameworkUtil.getBundle(getClass()) + .getBundleContext(); + ExtendedObjectSupplier supplier = new ExtendedObjectSupplier() { + @Override + public Object get(IObjectDescriptor descriptor, + IRequestor requestor, boolean track, boolean group) { + // TODO Auto-generated method stub + return null; + } + }; + Dictionary properties = new Hashtable<>(); + properties.put(ExtendedObjectSupplier.SERVICE_CONTEXT_KEY, + EventTopic.class.getName()); + properties.put(Constants.SERVICE_RANKING, 100); + ServiceRegistration sr = bc.registerService( + ExtendedObjectSupplier.SERVICE_NAME, supplier, properties); + try { + assertEquals(supplier, ProviderHelper.findProvider( + EventTopic.class.getName(), null)); + } finally { + sr.unregister(); + } + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceA.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceA.java new file mode 100644 index 00000000000..46bea2ecf66 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceA.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import org.osgi.service.component.annotations.Component; + +@Component(property = { "filtervalue=Test", "service.ranking:Integer=1" }) +public class FilterServiceA implements TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceB.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceB.java new file mode 100644 index 00000000000..25610b5534f --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/FilterServiceB.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import org.osgi.service.component.annotations.Component; + +@Component(property="filtervalue=Test") +public class FilterServiceB implements TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java new file mode 100644 index 00000000000..c6b077fc56e --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java @@ -0,0 +1,288 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.lang.reflect.InvocationTargetException; +import java.util.Dictionary; +import java.util.Hashtable; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.IInjector; +import org.eclipse.e4.core.di.InjectorFactory; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.di.extensions.EventTopic; +import org.eclipse.e4.core.di.internal.extensions.util.EventUtils; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventConstants; + +// TBD add auto-conversion? +@SuppressWarnings("restriction") +public class InjectionEventTest { + + static protected boolean testFailed = false; + + // Class used to test receiving events + static class InjectTarget { + public int counter1 = 0; + public int counter3 = 0; + + public String string1; + public String string3; + + public boolean valid = true; + + public MyBinding myBinding; + + public void resetCounters() { + counter1 = counter3 = 0; + } + + @Inject @Optional + public void receivedEvent1(@EventTopic("e4/test/event1") String string1) { + if (!valid) { + testFailed = true; + } + counter1++; + this.string1 = string1; + } + + @Inject + public void receivedOptionalEvent(MyBinding myBinding, @Optional @EventTopic("e4/test/event3") String string3) { + if (!valid) { + testFailed = true; + } + counter3++; + this.myBinding = myBinding; + this.string3 = string3; + } + } + + // Class used to test receiving events + static class InjectTargetEvent { + public int counter1 = 0; + public Event event; + + @Inject @Optional + public void receivedEvent1(@EventTopic("e4/test/eventInjection") Event event) { + counter1++; + this.event = event; + } + + } + + // Class used to test receiving events using wildcard + static class InjectStarEvent { + public int counter1 = 0; + public Event event; + + @Inject @Optional + public void receivedEvent1(@EventTopic("e4/test/*") Event event) { + counter1++; + this.event = event; + } + } + + // This tests and demos sending events + static public class EventAdminHelper { + @Inject + public EventAdmin eventAdmin; + + public void sendEvent(String topic, Object data) { + EventUtils.send(eventAdmin, topic, data); + } + + public void sendEvent(Event event) { + eventAdmin.sendEvent(event); + } + } + + // Tests mixed injection modes + @Singleton + static class MyBinding { + // static binding for injector + } + + private EventAdminHelper helper; + + @Before + public void setUp() throws Exception { + ensureEventAdminStarted(); + BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext(); + IEclipseContext localContext = EclipseContextFactory.getServiceContext(bundleContext); + helper = ContextInjectionFactory.make(EventAdminHelper.class, localContext); + } + + @Test + public void testEventInjection() throws InvocationTargetException, InstantiationException { + + IInjector injector = InjectorFactory.getDefault(); + injector.addBinding(MyBinding.class); + + IEclipseContext context = EclipseContextFactory.create(); + InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context); + + // initial state + assertEquals(0, target.counter1); + assertNull(target.string1); + assertEquals(1, target.counter3); + assertNull(target.string3); + assertNotNull(target.myBinding); + + // send event1 + helper.sendEvent("e4/test/event1", "event1data"); + + assertEquals(1, target.counter1); + assertEquals("event1data", target.string1); + assertEquals(1, target.counter3); + assertNull(target.string3); + assertNotNull(target.myBinding); + + // send event2 + helper.sendEvent("e4/test/event2", "event2data"); + + assertEquals(1, target.counter1); + assertEquals("event1data", target.string1); + assertEquals(1, target.counter3); + assertNull(target.string3); + assertNotNull(target.myBinding); + + // send event3 + helper.sendEvent("e4/test/event3", "event3data"); + + assertEquals(1, target.counter1); + assertEquals("event1data", target.string1); + assertEquals(2, target.counter3); + assertEquals("event3data", target.string3); + assertNotNull(target.myBinding); + + // send event1 again + helper.sendEvent("e4/test/event1", "abc"); + + assertEquals(2, target.counter1); + assertEquals("abc", target.string1); + assertEquals(2, target.counter3); + assertEquals("event3data", target.string3); + assertNotNull(target.myBinding); + } + + @Test + public void testInjectType() { + IEclipseContext context = EclipseContextFactory.create(); + InjectTargetEvent target = ContextInjectionFactory.make(InjectTargetEvent.class, context); + + // initial state + assertEquals(0, target.counter1); + assertNull(target.event); + + // send event + String eventTopic = "e4/test/eventInjection"; + Dictionary d = new Hashtable<>(); + d.put(EventConstants.EVENT_TOPIC, eventTopic); + d.put("data1", Integer.valueOf(5)); + d.put("data2", "sample"); + Event event = new Event(eventTopic, d); + helper.sendEvent(event); + + assertEquals(1, target.counter1); + assertEquals(event, target.event); + assertEquals(Integer.valueOf(5), target.event.getProperty("data1")); + assertEquals("sample", target.event.getProperty("data2")); + } + + // NOTE: this test relies on GC being actually done on the test object. + // Java does not guarantee that to happen, so, if this test starts to fail + // intermittently, feel free to comment it + @Test + public void testEventInjectionUnsubscribe() throws InvocationTargetException, InstantiationException { + IInjector injector = InjectorFactory.getDefault(); + injector.addBinding(MyBinding.class); + + wrapSetup(); // do it in a separate method to ease GC + System.gc(); + System.runFinalization(); + System.gc(); + helper.sendEvent("e4/test/event1", "wrong"); + assertFalse(testFailed); // target would have asserted if it is still subscribed + } + + @Test + public void testInjectWildCard() { + IEclipseContext context = EclipseContextFactory.create(); + InjectStarEvent target = ContextInjectionFactory.make(InjectStarEvent.class, context); + + // initial state + assertEquals(0, target.counter1); + assertNull(target.event); + + // send event + String eventTopic = "e4/test/eventInjection"; + Dictionary d = new Hashtable<>(); + d.put(EventConstants.EVENT_TOPIC, eventTopic); + d.put("data1", Integer.valueOf(5)); + d.put("data2", "sample"); + Event event = new Event(eventTopic, d); + helper.sendEvent(event); + + assertEquals(1, target.counter1); + assertEquals(event, target.event); + assertEquals(Integer.valueOf(5), target.event.getProperty("data1")); + assertEquals("sample", target.event.getProperty("data2")); + } + + private void wrapSetup() throws InvocationTargetException, InstantiationException { + IEclipseContext context = EclipseContextFactory.create(); + InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context); + // send event + helper.sendEvent("e4/test/event1", "event1data"); + assertEquals(1, target.counter1); + assertEquals("event1data", target.string1); + target.valid = false; + + } + + static void ensureEventAdminStarted() { + if (CoreTestsActivator.getDefault().getEventAdmin() == null) { + Bundle[] bundles = CoreTestsActivator.getDefault().getBundleContext().getBundles(); + for (Bundle bundle : bundles) { + if (!"org.eclipse.equinox.event".equals(bundle.getSymbolicName())) { + continue; + } + try { + bundle.start(Bundle.START_TRANSIENT); + } catch (BundleException e) { + e.printStackTrace(); + } + break; + } + } + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java new file mode 100644 index 00000000000..b1fef0aa783 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertEquals; + +import java.lang.reflect.InvocationTargetException; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.extensions.Preference; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.junit.Test; +import org.osgi.service.prefs.BackingStoreException; + +public class InjectionMixedSuppliersTest { + + static class InjectTarget { + public String pref; + public String other; + + @Inject + public void setPrefs(@Named("testMixed") String otherString, @Preference("injectedPrefs") String string) { + pref = string; + other = otherString; + } + } + + @Test + public void testPreferencesQualifier() throws BackingStoreException, InvocationTargetException, InstantiationException { + IEclipseContext context = EclipseContextFactory.create(); + setPreference("injectedPrefs", "abc"); + context.set("testMixed", "other"); + InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context); + + // test + assertEquals("abc", target.pref); + assertEquals("other", target.other); + + // change + setPreference("injectedPrefs", "xyz"); + context.set("testMixed", "bingo"); + + // re-test + assertEquals("xyz", target.pref); + assertEquals("bingo", target.other); + } + + private void setPreference(String key, String value) throws BackingStoreException { + String nodePath = CoreTestsActivator.getDefault().getBundleContext().getBundle().getSymbolicName(); + IEclipsePreferences node = InstanceScope.INSTANCE.getNode(nodePath); + node.put(key, value); + node.flush(); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java new file mode 100644 index 00000000000..9152f0ee4af --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Markus Alexander Kuppe and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * + * Contributors: + * Markus Alexander Kuppe - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertNotNull; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.extensions.OSGiBundle; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.junit.Test; +import org.osgi.framework.BundleContext; + +public class InjectionOSGiHandlerTest { + + public static class TestHandler { + + private BundleContext ctx; + + @Execute + public void execute(@OSGiBundle BundleContext ctx) { + this.ctx = ctx; + } + + public BundleContext getCtx() { + return ctx; + } + } + + @Test + public void testInjectBCinExecute() { + + final BundleContext bundleContext = CoreTestsActivator + .getDefault().getBundleContext(); + final IEclipseContext localContext = EclipseContextFactory + .getServiceContext(bundleContext); + + TestHandler handler = new TestHandler(); + ContextInjectionFactory.invoke(handler, Execute.class, localContext); + + assertNotNull(handler.getCtx()); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java new file mode 100644 index 00000000000..21e9cdd5e1d --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2013, 2015 Markus Alexander Kuppe and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Markus Alexander Kuppe - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.di.extensions.OSGiBundle; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; + +public class InjectionOSGiTest { + + // classed used as a user of the @OSGiBundle annotation + static class InjectionTarget { + + private BundleContext ctx; + + @Inject + public void setBundleContext( + @OSGiBundle @Optional BundleContext ctx) { + this.ctx = ctx; + } + + public boolean hasContext() { + return this.ctx != null; + } + + public BundleContext getContext() { + return this.ctx; + } + + private Bundle b; + + @Inject + public void setBundle( + @OSGiBundle Bundle b) { + this.b = b; + } + + public Bundle getBundle() { + return this.b; + } + + @Inject + public void setFoo(@OSGiBundle Object o) { + // make sure we don't fail when incompatible type requested + } + } + + // classed used as a user of the @OSGiBundle annotation + static class InjectionBundleTarget extends InjectionTarget { + } + + private InjectionTarget target; + private Bundle bundle; + + @After + public void tearDown() throws Exception { + bundle.start(); + + final BundleContext bundleContext = CoreTestsActivator + .getDefault().getBundleContext(); + final IEclipseContext localContext = EclipseContextFactory + .getServiceContext(bundleContext); + + ContextInjectionFactory.uninject(target, localContext); + } + + @Before + public void setUp() throws Exception { + final BundleContext bundleContext = CoreTestsActivator + .getDefault().getBundleContext(); + bundle = bundleContext.getBundle(); + + final IEclipseContext localContext = EclipseContextFactory + .getServiceContext(bundleContext); + + target = ContextInjectionFactory.make(InjectionTarget.class, + localContext); + } + + @Test + public void testInject() { + assertTrue(target.hasContext()); + } + + @Test + public void testUnInject() throws BundleException, InterruptedException { + // inject + assertTrue(target.hasContext()); + + // Check also that the BundleContext instance has indeed changed + final BundleContext firstContext = target + .getContext(); + + // uninject + bundle.stop(); + assertFalse(target.hasContext()); + + // re-inject + bundle.start(); + assertTrue(target.hasContext()); + + final BundleContext secondContext = target + .getContext(); + assertNotSame(firstContext, secondContext); + } + + @Test + public void testBundleInject() throws BundleException { + // inject + assertNotNull(target.getBundle()); + + // Contrary to the BC, the Bundle is available even for RESOLVED bundles + bundle.stop(); + + // not null but resolved _and_ still usable + assertNotNull(target.getBundle()); + assertTrue(target.getBundle().getState() == Bundle.RESOLVED); + assertNotNull(target.getBundle().getSymbolicName()); + + assertNull(target.getContext()); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java new file mode 100644 index 00000000000..6a9239143c1 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java @@ -0,0 +1,299 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import javax.inject.Inject; + +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.di.extensions.Preference; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.junit.Test; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Note: we do not support byte arrays at this time. + */ +public class InjectionPreferencesTest { + + static final private String TEST_PREFS_KEY = "testPreferencesQualifier"; + static final private String TEST_PREFS_NODE = "org.eclipse.e4.core.javax.tests.ext"; + + static final private String KEY_INT = "testPreferencesInt"; + static final private String KEY_BOOL = "testPreferencesBoolean"; + static final private String KEY_DOUBLE = "testPreferencesDouble"; + static final private String KEY_FLOAT = "testPreferencesFloat"; + static final private String KEY_LONG = "testPreferencesLong"; +// static final private String KEY_BYTE_ARRAY = "testPreferencesByteArray"; + + static class InjectTarget { + public int counter = 0; + public int counterNode = 0; + public int counterOptional = 0; + + public String pref; + public String prefNode; + public String prefOptional1; + public String prefOptional2; + + @Inject + public void setPrefs(@Preference(TEST_PREFS_KEY) String string) { + counter++; + pref = string; + } + + @Inject + public void setPrefsNode(@Preference(value=TEST_PREFS_KEY, nodePath=TEST_PREFS_NODE) String string) { + counterNode++; + prefNode = string; + } + + @Inject + public void setOptionalPrefs(@Optional @Preference("something") String string1, @Preference(TEST_PREFS_KEY) String string2) { + counterOptional++; + prefOptional1 = string1; + prefOptional2 = string2; + } + } + + static class InjectTargetPrimitive { + @Inject @Preference(KEY_INT) + public int intField; + + @Inject @Preference(KEY_BOOL) + public boolean booleanField; + + @Inject @Preference(KEY_DOUBLE) + public double doubleField; + + @Inject @Preference(KEY_FLOAT) + public float floatField; + + @Inject @Preference(KEY_LONG) + public long longField; + +// @Inject @Preference(KEY_BYTE_ARRAY) +// public byte[] byteArrayField; + + public int intArg; + public boolean booleanArg; + + @Inject + public void set(@Preference(KEY_INT) int intArg, @Preference(KEY_BOOL) boolean booleanArg) { + this.intArg = intArg; + this.booleanArg = booleanArg; + } + } + + static class InjectTargetConversion { + @Inject @Preference(KEY_INT) + public Integer intField; + + @Inject @Preference(KEY_BOOL) + public Boolean booleanField; + + @Inject @Preference(KEY_DOUBLE) + public Double doubleField; + + @Inject @Preference(KEY_FLOAT) + public Float floatField; + + @Inject @Preference(KEY_LONG) + public Long longField; + + public IEclipsePreferences preferences; + + public Integer intArg; + public Boolean booleanArg; + + @Inject + public void set(@Preference(KEY_INT) Integer intArg, @Preference(KEY_BOOL) Boolean booleanArg) { + this.intArg = intArg; + this.booleanArg = booleanArg; + } + + @Inject + public void set2(@Preference IEclipsePreferences prefNode) { + preferences = prefNode; + prefNode.put("testOutValue", "abc"); + } + } + + static class InjectTargetConstructor { + public String pref; + public String prefNode; + + @Inject + public InjectTargetConstructor(@Preference(TEST_PREFS_KEY) String string, @Preference(value=TEST_PREFS_KEY, nodePath=TEST_PREFS_NODE) String stringNode) { + pref = string; + prefNode = stringNode; + + } + } + + @Test + public void testPreferencesQualifier() throws BackingStoreException { + setPreference(TEST_PREFS_KEY, "abc"); + setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "123"); + IEclipseContext context = EclipseContextFactory.create(); + InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context); + // default node + assertEquals(1, target.counter); + assertEquals("abc", target.pref); + // specific node + assertEquals(1, target.counterNode); + assertEquals("123", target.prefNode); + // optional preference + assertEquals(1, target.counterOptional); + assertNull(target.prefOptional1); + assertEquals("abc", target.prefOptional2); + + // change + setPreference(TEST_PREFS_KEY, "xyz"); + setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "456"); + + // default node + assertEquals(2, target.counter); + assertEquals("xyz", target.pref); + // specific node + assertEquals(2, target.counterNode); + assertEquals("456", target.prefNode); + // optional preference + assertEquals(2, target.counterOptional); + assertNull(target.prefOptional1); + assertEquals("xyz", target.prefOptional2); + } + + @Test + public void testBaseTypeConversion() throws BackingStoreException { + // setup preferences + String nodePath = CoreTestsActivator.getDefault().getBundleContext().getBundle().getSymbolicName(); + IEclipsePreferences node = InstanceScope.INSTANCE.getNode(nodePath); + node.putInt(KEY_INT, 12); + node.putBoolean(KEY_BOOL, true); + node.putDouble(KEY_DOUBLE, 12.35345345345d); + node.putFloat(KEY_FLOAT, 5.13f); + node.putLong(KEY_LONG, 131232343453453L); +// node.putByteArray(KEY_BYTE_ARRAY, new byte[] { 12, 34, 45, 67}); + node.flush(); + + IEclipseContext context = EclipseContextFactory.create(); + InjectTargetPrimitive target = ContextInjectionFactory.make(InjectTargetPrimitive.class, context); + + assertEquals(12, target.intField); + assertEquals(true, target.booleanField); + assertEquals(12.35345345345d, target.doubleField, 0); + assertEquals(5.13f, target.floatField, 0); + assertEquals(131232343453453L, target.longField); +// assertNotNull(target.byteArrayField); +// assertEquals(4, target.byteArrayField.length); +// assertEquals(12, target.byteArrayField[0]); +// assertEquals(34, target.byteArrayField[1]); +// assertEquals(45, target.byteArrayField[2]); +// assertEquals(67, target.byteArrayField[3]); + + assertEquals(12, target.intArg); + assertEquals(true, target.booleanArg); + + // change + node.putInt(KEY_INT, 777); + node.putBoolean(KEY_BOOL, false); + + assertEquals(777, target.intField); + assertEquals(false, target.booleanField); + + assertEquals(777, target.intArg); + assertEquals(false, target.booleanArg); + } + + @Test + public void testAutoConversion() throws BackingStoreException { + // setup preferences + String nodePath = CoreTestsActivator.getDefault().getBundleContext().getBundle().getSymbolicName(); + IEclipsePreferences node = InstanceScope.INSTANCE.getNode(nodePath); + node.putInt(KEY_INT, 12); + node.putBoolean(KEY_BOOL, true); + node.putDouble(KEY_DOUBLE, 12.35345345345d); + node.putFloat(KEY_FLOAT, 5.13f); + node.putLong(KEY_LONG, 131232343453453L); + node.flush(); + + IEclipseContext context = EclipseContextFactory.create(); + InjectTargetConversion target = ContextInjectionFactory.make(InjectTargetConversion.class, context); + + assertEquals(Integer.valueOf(12), target.intField); + assertEquals(Boolean.TRUE, target.booleanField); + assertEquals(Double.valueOf(12.35345345345d), target.doubleField); + assertEquals(Float.valueOf(5.13f), target.floatField); + assertEquals(Long.valueOf(131232343453453L), target.longField); + + assertEquals(Integer.valueOf(12), target.intArg); + assertEquals(Boolean.TRUE, target.booleanArg); + + // change + node.putInt(KEY_INT, 777); + node.putBoolean(KEY_BOOL, false); + + assertEquals(Integer.valueOf(777), target.intField); + assertEquals(Boolean.FALSE, target.booleanField); + + assertEquals(Integer.valueOf(777), target.intArg); + assertEquals(Boolean.FALSE, target.booleanArg); + + assertNotNull(target.preferences); + assertEquals("abc", node.get("testOutValue", null)); + } + + private void setPreference(String key, String value) throws BackingStoreException { + String nodePath = CoreTestsActivator.getDefault().getBundleContext().getBundle().getSymbolicName(); + IEclipsePreferences node = InstanceScope.INSTANCE.getNode(nodePath); + node.put(key, value); + node.flush(); + } + + private void setPreference(String key, String nodePath, String value) throws BackingStoreException { + IEclipsePreferences node = InstanceScope.INSTANCE.getNode(nodePath); + node.put(key, value); + node.flush(); + } + + @Test + public void testPreferencesConstructor() throws BackingStoreException { + setPreference(TEST_PREFS_KEY, "abc"); + setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "123"); + IEclipseContext context = EclipseContextFactory.create(); + InjectTargetConstructor target = ContextInjectionFactory.make(InjectTargetConstructor.class, context); + // default node + assertEquals("abc", target.pref); + // specific node + assertEquals("123", target.prefNode); + + // change + setPreference(TEST_PREFS_KEY, "xyz"); + setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "456"); + + // values should stay the same - no tracking for constructor injection + assertEquals("abc", target.pref); + assertEquals("123", target.prefNode); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java new file mode 100644 index 00000000000..6a4cb607dab --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertEquals; + +import java.lang.reflect.InvocationTargetException; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; +import org.osgi.service.prefs.BackingStoreException; + +/** + * This test should be execute without an OSGI runtime running to verfiy BR + * 513883 + * + * @author jonas + * + */ +public class InjectionWithoutOSGITest { + + static class InjectTarget { + public String other; + + @Inject + public void setSth(@Named("testMixed") String otherString) { + other = otherString; + } + } + + @Test + public void testPreferencesQualifier() throws BackingStoreException, InvocationTargetException, InstantiationException { + IEclipseContext context = EclipseContextFactory.create(); + context.set("testMixed", "other"); + InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context); + + // test + assertEquals("other", target.other); + + // change + context.set("testMixed", "bingo"); + + // re-test + // assertEquals("xyz", target.pref); + assertEquals("bingo", target.other); + } + + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceA.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceA.java new file mode 100644 index 00000000000..390acb24a69 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceA.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import org.osgi.service.component.annotations.Component; + +@Component(property = "service.ranking:Integer=50") +public class SampleServiceA implements TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceB.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceB.java new file mode 100644 index 00000000000..68dc57ba514 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/SampleServiceB.java @@ -0,0 +1,8 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import org.osgi.service.component.annotations.Component; + +@Component(property = "service.ranking:Integer=40") +public class SampleServiceB implements TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java new file mode 100644 index 00000000000..ca6db748117 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java @@ -0,0 +1,316 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.function.BooleanSupplier; +import java.util.function.Supplier; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.di.extensions.Service; +import org.junit.After; +import org.junit.Ignore; +import org.junit.Test; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; + +public class ServiceSupplierTestCase { + public static class TestBean { + volatile TestService service; + volatile List serviceList; + volatile int serviceInjectionCount; + volatile int serviceListInjectionCount; + volatile boolean updated; + volatile boolean listUpdated; + + @Inject + public void setService(@Service TestService service) { + this.service = service; + this.serviceInjectionCount++; + updated = true; + } + + @Inject + public void setServiceList(@Service List serviceList) { + this.serviceList = serviceList; + this.serviceListInjectionCount++; + listUpdated = true; + } + } + + public static class TestStaticFilterBean { + TestService service; + List serviceList; + int serviceInjectionCount; + int serviceListInjectionCount; + + @Inject + public void setService(@Service(filterExpression="(filtervalue=Test)") TestService service) { + this.service = service; + this.serviceInjectionCount++; + } + + @Inject + public void setServiceList(@Service(filterExpression="(filtervalue=Test)") List serviceList) { + this.serviceList = serviceList; + this.serviceListInjectionCount++; + } + } + + public static class TestDisabledBean { + @Inject + @Optional + @Service(filterExpression = "(component=disabled)") + TestService disabledService; + + @Inject + @Service(filterExpression = "(component=disabled)") + List services; + } + + private final List> registrations = new ArrayList<>(); + + @After + public void cleanup() { + this.registrations.forEach( ServiceRegistration::unregister); + } + + @Test + public void testInitialInject() { + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()); + TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext); + assertNotNull(bean.service); + assertNotNull(bean.serviceList); + assertSame(SampleServiceA.class, bean.service.getClass()); + assertEquals(1, bean.serviceInjectionCount); + + assertEquals(4, bean.serviceList.size()); + assertEquals(1, bean.serviceListInjectionCount); + assertSame(SampleServiceA.class, bean.serviceList.get(0).getClass()); + assertSame(SampleServiceB.class, bean.serviceList.get(1).getClass()); + + } + + @Test + public void testStaticFilter() { + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()); + TestStaticFilterBean bean = ContextInjectionFactory.make(TestStaticFilterBean.class, serviceContext); + + assertNotNull(bean.service); + assertNotNull(bean.serviceList); + + assertSame(FilterServiceA.class, bean.service.getClass()); + assertEquals(1, bean.serviceInjectionCount); + + assertEquals(2, bean.serviceList.size()); + assertEquals(1, bean.serviceListInjectionCount); + assertSame(FilterServiceA.class, bean.serviceList.get(0).getClass()); + assertSame(FilterServiceB.class, bean.serviceList.get(1).getClass()); + } + + @Test(timeout = 30000) + public void testDynamicAdd() { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context); + TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext); + + assertEquals(1, bean.serviceInjectionCount); + assertEquals(1, bean.serviceListInjectionCount); + + TestService t = new TestService() { + // nothing todo + }; + + Hashtable properties = new Hashtable<>(); + properties.put("service.ranking", 10000); //$NON-NLS-1$ + bean.updated = false; + bean.listUpdated = false; + System.out.println("-------------------"); + this.registrations.add(context.registerService(TestService.class, t, properties)); + spinWait(() -> bean.updated && bean.listUpdated && bean.service == t); + System.out.println("-------------------"); + System.out.println("Final " + bean.service); + assertSame(t, bean.service); + assertEquals(2, bean.serviceInjectionCount); + + assertEquals(2, bean.serviceListInjectionCount); + assertEquals(5, bean.serviceList.size()); + assertSame(t, bean.serviceList.get(0)); + + TestService t2 = new TestService() { + // nothing todo + }; + + properties = new Hashtable<>(); + properties.put("service.ranking", Integer.valueOf(-1)); //$NON-NLS-1$ + bean.updated = false; + bean.listUpdated = false; + this.registrations.add(context.registerService(TestService.class, t2, properties)); + spinWait(() -> bean.updated && bean.listUpdated); + assertSame(t, bean.service); + assertEquals(3, bean.serviceInjectionCount); + + assertEquals(3, bean.serviceListInjectionCount); + + assertEquals(6, bean.serviceList.size()); + assertSame(t, bean.serviceList.get(0)); + } + + private void spinWait(BooleanSupplier condition) { + while (!condition.getAsBoolean() && !Thread.currentThread().isInterrupted()) { + Thread.onSpinWait(); + } + } + + @Test + public void testDynamicAddRemove() { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context); + TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext); + + assertEquals(1, bean.serviceInjectionCount); + assertEquals(1, bean.serviceListInjectionCount); + + TestService t = new TestService() { + // nothing todo + }; + + Hashtable properties = new Hashtable<>(); + properties.put("service.ranking", 52); //$NON-NLS-1$ + bean.updated = false; + bean.listUpdated = false; + this.registrations.add(context.registerService(TestService.class, t, properties)); + spinWait(() -> bean.updated && bean.listUpdated); + assertSame(t, bean.service); + assertEquals(2, bean.serviceInjectionCount); + + assertEquals(2, bean.serviceListInjectionCount); + assertEquals(5, bean.serviceList.size()); + assertSame(t, bean.serviceList.get(0)); + bean.updated = false; + bean.listUpdated = false; + ServiceRegistration registration = this.registrations.get(0); + registration.unregister(); + this.registrations.remove(registration); + spinWait(() -> bean.updated && bean.listUpdated); + assertEquals(3, bean.serviceInjectionCount); + assertEquals(3, bean.serviceListInjectionCount); + + assertSame(SampleServiceA.class, bean.service.getClass()); + assertEquals(4, bean.serviceList.size()); + assertSame(SampleServiceA.class, bean.serviceList.get(0).getClass()); + assertSame(SampleServiceB.class, bean.serviceList.get(1).getClass()); + } + + @Test(timeout = 30000) + public void testCleanup() { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + IEclipseContext eclipseContext = EclipseContextFactory.getServiceContext(context); + IEclipseContext iec = eclipseContext.createChild(); + TestBean bean = ContextInjectionFactory.make(TestBean.class, iec); + TestBean bean2 = ContextInjectionFactory.make(TestBean.class, eclipseContext); + iec.dispose(); + + TestService t = new TestService() { + // nothing todo + }; + + Hashtable properties = new Hashtable<>(); + properties.put("service.ranking", 2); //$NON-NLS-1$ + bean2.listUpdated = false; + this.registrations.add(context.registerService(TestService.class, t, properties)); + spinWait(() -> bean2.listUpdated); + assertSame(SampleServiceA.class, bean.service.getClass()); + } + + @Test + public void testOptionalReferences() throws Exception { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context); + TestDisabledBean bean = ContextInjectionFactory.make(TestDisabledBean.class, serviceContext); + + assertNull(bean.disabledService); + assertEquals(0, bean.services.size()); + + ServiceReference ref = context.getServiceReference(ComponentEnabler.class); + ComponentEnabler enabler = context.getService(ref); + final int timeoutInMillis = 1000; + try { + enabler.enableDisabledServiceA(); + // wait for asynchronous service registry and injection to finish + waitForCondition(() -> bean.services.size() == 1, timeoutInMillis); + assertNotNull(bean.disabledService); + assertEquals(1, bean.services.size()); + assertSame(DisabledServiceA.class, bean.disabledService.getClass()); + + enabler.enableDisabledServiceB(); + // wait for asynchronous service registry and injection to finish + waitForCondition(() -> bean.services.size() == 2, timeoutInMillis); + assertNotNull(bean.disabledService); + assertEquals(2, bean.services.size()); + assertSame(DisabledServiceB.class, bean.disabledService.getClass()); + + enabler.disableDisabledServiceB(); + // wait for asynchronous service registry and injection to finish + waitForCondition(() -> bean.services.size() == 1, timeoutInMillis); + assertNotNull(bean.disabledService); + assertEquals(1, bean.services.size()); + assertSame(DisabledServiceA.class, bean.disabledService.getClass()); + + enabler.disableDisabledServiceA(); + // wait for asynchronous service registry and injection to finish + waitForCondition(() -> bean.services.size() == 0, timeoutInMillis); + assertNull(bean.disabledService); + assertEquals(0, bean.services.size()); + } finally { + enabler.disableDisabledServiceA(); + enabler.disableDisabledServiceB(); + // wait for asynchronous service registry and injection to ensure + // clear state after this test + waitForCondition(() -> bean.services.size() == 0, timeoutInMillis); + } + } + + private void waitForCondition(Supplier condition, int timeoutInMillis) throws Exception { + long startTimeInMillis = System.currentTimeMillis(); + while (!condition.get() && System.currentTimeMillis() - startTimeInMillis < timeoutInMillis) { + Thread.sleep(20); + } + } + + @Test + @Ignore("See Bug 572546") + public void testUselessUpdates() throws InterruptedException { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context); + TestBean bean = ContextInjectionFactory.make(TestBean.class, serviceContext); + assertEquals(1, bean.serviceInjectionCount); + assertEquals(1, bean.serviceListInjectionCount); + TestService current = bean.service; + TestService t = new TestService() { + // nothing todo + }; + + Hashtable properties = new Hashtable<>(); + properties.put("service.ranking", -1); //$NON-NLS-1$ + bean.updated = false; + bean.listUpdated = false; + this.registrations.add(context.registerService(TestService.class, t, properties)); + spinWait(() -> bean.listUpdated); + Thread.sleep(100); + assertEquals(current, bean.service); + assertEquals(1, bean.serviceInjectionCount); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/TestService.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/TestService.java new file mode 100644 index 00000000000..bdcdcecb96d --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/TestService.java @@ -0,0 +1,5 @@ +package org.eclipse.e4.core.internal.tests.di.extensions; + +public interface TestService { + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java new file mode 100644 index 00000000000..cfbaf57355b --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.manual; + +import static org.junit.Assert.assertTrue; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.junit.Test; + + +/** + * This is a demo of a scenario when computed values don't work. The basic idea here is that a + * calculated value depends on something not stored in the context, it won't necessarily be updated. + * + * CalculatedValue = Function(ContextElement1, ..., ContextElement1N, ExtnernalFactor) + * + * In this scenario we deal with the Output = Function(arg1, ..., arg10, Time) + * + * We use a system timer here as an external input, but it can be pretty much anything not stored + * directly in the context. + */ +public class ComputedValueLimitationTest { + + + /** + * Used as an injection target + */ + public static class UserObject { + + private String txt; + + @Inject + public void Computed(String txt) { + this.txt = txt; + } + + public String getComputed() { + return txt; + } + } + + static public class ExtenralFactor { + static public int useChild() { + long time = System.currentTimeMillis(); + return ((int) time % 10); // this is incorrect but works for the example + } + } + + public static class CalcColor extends ContextFunction { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + int useArg = ExtenralFactor.useChild(); + return context.get("arg" + useArg); + } + } + + public static class Time extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + context.get(String.valueOf(System.currentTimeMillis())); + return Long.valueOf(System.currentTimeMillis()); + } + } + + @Test + public synchronized void testInjection() { + + IEclipseContext context = EclipseContextFactory.create(); + for (int i = 0; i < 10; i++) { + context.set("arg" + i, Integer.toString(i)); + } + context.set("computed", new CalcColor()); + + UserObject userObject = new UserObject(); + ContextInjectionFactory.inject(userObject, context); + + for (int i = 0; i < 20; i++) { + int before = ExtenralFactor.useChild(); + String actual = userObject.getComputed(); + int after = ExtenralFactor.useChild(); + System.out.println("[" + before + "] actual: " + actual + " [" + after + "]"); + try { + wait(1); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + @Test + public void testVolatileFunction() { + IEclipseContext context = EclipseContextFactory.create(); + context.set("time", new Time()); + long time = ((Long) context.get("time")).longValue(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // + } + long newTime = ((Long) context.get("time")).longValue(); + assertTrue(time != newTime); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java new file mode 100644 index 00000000000..5e1b4618c94 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2009, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.manual; + +import java.text.NumberFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.contexts.RunAndTrack; +import org.eclipse.e4.core.internal.tests.CoreTestsActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +/** + * + */ +public class ContextExample { + static class Crayon { + @Inject + IPaletteService pallete; + + public void draw() { + if (pallete == null) + System.out.println("No palette"); + else + System.out.println("My pen is: " + pallete.getColor()); + } + } + + static enum Color { + RED, BLUE, YELLOW, GREEN, ORANGE, PURPLE; + } + + interface IPaletteService { + public Color getColor(); + } + + static class PaletteImpl implements IPaletteService { + private final Color color; + + PaletteImpl(Color color) { + this.color = color; + } + + @Override + public Color getColor() { + return color; + } + } + + static class ComplementaryColor extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + switch ((Color) context.get("color")) { + case RED: + return Color.GREEN; + case GREEN: + return Color.RED; + case BLUE: + return Color.ORANGE; + case ORANGE: + return Color.BLUE; + case YELLOW: + return Color.PURPLE; + case PURPLE: + return Color.YELLOW; + default: + return null; + } + } + } + + static class ResourceSelection extends ContextFunction { + @Override + public Object compute(IEclipseContext context, String contextKey) { + return null; + } + } + + public static void main(String[] arguments) { + new ContextExample().price(); + } + + /** + * + */ + public void run() { + IEclipseContext parent = EclipseContextFactory.create(); + parent.set("complement", new ComplementaryColor()); + IEclipseContext context = parent.createChild(); + context.set("color", Color.YELLOW); + Crayon crayon = new Crayon(); + ContextInjectionFactory.inject(crayon, context); + crayon.draw(); + } + + public void runWithService() { + BundleContext bundleContext = CoreTestsActivator.getDefault().getBundleContext(); + ServiceRegistration reg = bundleContext.registerService(IPaletteService.class + .getName(), new PaletteImpl(Color.BLUE), null); + IEclipseContext context = EclipseContextFactory.getServiceContext(bundleContext); + Crayon crayon = new Crayon(); + ContextInjectionFactory.inject(crayon, context); + crayon.draw(); + reg.unregister(); + crayon.draw(); + } + + public void run2() { + IEclipseContext parent = EclipseContextFactory.create(); + parent.set("complement", new ComplementaryColor()); + IEclipseContext child = parent.createChild(); + child.set("color", Color.RED); + System.out.println(child.get("color")); + System.out.println(child.get("complement")); + + } + + public void run3() { + // IEclipseContext context = EclipseContextFactory.create(); + // Object[] args = new Object[] {IResource.class}; + // IResource[] resources = context.get("Selection", args); + } + + double total = 0; + + public void price() { + final IEclipseContext context = EclipseContextFactory.create(); + context.set("price", 19.99); + context.set("tax", 0.05); + context.runAndTrack(new RunAndTrack() { + @Override + public boolean changed(IEclipseContext context) { + total = (Double) context.get("price") * (1.0 + (Double) context.get("tax")); + return true; + } + + @Override + public String toString() { + return "calculator"; + } + }); + print(total); + context.set("tax", 0.07); + print(total); + } + + private void print(double price) { + System.out.println(NumberFormat.getCurrencyInstance().format(price)); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java new file mode 100644 index 00000000000..599d551812b --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java @@ -0,0 +1,220 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + *******************************************************************************/ +package org.eclipse.e4.core.internal.tests.manual; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.InjectionException; +import org.eclipse.e4.core.di.annotations.Creatable; +import org.junit.Test; + +/** + * Manual test to observe error reporting. The JUnits in this + * test are expected to produce exceptions in the output stream. + */ +public class InjectionErrorReportingTest { + static class TestData { + } + + static class InjectedMethod { + public int setMethodCalled = 0; + public TestData value; + + @Inject + public void injectedMethod(@Named("testing123") TestData arg) { + setMethodCalled++; + value = arg; + } + } + + static class InjectedMethodNull { + public int setMethodCalled = 0; + public String nullString = null; + + @Inject + public int injectedMethod(@Named("testing") TestData arg) { + setMethodCalled++; + return nullString.length(); + } + } + + static class InjectedConstructor { + public int setMethodCalled = 0; + public TestData value; + + @Inject + public InjectedConstructor(@Named("testing123") TestData arg) { + setMethodCalled++; + value = arg; + } + } + + static class InjectedConstructorCast { + public int setMethodCalled = 0; + public TestData value; + public String nullString = "abc"; + + @Inject + public InjectedConstructorCast(@Named("testing") TestData arg) { + setMethodCalled++; + value = arg; + Object otherObject = new TestData(); + nullString = (String) otherObject; + } + } + + static class InjectedField { + @Inject @Named("testing123") + public TestData data; + } + + static class InjectedPostConstruct { + public int setMethodCalled = 0; + public String nullString = null; + public int length; + + @PostConstruct + public void myMethod() { + setMethodCalled++; + length = nullString.length(); + } + } + + static class InjectedPreDestroy { + public int setMethodCalled = 0; + public String nullString = null; + public int length; + + @Inject + public void injectedMethod(@Named("testing") TestData arg) { + setMethodCalled++; + } + + @PreDestroy + public void myMethod() { + setMethodCalled++; + length = nullString.length(); + } + } + + @Creatable + static class InjectedRecursive { + @Inject + public InjectedRecursive field; + } + + /** + * Shows the error message for an unresolved method argument + */ + @Test(expected = InjectionException.class) + public void testMethodInjectionError() { + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing", methodValue); + InjectedMethod object = new InjectedMethod(); + ContextInjectionFactory.inject(object, context); + } + + /** + * Shows the error message in case method call throws an exception + */ + @Test(expected = InjectionException.class) + public void testMethodInjectionNullError() { + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing", methodValue); + InjectedMethodNull object = new InjectedMethodNull(); + ContextInjectionFactory.inject(object, context); + } + + /** + * Shows the error message for an unresolved constructor argument + */ + @Test(expected = InjectionException.class) + public void testConstructorInjectionError() { + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing", methodValue); + ContextInjectionFactory.make(InjectedConstructor.class, context); + + } + + /** + * Shows the error message for an exception in the injected constructor + */ + @Test(expected = InjectionException.class) + public void testConstructorCastError() { + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing", methodValue); + ContextInjectionFactory.make(InjectedConstructorCast.class, context); + } + + /** + * Shows the error message for an unresolved field value + */ + @Test(expected = InjectionException.class) + public void testFieldInjectionError() { + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing", methodValue); + InjectedField object = new InjectedField(); + ContextInjectionFactory.inject(object, context); + } + + /** + * Shows the error message in case @PostConstruct method call throws an exception + */ + @Test(expected = InjectionException.class) + public void testPostConstructError() { + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing", methodValue); + ContextInjectionFactory.make(InjectedPostConstruct.class, context); + } + + /** + * Shows the error message in case @PreDestory method call throws an exception + */ + @Test(expected = InjectionException.class) + public void testPreDestoryError() { + IEclipseContext context = EclipseContextFactory.create(); + TestData methodValue = new TestData(); + context.set("testing", methodValue); + ContextInjectionFactory.make(InjectedPreDestroy.class, context); + context.dispose(); + } + + /** + * Manual test to check error message for recursive object creation Although + * bug 377343 disabled throwing InjectionExceptions on recursive creation, + * the fix for bug 457687 now exposes java.lang.Errors (such as + * StackOverflowError) rather than wrapping them in an InjectionException. + */ + @Test(expected = StackOverflowError.class) + public void testRecursionError() { + IEclipseContext context = EclipseContextFactory.create(); + ContextInjectionFactory.make(InjectedRecursive.class, context); + + context.set(InjectedRecursive.class, new InjectedRecursive()); + ContextInjectionFactory.make(InjectedRecursive.class, context); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java new file mode 100644 index 00000000000..1b486932a38 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java @@ -0,0 +1,45 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import java.text.MessageFormat; + +import javax.annotation.PostConstruct; + +/** + * Load messages from the OSGi resource bundle (OSGI-INF/l10n/bundle.properties) + */ +public class BundleMessages { + + //message as is + public String message; + + //message as is with underscore + public String message_one; + + //message as is camel cased + public String messageOne; + + //message with underscore transformed to . separated properties key + public String message_two; + + //camel cased message transformed to . separated properties key + public String messageThree; + + //message with placeholder + public String messageFour; + + // messages with camel case and underscore + public String messageFive_Sub; + public String messageSix_Sub; + public String messageSeven_Sub; + public String messageEight_Sub; + public String messageNine_Sub; + + @PostConstruct + public void format() { + messageFour = MessageFormat.format(messageFour, "Tom"); //$NON-NLS-1$ + } + + public String getMessage() { + return message; + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java new file mode 100644 index 00000000000..d21c6138257 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java @@ -0,0 +1,18 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Creatable; +import org.eclipse.e4.core.services.nls.BaseMessageRegistry; +import org.eclipse.e4.core.services.nls.Translation; + +@Creatable +public class BundleMessagesRegistry extends BaseMessageRegistry { + + @Override + @Inject + public void updateMessages(@Translation BundleMessages messages) { + super.updateMessages(messages); + } + +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/LocaleTransformationTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/LocaleTransformationTest.java new file mode 100644 index 00000000000..130c5ce3867 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/LocaleTransformationTest.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Dirk Fauth and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Dirk Fauth - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ +package org.eclipse.e4.core.internal.tests.nls; + +import static org.junit.Assert.assertEquals; + +import java.util.Locale; + +import org.eclipse.e4.core.internal.services.ResourceBundleHelper; +import org.junit.Test; + +@SuppressWarnings("restriction") +public class LocaleTransformationTest { + + @Test + public void testValidLanguageCountryVariant() { + String localeString = "de_DE_EURO"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("de", locale.getLanguage()); + assertEquals("DE", locale.getCountry()); + assertEquals("EURO", locale.getVariant()); + } + + @Test + public void testValidLanguageCountry() { + String localeString = "de_DE"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("de", locale.getLanguage()); + assertEquals("DE", locale.getCountry()); + assertEquals("", locale.getVariant()); + } + + @Test + public void testValidLanguage() { + String localeString = "de"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("de", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("", locale.getVariant()); + } + + @Test + public void testValidCountry() { + String localeString = "_DE"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("", locale.getLanguage()); + assertEquals("DE", locale.getCountry()); + assertEquals("", locale.getVariant()); + } + + @Test + public void testValidLanguageVariant() { + String localeString = "de__EURO"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("de", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("EURO", locale.getVariant()); + } + + @Test + public void testValidVariant() { + String localeString = "__EURO"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("EURO", locale.getVariant()); + } + + @Test + public void testValidCountryVariant() { + String localeString = "_DE_EURO"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("", locale.getLanguage()); + assertEquals("DE", locale.getCountry()); + assertEquals("EURO", locale.getVariant()); + } + + @Test + public void testInvalidLanguage() { + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + + String localeString = "1234"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("en", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("", locale.getVariant()); + + Locale.setDefault(defaultLocale); + } + + @Test + public void testInvalidOneLetterLanguage() { + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + + String localeString = "a"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("en", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("", locale.getVariant()); + + Locale.setDefault(defaultLocale); + } + + @Test + public void testThreeLetterValidLanguage() { + String localeString = "kok"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("kok", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("", locale.getVariant()); + } + + @Test + public void testInvalidOneLetterCountry() { + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + + String localeString = "_X"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("en", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("", locale.getVariant()); + + Locale.setDefault(defaultLocale); + } + + @Test + public void testInvalidThreeLetterCountry() { + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + + String localeString = "_XXX"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("en", locale.getLanguage()); + assertEquals("", locale.getCountry()); + assertEquals("", locale.getVariant()); + + Locale.setDefault(defaultLocale); + } + + @Test + public void testValidNumericAreaCode() { + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + + String localeString = "_029"; + Locale locale = ResourceBundleHelper.toLocale(localeString); + assertEquals("", locale.getLanguage()); + assertEquals("029", locale.getCountry()); + assertEquals("", locale.getVariant()); + + Locale.setDefault(defaultLocale); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java new file mode 100644 index 00000000000..9baf2ac75d4 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * Copyright (c) 2014, 2020 Dirk Fauth and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Dirk Fauth - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.nls; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Locale; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.translation.TranslationService; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.FrameworkUtil; + +public class MessageRegistryTest { + + static class TestObject { + @Inject + BundleMessagesRegistry registry; + } + + static class TestLocalizableObject { + private String localizableValue; + + public String getLocalizableValue() { + return localizableValue; + } + + public void setLocalizableValue(String localizableValue) { + this.localizableValue = localizableValue; + } + } + + private IEclipseContext context; + + @Before + public void setUp() { + this.context = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()); + ContextInjectionFactory.setDefault(context); + } + + @Test + public void testRegisterLocalizationByProperty() { + // ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestObject o = ContextInjectionFactory.make(TestObject.class, this.context); + + TestLocalizableObject control = new TestLocalizableObject(); + o.registry.registerProperty(control, "localizableValue", "message"); + + // test value is set + assertNotNull(control.getLocalizableValue()); + + // test the set value + assertEquals("BundleMessage", control.getLocalizableValue()); + } + + @Test + public void testRegisterLocalizationByMethod() { + // ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestObject o = ContextInjectionFactory.make(TestObject.class, this.context); + + TestLocalizableObject control = new TestLocalizableObject(); + o.registry.register(control, "setLocalizableValue", "message"); + + // test value is set + assertNotNull(control.getLocalizableValue()); + + // test the set value + assertEquals("BundleMessage", control.getLocalizableValue()); + } + + @Test + public void testRegisterLocalizationByMethodReference() { + // ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestObject o = ContextInjectionFactory.make(TestObject.class, this.context); + + TestLocalizableObject control = new TestLocalizableObject(); + o.registry.register(control::setLocalizableValue, (m) -> m.message); + + // test value is set + assertNotNull(control.getLocalizableValue()); + + // test the set value + assertEquals("BundleMessage", control.getLocalizableValue()); + } + + @Test + public void testRegisterLocalizationByPropertyAndChangeLocale() { + // ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestObject o = ContextInjectionFactory.make(TestObject.class, this.context); + + TestLocalizableObject control = new TestLocalizableObject(); + o.registry.registerProperty(control, "localizableValue", "message"); + + // test value is set + assertNotNull(control.getLocalizableValue()); + + // test the set value + assertEquals("BundleMessage", control.getLocalizableValue()); + + // change the locale to GERMAN + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + + assertEquals("BundleNachricht", control.getLocalizableValue()); + } + + @Test + public void testRegisterLocalizationByMethodAndChangeLocale() { + // ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestObject o = ContextInjectionFactory.make(TestObject.class, this.context); + + TestLocalizableObject control = new TestLocalizableObject(); + o.registry.register(control, "setLocalizableValue", "message"); + + // test value is set + assertNotNull(control.getLocalizableValue()); + + // test the set value + assertEquals("BundleMessage", control.getLocalizableValue()); + + // change the locale to GERMAN + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + + assertEquals("BundleNachricht", control.getLocalizableValue()); + } + + @Test + public void testRegisterLocalizationByMethodReferenceAndChangeLocale() { + // ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestObject o = ContextInjectionFactory.make(TestObject.class, this.context); + + TestLocalizableObject control = new TestLocalizableObject(); + o.registry.register(control::setLocalizableValue, BundleMessages::getMessage); + + // test value is set + assertNotNull(control.getLocalizableValue()); + + // test the set value + assertEquals("BundleMessage", control.getLocalizableValue()); + + // change the locale to GERMAN + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + + assertEquals("BundleNachricht", control.getLocalizableValue()); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java new file mode 100644 index 00000000000..037b354098a --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java @@ -0,0 +1,42 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import java.text.MessageFormat; + +import javax.annotation.PostConstruct; + +/** + * Load messages from a relative positioned resource bundle (./messages.properties) + * Used to verify the case sensitive filename handling under Linux + */ +public class Messages { + + //message as is + public String message; + + //message as is with underscore + public String message_one; + + //message as is camel cased + public String messageOne; + + //message with underscore transformed to . separated properties key + public String message_two; + + //camel cased message transformed to . separated properties key + public String messageThree; + + //message with placeholder + public String messageFour; + + // message with camel case and underscore + public String messageFive_Sub; + public String messageSix_Sub; + public String messageSeven_Sub; + public String messageEight_Sub; + public String messageNine_Sub; + + @PostConstruct + public void format() { + messageFour = MessageFormat.format(messageFour, "Tom"); //$NON-NLS-1$ + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java new file mode 100644 index 00000000000..440571d0fb9 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java @@ -0,0 +1,948 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Dirk Fauth and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Dirk Fauth - initial API and implementation + * Lars Vogel - Bug 474274 + ******************************************************************************/ + +package org.eclipse.e4.core.internal.tests.nls; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Locale; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.EclipseContextFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.core.services.translation.TranslationService; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.FrameworkUtil; + +public class NLSTest { + + static class TestSimpleObject { + @Inject + @Translation + SimpleMessages simpleMessages; + } + + static class TestMessagesObject { + @Inject + @Translation + Messages Messages; + } + + static class TestBundleObject { + @Inject + @Translation + BundleMessages bundleMessages; + } + + static class TestResourceBundleClassObject { + @Inject + @Translation + ResourceBundleClassMessages bundleClassMessages; + } + + static class TestResourcesBundleObject { + @Inject + @Translation + ResourcesMessages resourcesMessages; + } + + private IEclipseContext context; + private Locale beforeLocale; + + @Before + public void setUp() { + this.context = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()); + ContextInjectionFactory.setDefault(context); + + beforeLocale = Locale.getDefault(); + //always set the locale to en prior a test case + Locale.setDefault(new Locale("en")); + } + + @After + public void tearDown() { + Locale.setDefault(beforeLocale); + } + + @Test + public void testSimpleMessages() { + //ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context); + + SimpleMessages messages = o.simpleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("SimpleMessage", messages.message); + assertEquals("SimpleMessageUnderscore", messages.message_one); + assertEquals("SimpleMessageCamelCase", messages.messageOne); + assertEquals("SimpleMessageUnderscoreDot", messages.message_two); + assertEquals("SimpleMessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("SimpleMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", messages.messageSeven_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", messages.messageNine_Sub); + } + + @Test + public void testSimpleMessagesDifferentLocale() { + //set Locale to de + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context); + + SimpleMessages messages = o.simpleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("SimpleNachricht", messages.message); + assertEquals("SimpleNachrichtUnderscore", messages.message_one); + assertEquals("SimpleNachrichtCamelCase", messages.messageOne); + assertEquals("SimpleNachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("SimpleMessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testSimpleMessagesSkipDefaultLocaleForEquinoxRoot() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set the locale to en + //as there is no _en properties file, by default the _de properties file would be loaded and we would + //get german translations as the default locale is set to "de_DE" + //with checking the equinox.root.locale in the system properties the fallback is skipped as it tells + //that the root properties file is for locale en. + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context); + + SimpleMessages messages = o.simpleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //not the default resource bundle should be used (e.g. de when running on a machine with german OS) + //but the default resource bundle + assertEquals("SimpleMessage", messages.message); + assertEquals("SimpleMessageUnderscore", messages.message_one); + assertEquals("SimpleMessageCamelCase", messages.messageOne); + assertEquals("SimpleMessageUnderscoreDot", messages.message_two); + assertEquals("SimpleMessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("SimpleMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", messages.messageSeven_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("SimpleMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", messages.messageNine_Sub); + } + + @Test + public void testSimpleMessagesUseDefaultLocaleForInvalidLocale() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set a locale for which no resource bundle is set + this.context.set(TranslationService.LOCALE, Locale.FRENCH); + TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context); + + SimpleMessages messages = o.simpleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //the default resource bundle should be used + assertEquals("SimpleNachricht", messages.message); + assertEquals("SimpleNachrichtUnderscore", messages.message_one); + assertEquals("SimpleNachrichtCamelCase", messages.messageOne); + assertEquals("SimpleNachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("SimpleMessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("SimpleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testMessages() { + //ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context); + + Messages messages = o.Messages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("Message", messages.message); + assertEquals("MessageUnderscore", messages.message_one); + assertEquals("MessageCamelCase", messages.messageOne); + assertEquals("MessageUnderscoreDot", messages.message_two); + assertEquals("MessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("MessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", messages.messageSeven_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", messages.messageNine_Sub); + } + + @Test + public void testMessagesDifferentLocale() { + //set Locale to de + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context); + + Messages messages = o.Messages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("Nachricht", messages.message); + assertEquals("NachrichtUnderscore", messages.message_one); + assertEquals("NachrichtCamelCase", messages.messageOne); + assertEquals("NachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("MessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("NachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testMessagesSkipDefaultLocaleForEquinoxRoot() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set the locale to en + //as there is no _en properties file, by default the _de properties file would be loaded and we would + //get german translations as the default locale is set to "de_DE" + //with checking the equinox.root.locale in the system properties the fallback is skipped as it tells + //that the root properties file is for locale en. + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context); + + Messages messages = o.Messages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //not the default resource bundle should be used (e.g. de when running on a machine with german OS) + //but the default resource bundle + assertEquals("Message", messages.message); + assertEquals("MessageUnderscore", messages.message_one); + assertEquals("MessageCamelCase", messages.messageOne); + assertEquals("MessageUnderscoreDot", messages.message_two); + assertEquals("MessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("MessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", messages.messageSeven_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("MessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", messages.messageNine_Sub); + } + + @Test + public void testSimpleMessagesRegionCode() { + // set Locale to "de_CH" + + Locale locale = new Locale("de", "CH"); + this.context.set(TranslationService.LOCALE, locale); + TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context); + + SimpleMessages messages = o.simpleMessages; + + // test if relevant values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.messageOne); + + // test the set relevant values + assertEquals("Region", messages.message); + assertEquals("RegionOne", messages.messageOne); + } + + @Test + public void testSimpleMessagesRegionAndVariantCode() { + // set Locale to "de_CH_TEST" + + Locale locale = new Locale("de", "CH", "TEST"); + this.context.set(TranslationService.LOCALE, locale); + TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context); + + SimpleMessages messages = o.simpleMessages; + + // test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.messageOne); + + // test the set values + assertEquals("RegionWithTestVariant", messages.message); + assertEquals("RegionWithTestVariantOne", messages.messageOne); + + locale = new Locale("de", "CH", "OTHER"); + this.context.set(TranslationService.LOCALE, locale); + TestSimpleObject otherO = ContextInjectionFactory.make(TestSimpleObject.class, this.context); + + SimpleMessages otherMessages = otherO.simpleMessages; + + // test the set values + assertEquals("RegionWithOtherVariant", otherMessages.message); + assertEquals("RegionWithOtherVariantOne", otherMessages.messageOne); + } + + @Test + public void testMessagesUseDefaultLocaleForInvalidLocale() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set a locale for which no resource bundle is set + this.context.set(TranslationService.LOCALE, Locale.FRENCH); + TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context); + + Messages messages = o.Messages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //the default resource bundle should be used + assertEquals("Nachricht", messages.message); + assertEquals("NachrichtUnderscore", messages.message_one); + assertEquals("NachrichtCamelCase", messages.messageOne); + assertEquals("NachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("MessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("NachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("NachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testBundleMessages() { + //ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context); + + BundleMessages messages = o.bundleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("BundleMessage", messages.message); + assertEquals("BundleMessageUnderscore", messages.message_one); + assertEquals("BundleMessageCamelCase", messages.messageOne); + assertEquals("BundleMessageUnderscoreDot", messages.message_two); + assertEquals("BundleMessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("BundleMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", messages.messageSeven_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", messages.messageNine_Sub); + } + + @Test + public void testBundleMessagesDifferentLocale() { + //set Locale to de + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context); + + BundleMessages messages = o.bundleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("BundleNachricht", messages.message); + assertEquals("BundleNachrichtUnderscore", messages.message_one); + assertEquals("BundleNachrichtCamelCase", messages.messageOne); + assertEquals("BundleNachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("BundleMessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testBundleMessagesSkipDefaultLocaleForEquinoxRoot() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set the locale to en + //as there is no _en properties file, by default the _de properties file would be loaded and we would + //get german translations as the default locale is set to "de_DE" + //with checking the equinox.root.locale in the system properties the fallback is skipped as it tells + //that the root properties file is for locale en. + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context); + + BundleMessages messages = o.bundleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //not the default resource bundle should be used (e.g. de when running on a machine with german OS) + //but the default resource bundle + assertEquals("BundleMessage", messages.message); + assertEquals("BundleMessageUnderscore", messages.message_one); + assertEquals("BundleMessageCamelCase", messages.messageOne); + assertEquals("BundleMessageUnderscoreDot", messages.message_two); + assertEquals("BundleMessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("BundleMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", messages.messageSeven_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("BundleMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", messages.messageNine_Sub); + } + + @Test + public void testBundleMessagesUseDefaultLocaleForInvalidLocale() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set a locale for which no resource bundle is set + this.context.set(TranslationService.LOCALE, Locale.FRENCH); + TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context); + + BundleMessages messages = o.bundleMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //the default resource bundle should be used + assertEquals("BundleNachricht", messages.message); + assertEquals("BundleNachrichtUnderscore", messages.message_one); + assertEquals("BundleNachrichtCamelCase", messages.messageOne); + assertEquals("BundleNachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("BundleMessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("BundleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testClassBasedResourceBundle() { + //ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context); + + ResourceBundleClassMessages messages = o.bundleClassMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("ResourceBundleClassMessage", messages.message); + assertEquals("ResourceBundleClassMessageUnderscore", messages.message_one); + assertEquals("ResourceBundleClassMessageCamelCase", messages.messageOne); + assertEquals("ResourceBundleClassMessageUnderscoreDot", messages.message_two); + assertEquals("ResourceBundleClassCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testClassBasedResourceBundleDifferentLocale() { + //set Locale to de + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context); + + ResourceBundleClassMessages messages = o.bundleClassMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("ResourceBundleClassNachricht", messages.message); + assertEquals("ResourceBundleClassNachrichtUnderscore", messages.message_one); + assertEquals("ResourceBundleClassNachrichtCamelCase", messages.messageOne); + assertEquals("ResourceBundleNachrichtMessageUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("ResourceBundleClassCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testClassBasedResourceBundleSkipDefaultLocaleForEquinoxRoot() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set the locale to en + //as there is no _en properties file, by default the _de properties file would be loaded and we would + //get german translations as the default locale is set to "de_DE" + //with checking the equinox.root.locale in the system properties the fallback is skipped as it tells + //that the root properties file is for locale en. + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context); + + ResourceBundleClassMessages messages = o.bundleClassMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //not the default resource bundle should be used (e.g. de when running on a machine with german OS) + //but the default resource bundle + assertEquals("ResourceBundleClassMessage", messages.message); + assertEquals("ResourceBundleClassMessageUnderscore", messages.message_one); + assertEquals("ResourceBundleClassMessageCamelCase", messages.messageOne); + assertEquals("ResourceBundleClassMessageUnderscoreDot", messages.message_two); + assertEquals("ResourceBundleClassCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourceBundleClassMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testClassBasedResourceBundleUseDefaultLocaleForInvalidLocale() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set a locale for which no resource bundle is set + this.context.set(TranslationService.LOCALE, Locale.FRENCH); + TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context); + + ResourceBundleClassMessages messages = o.bundleClassMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //the default resource bundle should be used + assertEquals("ResourceBundleClassNachricht", messages.message); + assertEquals("ResourceBundleClassNachrichtUnderscore", messages.message_one); + assertEquals("ResourceBundleClassNachrichtCamelCase", messages.messageOne); + assertEquals("ResourceBundleNachrichtMessageUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("ResourceBundleClassCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testResourcesBundle() { + //ensure the en Locale is set for this test + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context); + + ResourcesMessages messages = o.resourcesMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("ResourcesMessage", messages.message); + assertEquals("ResourcesMessageUnderscore", messages.message_one); + assertEquals("ResourcesMessageCamelCase", messages.messageOne); + assertEquals("ResourcesMessageUnderscoreDot", messages.message_two); + assertEquals("ResourcesMessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testResourcesBundleDifferentLocale() { + //set Locale to de + this.context.set(TranslationService.LOCALE, Locale.GERMAN); + TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context); + + ResourcesMessages messages = o.resourcesMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //test the set values + assertEquals("ResourcesNachricht", messages.message); + assertEquals("ResourcesNachrichtUnderscore", messages.message_one); + assertEquals("ResourcesNachrichtCamelCase", messages.messageOne); + assertEquals("ResourcesNachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("ResourcesMessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testResourcesBundleSkipDefaultLocaleForEquinoxRoot() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set the locale to en + //as there is no _en properties file, by default the _de properties file would be loaded and we would + //get german translations as the default locale is set to "de_DE" + //with checking the equinox.root.locale in the system properties the fallback is skipped as it tells + //that the root properties file is for locale en. + this.context.set(TranslationService.LOCALE, Locale.ENGLISH); + TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context); + + ResourcesMessages messages = o.resourcesMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //not the default resource bundle should be used (e.g. de when running on a machine with german OS) + //but the default resource bundle + assertEquals("ResourcesMessage", messages.message); + assertEquals("ResourcesMessageUnderscore", messages.message_one); + assertEquals("ResourcesMessageCamelCase", messages.messageOne); + assertEquals("ResourcesMessageUnderscoreDot", messages.message_two); + assertEquals("ResourcesMessageCamelCaseDot", messages.messageThree); + assertEquals("The idea is from Tom", messages.messageFour); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourcesMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + + @Test + public void testResourcesBundleUseDefaultLocaleForInvalidLocale() { + //change the default Locale for this testcase + Locale.setDefault(new Locale("de")); + + //set a locale for which no resource bundle is set + this.context.set(TranslationService.LOCALE, Locale.FRENCH); + TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context); + + ResourcesMessages messages = o.resourcesMessages; + + //test all values are set + assertNotNull(messages); + assertNotNull(messages.message); + assertNotNull(messages.message_one); + assertNotNull(messages.messageOne); + assertNotNull(messages.message_two); + assertNotNull(messages.messageThree); + assertNotNull(messages.messageFour); + assertNotNull(messages.messageFive_Sub); + assertNotNull(messages.messageSix_Sub); + assertNotNull(messages.messageSeven_Sub); + assertNotNull(messages.messageEight_Sub); + assertNotNull(messages.messageNine_Sub); + + //the default resource bundle should be used + assertEquals("ResourcesNachricht", messages.message); + assertEquals("ResourcesNachrichtUnderscore", messages.message_one); + assertEquals("ResourcesNachrichtCamelCase", messages.messageOne); + assertEquals("ResourcesNachrichtUnderscoreDot", messages.message_two); + //for messageThree there is no key specified in de properties file, so there should be the fallback + assertEquals("ResourcesMessageCamelCaseDot", messages.messageThree); + assertEquals("Die Idee ist von Tom", messages.messageFour); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreOriginal", messages.messageFive_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasified", messages.messageSix_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified", + messages.messageSeven_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorified", messages.messageEight_Sub); + assertEquals("ResourcesNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified", + messages.messageNine_Sub); + } + +} \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass.java new file mode 100644 index 00000000000..77dc951362a --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass.java @@ -0,0 +1,24 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import java.util.ListResourceBundle; + +public class ResourceBundleClass extends ListResourceBundle { + @Override + protected Object[][] getContents() { + return new Object[][] { + new Object[] { "message", "ResourceBundleClassMessage" }, + new Object[] { "message_one", "ResourceBundleClassMessageUnderscore" }, + new Object[] { "messageOne", "ResourceBundleClassMessageCamelCase" }, + new Object[] { "message_two", "ResourceBundleClassMessageUnderscoreDot" }, + new Object[] { "messageThree", "ResourceBundleClassCamelCaseDot" }, + new Object[] { "messageFour", "The idea is from {0}" }, + new Object[] { "messageFive_Sub", "ResourceBundleClassMessageCamelCaseAndUnderscoreOriginal" }, + new Object[] { "message_six__sub", "ResourceBundleClassMessageCamelCaseAndUnderscoreDeCamelCasified" }, + new Object[] { "message.seven..sub", + "ResourceBundleClassMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified" }, + new Object[] { "messageEight.Sub", "ResourceBundleClassMessageCamelCaseAndUnderscoreDeUnderscorified" }, + new Object[] { "message_nine._sub", + "ResourceBundleClassMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified" } + }; + } +} \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java new file mode 100644 index 00000000000..3b99c4eb310 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java @@ -0,0 +1,44 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import java.text.MessageFormat; + +import javax.annotation.PostConstruct; + +import org.eclipse.e4.core.services.nls.Message; + +/** + * Load messages out of a class based resource bundle specified in the annotation. + */ +@Message(contributionURI = "bundleclass://org.eclipse.e4.core.javax.tests/org.eclipse.e4.core.internal.tests.nls.ResourceBundleClass") +public class ResourceBundleClassMessages { + + //message as is + public String message; + + //message as is with underscore + public String message_one; + + //message as is camel cased + public String messageOne; + + //message with underscore transformed to . separated properties key + public String message_two; + + //camel cased message transformed to . separated properties key + public String messageThree; + + //message with placeholder + public String messageFour; + + // message with camel case and underscore + public String messageFive_Sub; + public String messageSix_Sub; + public String messageSeven_Sub; + public String messageEight_Sub; + public String messageNine_Sub; + + @PostConstruct + public void format() { + messageFour = MessageFormat.format(messageFour, "Tom"); //$NON-NLS-1$ + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass_de.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass_de.java new file mode 100644 index 00000000000..3506e37adbe --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClass_de.java @@ -0,0 +1,23 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import java.util.ListResourceBundle; + +public class ResourceBundleClass_de extends ListResourceBundle { + @Override + protected Object[][] getContents() { + return new Object[][] { + new Object[] { "message", "ResourceBundleClassNachricht" }, + new Object[] { "message_one", "ResourceBundleClassNachrichtUnderscore" }, + new Object[] { "messageOne", "ResourceBundleClassNachrichtCamelCase" }, + new Object[] { "message_two", "ResourceBundleNachrichtMessageUnderscoreDot" }, + new Object[] { "messageFour", "Die Idee ist von {0}" }, + new Object[] { "messageFive_Sub", "ResourceBundleClassNachrichtCamelCaseAndUnderscoreOriginal" }, + new Object[] { "message_six__sub", "ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeCamelCasified" }, + new Object[] { "message.seven..sub", + "ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified" }, + new Object[] { "messageEight.Sub", "ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeUnderscorified" }, + new Object[] { "message_nine._sub", + "ResourceBundleClassNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified" } + }; + } +} \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java new file mode 100644 index 00000000000..4a5643c4789 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java @@ -0,0 +1,44 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import java.text.MessageFormat; + +import javax.annotation.PostConstruct; + +import org.eclipse.e4.core.services.nls.Message; + +/** + * Load messages from a resource folder in the plugin + */ +@Message(contributionURI = "platform:/plugin/org.eclipse.e4.core.javax.tests/resources/another") +public class ResourcesMessages { + + //message as is + public String message; + + //message as is with underscore + public String message_one; + + //message as is camel cased + public String messageOne; + + //message with underscore transformed to . separated properties key + public String message_two; + + //camel cased message transformed to . separated properties key + public String messageThree; + + //message with placeholder + public String messageFour; + + // message with camel case and underscore + public String messageFive_Sub; + public String messageSix_Sub; + public String messageSeven_Sub; + public String messageEight_Sub; + public String messageNine_Sub; + + @PostConstruct + public void format() { + messageFour = MessageFormat.format(messageFour, "Tom"); //$NON-NLS-1$ + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java new file mode 100644 index 00000000000..eecea6f2224 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java @@ -0,0 +1,41 @@ +package org.eclipse.e4.core.internal.tests.nls; + +import java.text.MessageFormat; + +import javax.annotation.PostConstruct; + +/** + * Load messages from a relative positioned resource bundle (./SimpleMessages.properties) + */ +public class SimpleMessages { + + //message as is + public String message; + + //message as is with underscore + public String message_one; + + //message as is camel cased + public String messageOne; + + //message with underscore transformed to . separated properties key + public String message_two; + + //camel cased message transformed to . separated properties key + public String messageThree; + + //message with placeholder + public String messageFour; + + // message with camel case and underscore + public String messageFive_Sub; + public String messageSix_Sub; + public String messageSeven_Sub; + public String messageEight_Sub; + public String messageNine_Sub; + + @PostConstruct + public void format() { + messageFour = MessageFormat.format(messageFour, "Tom"); //$NON-NLS-1$ + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.properties new file mode 100644 index 00000000000..7a0051d5c1f --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.properties @@ -0,0 +1,11 @@ +message=SimpleMessage +message_one=SimpleMessageUnderscore +messageOne=SimpleMessageCamelCase +message.two=SimpleMessageUnderscoreDot +message.three=SimpleMessageCamelCaseDot +message.four=The idea is from {0} +messageFive_Sub=SimpleMessageCamelCaseAndUnderscoreOriginal +message_six__sub=SimpleMessageCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=SimpleMessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=SimpleMessageCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=SimpleMessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de.properties new file mode 100644 index 00000000000..76c3c89335f --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de.properties @@ -0,0 +1,10 @@ +message=SimpleNachricht +message_one=SimpleNachrichtUnderscore +messageOne=SimpleNachrichtCamelCase +message.two=SimpleNachrichtUnderscoreDot +message.four=Die Idee ist von {0} +messageFive_Sub=SimpleNachrichtCamelCaseAndUnderscoreOriginal +message_six__sub=SimpleNachrichtCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=SimpleNachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=SimpleNachrichtCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=SimpleNachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH.properties new file mode 100644 index 00000000000..fba770fa7c2 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH.properties @@ -0,0 +1,2 @@ +message=Region +messageOne=RegionOne diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_OTHER.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_OTHER.properties new file mode 100644 index 00000000000..ba394356302 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_OTHER.properties @@ -0,0 +1,2 @@ +message=RegionWithOtherVariant +messageOne=RegionWithOtherVariantOne diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_TEST.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_TEST.properties new file mode 100644 index 00000000000..ca232d2609b --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages_de_CH_TEST.properties @@ -0,0 +1,2 @@ +message=RegionWithTestVariant +messageOne=RegionWithTestVariantOne diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages.properties new file mode 100644 index 00000000000..26442f03bd3 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages.properties @@ -0,0 +1,11 @@ +message=Message +message_one=MessageUnderscore +messageOne=MessageCamelCase +message.two=MessageUnderscoreDot +message.three=MessageCamelCaseDot +message.four=The idea is from {0} +messageFive_Sub=MessageCamelCaseAndUnderscoreOriginal +message_six__sub=MessageCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=MessageCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=MessageCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=MessageCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages_de.properties b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages_de.properties new file mode 100644 index 00000000000..a1b3501cbb1 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/nls/messages_de.properties @@ -0,0 +1,10 @@ +message=Nachricht +message_one=NachrichtUnderscore +messageOne=NachrichtCamelCase +message.two=NachrichtUnderscoreDot +message.four=Die Idee ist von {0} +messageFive_Sub=NachrichtCamelCaseAndUnderscoreOriginal +message_six__sub=NachrichtCamelCaseAndUnderscoreDeCamelCasified +message.seven..sub=NachrichtCamelCaseAndUnderscoreDeCamelCasifiedAndDeUnderscorified +messageEight.Sub=NachrichtCamelCaseAndUnderscoreDeUnderscorified +message_nine._sub=NachrichtCamelCaseAndUnderscoreDeUnderscorifiedAndDeCamelCasified \ No newline at end of file diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/javax/tests/CoreTestSuite.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/javax/tests/CoreTestSuite.java new file mode 100644 index 00000000000..572ec083fae --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/javax/tests/CoreTestSuite.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2009, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Lars Vogel - Bug 474274 + * Alexander Fedorov - Bug 548516 + ******************************************************************************/ + +package org.eclipse.e4.core.javax.tests; + +import org.eclipse.e4.core.internal.tests.contexts.ActivationTest; +import org.eclipse.e4.core.internal.tests.contexts.ContextDynamicTest; +import org.eclipse.e4.core.internal.tests.contexts.DependenciesLeakTest; +import org.eclipse.e4.core.internal.tests.contexts.EclipseContextTest; +import org.eclipse.e4.core.internal.tests.contexts.NeutralValueTest; +import org.eclipse.e4.core.internal.tests.contexts.ReparentingTest; +import org.eclipse.e4.core.internal.tests.contexts.RunAndTrackTest; +import org.eclipse.e4.core.internal.tests.contexts.StrongIterableTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ActivationInjectionTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.AnnotationsInjectionTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.Bug317183Test; +import org.eclipse.e4.core.internal.tests.contexts.inject.ComplexDisposalTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ContextFunctionDynamicsTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ContextInjectionDisposeTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ContextInjectionFactoryTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ContextInjectionTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.DisposingReferencedContextTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ExtraDependenciesTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.GenericsInjectionTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.GroupedUpdatesTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.InjectStaticContextTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.InjectionUpdateTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.InvokeInRATTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ParentContextDisposalTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ProviderInjectionTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.ServiceContextTest; +import org.eclipse.e4.core.internal.tests.contexts.inject.TestConstructorInjection; +import org.eclipse.e4.core.internal.tests.di.AutoConstructWithCreatableTest; +import org.eclipse.e4.core.internal.tests.di.DisposeClassLinkTest; +import org.eclipse.e4.core.internal.tests.di.InjectArraysTest; +import org.eclipse.e4.core.internal.tests.di.InjectBaseTypeTest; +import org.eclipse.e4.core.internal.tests.di.InjectBridgeTest; +import org.eclipse.e4.core.internal.tests.di.InjectionOrderTest; +import org.eclipse.e4.core.internal.tests.di.InjectionResultLeakTest; +import org.eclipse.e4.core.internal.tests.di.InvokeTest; +import org.eclipse.e4.core.internal.tests.di.InvokeTestMissingAnnotation; +import org.eclipse.e4.core.internal.tests.di.RecursiveObjectCreationTest; +import org.eclipse.e4.core.internal.tests.di.extensions.ExtendedSupplierInjectionTests; +import org.eclipse.e4.core.internal.tests.di.extensions.InjectionEventTest; +import org.eclipse.e4.core.internal.tests.di.extensions.InjectionMixedSuppliersTest; +import org.eclipse.e4.core.internal.tests.di.extensions.InjectionOSGiHandlerTest; +import org.eclipse.e4.core.internal.tests.di.extensions.InjectionOSGiTest; +import org.eclipse.e4.core.internal.tests.di.extensions.InjectionPreferencesTest; +import org.eclipse.e4.core.internal.tests.di.extensions.ServiceSupplierTestCase; +import org.eclipse.e4.core.internal.tests.nls.MessageRegistryTest; +import org.eclipse.e4.core.internal.tests.nls.NLSTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import junit.framework.JUnit4TestAdapter; +import junit.framework.Test; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ExtendedSupplierInjectionTests.class, + InjectionPreferencesTest.class, + InjectionMixedSuppliersTest.class, + InjectionEventTest.class, + InjectionOSGiTest.class, + InjectionOSGiHandlerTest.class, + ServiceSupplierTestCase.class, + + // DI + InjectionOrderTest.class, + InvokeTest.class, + InjectBaseTypeTest.class, + InvokeTestMissingAnnotation.class, + InjectionResultLeakTest.class, + AutoConstructWithCreatableTest.class, + + // Contexts + StrongIterableTest.class, + EclipseContextTest.class, + ContextInjectionTest.class, + ContextInjectionDisposeTest.class, + ContextInjectionFactoryTest.class, + ContextDynamicTest.class, + ReparentingTest.class, + RunAndTrackTest.class, + ParentContextDisposalTest.class, + ComplexDisposalTest.class, + DisposeClassLinkTest.class, + InjectStaticContextTest.class, + ActivationTest.class, + NeutralValueTest.class, + + // Contexts injection + AnnotationsInjectionTest.class, + TestConstructorInjection.class, + ServiceContextTest.class, + ProviderInjectionTest.class, + InjectionUpdateTest.class, + DisposingReferencedContextTest.class, + InjectionOrderTest.class, + GroupedUpdatesTest.class, + ExtraDependenciesTest.class, + ContextFunctionDynamicsTest.class, + InjectArraysTest.class, + InjectBridgeTest.class, + InvokeInRATTest.class, + Bug317183Test.class, + DependenciesLeakTest.class, + ActivationInjectionTest.class, + GenericsInjectionTest.class, + RecursiveObjectCreationTest.class, + + // NLS + NLSTest.class, + MessageRegistryTest.class, + }) +public class CoreTestSuite { + public static Test suite() { + return new JUnit4TestAdapter(CoreTestSuite.class); + } +} diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/test.xml b/runtime/tests/org.eclipse.e4.core.javax.tests/test.xml new file mode 100644 index 00000000000..5b1d670de07 --- /dev/null +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/test.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/runtime/tests/org.eclipse.e4.core.tests/META-INF/MANIFEST.MF b/runtime/tests/org.eclipse.e4.core.tests/META-INF/MANIFEST.MF index f1ffc610d52..7499547338d 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/META-INF/MANIFEST.MF +++ b/runtime/tests/org.eclipse.e4.core.tests/META-INF/MANIFEST.MF @@ -17,8 +17,8 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.6.0", org.junit;bundle-version="4.12.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-17 -Import-Package: javax.annotation, - javax.inject;version="1.0.0", +Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)", + jakarta.inject;version="[2.0.0,3.0.0)", org.osgi.service.component;version="1.3.0", org.osgi.service.event;version="1.3.0" Export-Package: org.eclipse.e4.core.internal.tests;x-internal:=true, diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java index 767113bd3dd..15cb34dbffe 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java @@ -18,15 +18,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.contexts.RunAndTrack; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class ActivationTest { static public class TestRAT extends ContextFunction { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java index 3476abb11c2..5dcbfe3e8e6 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ReparentingTest.java @@ -20,9 +20,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -31,6 +28,9 @@ import org.eclipse.e4.core.internal.tests.contexts.inject.ObjectSuperClass; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Test for changing a context's parent. */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java index 9b83bdcb0e1..6b30f555306 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ActivationInjectionTest.java @@ -17,9 +17,6 @@ import static org.junit.Assert.assertEquals; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.Active; import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; @@ -28,6 +25,9 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class ActivationInjectionTest { static public class TestRAT extends ContextFunction { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java index 4aaf0282406..c04a5383f67 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/AnnotationsInjectionTest.java @@ -19,11 +19,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -31,6 +26,10 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import jakarta.inject.Named; import junit.framework.AssertionFailedError; /** * Tests for the basic context injection functionality diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java index 7e6ea12038c..12ae62c3bdf 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ComplexDisposalTest.java @@ -16,16 +16,16 @@ import static org.junit.Assert.assertEquals; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * See bug 296337: duplicate disposal of an object */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java index 1f2b8c82e81..9783d1afd18 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextFunctionDynamicsTest.java @@ -17,9 +17,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -27,6 +24,9 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class ContextFunctionDynamicsTest { private static final String SELECTION = "selection"; //$NON-NLS-1$ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java index 7b832082b77..c5249f44bba 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionDisposeTest.java @@ -19,15 +19,15 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; + /** * Tests for injection handling of context dispose, and handling disposal of * injected objects. diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java index b9d9ebd0e85..6e860b7af3a 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ContextInjectionTest.java @@ -18,15 +18,15 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import javax.annotation.PostConstruct; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.contexts.RunAndTrack; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.inject.Inject; + /** * Tests for the basic context injection functionality */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java index 7467d0beda4..0e96d9fa442 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/DisposingReferencedContextTest.java @@ -16,9 +16,6 @@ import static org.junit.Assert.assertEquals; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -26,6 +23,9 @@ import org.eclipse.e4.core.internal.contexts.EclipseContext; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class DisposingReferencedContextTest { static class MandatoryTarget { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java index 50b1adbea35..9d31b6d91dc 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ExtraDependenciesTest.java @@ -22,15 +22,15 @@ import java.lang.reflect.InvocationTargetException; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class ExtraDependenciesTest { static public class TestObject { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java index 210d385c459..f1fcc640f01 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsInjectionTest.java @@ -16,14 +16,14 @@ import static org.junit.Assert.assertEquals; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Tests for the generics context injection functionality */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java index 90e34d498bb..07d0d62dfe7 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GenericsListTest.java @@ -18,13 +18,13 @@ import java.util.ArrayList; import java.util.List; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.inject.Inject; + /** * Tests for the type erasure in lists */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java index ad0eb3e41e9..882edc6b8f2 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/GroupedUpdatesTest.java @@ -16,15 +16,15 @@ import static org.junit.Assert.assertEquals; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.GroupUpdates; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class GroupedUpdatesTest { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java index c94cb865cec..a34b357c13e 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectStaticContextTest.java @@ -18,11 +18,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -30,6 +25,11 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Tests for the context injection functionality using 2 contexts */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java index 05cb99cd326..91d32235436 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionOrderTest.java @@ -16,15 +16,15 @@ import static org.junit.Assert.assertTrue; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class InjectionOrderTest { public static class InjectTargetMethod { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java index 57f7bf08e1e..dbea804a226 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InjectionUpdateTest.java @@ -19,10 +19,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -31,6 +27,10 @@ import org.junit.Before; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Tests updates of injected values and calls to runnables */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java index 704c8a20007..e11810fa1c5 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/InvokeInRATTest.java @@ -16,8 +16,6 @@ import static org.junit.Assert.assertEquals; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -26,6 +24,8 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.inject.Named; + /** * Tests for the context injection functionality using 2 contexts */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java index d8a01110d4e..2f6186799e3 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectBasic.java @@ -13,13 +13,13 @@ *******************************************************************************/ package org.eclipse.e4.core.internal.tests.contexts.inject; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Optional; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; + /** * Test class to check injection mechanism */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java index c1417a1e59d..f31ebbaca21 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSubClass.java @@ -13,12 +13,12 @@ *******************************************************************************/ package org.eclipse.e4.core.internal.tests.contexts.inject; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.IEclipseContext; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; + /** * Test class to check injection mechanism into classes with inheritance */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java index f144558d2bc..abe2705f8d0 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ObjectSuperClass.java @@ -13,12 +13,12 @@ *******************************************************************************/ package org.eclipse.e4.core.internal.tests.contexts.inject; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.IEclipseContext; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; + /** * Test class to check injection mechanism into classes with inheritance */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java index 1edb3cabffc..86664632fe0 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/OptionalAnnotations.java @@ -14,10 +14,10 @@ package org.eclipse.e4.core.internal.tests.contexts.inject; -import javax.inject.Inject; - import org.eclipse.e4.core.di.annotations.Optional; +import jakarta.inject.Inject; + public class OptionalAnnotations { @Inject @Optional diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java index 33ce50ed91f..283ad17fc39 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ParentContextDisposalTest.java @@ -16,16 +16,16 @@ import static org.junit.Assert.assertEquals; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class ParentContextDisposalTest { static class Target { int pc = 0; diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java index 44dae9927cd..a1aed822b3d 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ProviderInjectionTest.java @@ -17,9 +17,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import javax.inject.Inject; -import javax.inject.Provider; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -28,6 +25,9 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Provider; + /** * Testing provider interface diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java index 84e6ce88bdb..486d4d344ab 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/ServiceContextTest.java @@ -24,8 +24,6 @@ import java.util.ArrayList; import java.util.List; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -42,6 +40,8 @@ import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; +import jakarta.inject.Inject; + /** * Tests for contexts used in OSGi services. */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java index 5c3bfa99048..5819f48659c 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/inject/TestConstructorInjection.java @@ -23,13 +23,13 @@ import java.lang.reflect.InvocationTargetException; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.inject.Inject; + public class TestConstructorInjection { static class TestConstructorObject { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java index f5453437c5f..80ebed9ca6b 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/AutoConstructWithCreatableTest.java @@ -17,8 +17,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -27,6 +25,8 @@ import org.junit.Before; import org.junit.Test; +import jakarta.inject.Inject; + public class AutoConstructWithCreatableTest { private IEclipseContext context; diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java index ef24fe0d6a9..4573266d550 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/DisposeClassLinkTest.java @@ -17,16 +17,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.core.di.extensions.EventTopic; import org.junit.Test; + +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; /** * Checks that injected objects that do not have normal links * established to the context are still notified on context diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java index 978e86dc110..2a033c12b3a 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectArraysTest.java @@ -17,14 +17,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Checks injection of arrays */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java index 16a8afdadfc..79ca2c3ff6a 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBaseTypeTest.java @@ -15,15 +15,15 @@ import static org.junit.Assert.assertEquals; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Checks conversion of primitive types */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java index 71b00e7dbb6..b127399d230 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectBridgeTest.java @@ -13,8 +13,6 @@ ******************************************************************************/ package org.eclipse.e4.core.internal.tests.di; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -22,6 +20,8 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.junit.Test; +import jakarta.inject.Inject; + public class InjectBridgeTest { static class Base { public void testInject(T value) { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java index 753d88e0b55..0074f888458 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionOrderTest.java @@ -17,16 +17,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.InjectionException; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; + public class InjectionOrderTest { public interface ITestObject { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java index 1cc34cbc93c..296ef5c2ecf 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/InjectionResultLeakTest.java @@ -19,15 +19,15 @@ import java.lang.ref.WeakReference; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Optional; import org.junit.Test; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Test that we don't hold on to the values calculated during injection. * This test relies on VM performing garbage collection in System.gc(). diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java index 1a57e37b3d9..4d78a14b1bb 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/RecursiveObjectCreationTest.java @@ -17,15 +17,15 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import javax.annotation.PostConstruct; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.InjectionException; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.inject.Inject; + public class RecursiveObjectCreationTest { static public class CheckSelfInject { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java index 98801febfc4..d82e28f83f6 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ExtendedSupplierInjectionTests.java @@ -20,9 +20,6 @@ import java.util.Dictionary; import java.util.Hashtable; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -40,6 +37,9 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceRegistration; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; + @SuppressWarnings("restriction") public class ExtendedSupplierInjectionTests { static final String TOPIC = "org/eclipse/e4/core/tests/di/extensions/ExtendedSupplierInjectionTests"; diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java index c6b077fc56e..402f16a9c9a 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionEventTest.java @@ -23,9 +23,6 @@ import java.util.Dictionary; import java.util.Hashtable; -import javax.inject.Inject; -import javax.inject.Singleton; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -44,6 +41,9 @@ import org.osgi.service.event.EventAdmin; import org.osgi.service.event.EventConstants; +import jakarta.inject.Inject; +import jakarta.inject.Singleton; + // TBD add auto-conversion? @SuppressWarnings("restriction") public class InjectionEventTest { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java index b1fef0aa783..9adc94aff8e 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionMixedSuppliersTest.java @@ -18,9 +18,6 @@ import java.lang.reflect.InvocationTargetException; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.e4.core.contexts.ContextInjectionFactory; @@ -31,6 +28,9 @@ import org.junit.Test; import org.osgi.service.prefs.BackingStoreException; +import jakarta.inject.Inject; +import jakarta.inject.Named; + public class InjectionMixedSuppliersTest { static class InjectTarget { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java index 21e9cdd5e1d..1731b8e8e39 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiTest.java @@ -20,8 +20,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -35,6 +33,8 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; +import jakarta.inject.Inject; + public class InjectionOSGiTest { // classed used as a user of the @OSGiBundle annotation diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java index 3c4d0c5cb3b..9c684c3fb29 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionPreferencesTest.java @@ -18,8 +18,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import javax.inject.Inject; - import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.e4.core.contexts.ContextInjectionFactory; @@ -31,6 +29,8 @@ import org.junit.Test; import org.osgi.service.prefs.BackingStoreException; +import jakarta.inject.Inject; + /** * Note: we do not support byte arrays at this time. */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java index 6a4cb607dab..27f47b0d663 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionWithoutOSGITest.java @@ -18,15 +18,15 @@ import java.lang.reflect.InvocationTargetException; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; import org.osgi.service.prefs.BackingStoreException; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * This test should be execute without an OSGI runtime running to verfiy BR * 513883 diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java index ca6db748117..07000621041 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java @@ -11,8 +11,6 @@ import java.util.function.BooleanSupplier; import java.util.function.Supplier; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -26,6 +24,8 @@ import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; +import jakarta.inject.Inject; + public class ServiceSupplierTestCase { public static class TestBean { volatile TestService service; diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java index cfbaf57355b..1853761c6e1 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ComputedValueLimitationTest.java @@ -16,14 +16,14 @@ import static org.junit.Assert.assertTrue; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.junit.Test; +import jakarta.inject.Inject; + /** * This is a demo of a scenario when computed values don't work. The basic idea here is that a diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java index 5e1b4618c94..0b569eea856 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/ContextExample.java @@ -16,8 +16,6 @@ import java.text.NumberFormat; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -27,6 +25,8 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +import jakarta.inject.Inject; + /** * */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java index 599d551812b..6ce281a8337 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java @@ -14,11 +14,6 @@ *******************************************************************************/ package org.eclipse.e4.core.internal.tests.manual; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import javax.inject.Named; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -26,6 +21,11 @@ import org.eclipse.e4.core.di.annotations.Creatable; import org.junit.Test; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * Manual test to observe error reporting. The JUnits in this * test are expected to produce exceptions in the output stream. diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java index 1b486932a38..b5044d85c29 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessages.java @@ -2,7 +2,7 @@ import java.text.MessageFormat; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; /** * Load messages from the OSGi resource bundle (OSGI-INF/l10n/bundle.properties) diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java index d21c6138257..73b1a903fce 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/BundleMessagesRegistry.java @@ -1,11 +1,11 @@ package org.eclipse.e4.core.internal.tests.nls; -import javax.inject.Inject; - import org.eclipse.e4.core.di.annotations.Creatable; import org.eclipse.e4.core.services.nls.BaseMessageRegistry; import org.eclipse.e4.core.services.nls.Translation; +import jakarta.inject.Inject; + @Creatable public class BundleMessagesRegistry extends BaseMessageRegistry { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java index 9baf2ac75d4..e447bbe3a69 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/MessageRegistryTest.java @@ -20,8 +20,6 @@ import java.util.Locale; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -30,6 +28,8 @@ import org.junit.Test; import org.osgi.framework.FrameworkUtil; +import jakarta.inject.Inject; + public class MessageRegistryTest { static class TestObject { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java index 037b354098a..f24556a35fd 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/Messages.java @@ -2,7 +2,7 @@ import java.text.MessageFormat; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; /** * Load messages from a relative positioned resource bundle (./messages.properties) diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java index 440571d0fb9..fed1adec6af 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java @@ -20,8 +20,6 @@ import java.util.Locale; -import javax.inject.Inject; - import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -32,6 +30,8 @@ import org.junit.Test; import org.osgi.framework.FrameworkUtil; +import jakarta.inject.Inject; + public class NLSTest { static class TestSimpleObject { diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java index b616933880b..4e13fad4904 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourceBundleClassMessages.java @@ -2,10 +2,10 @@ import java.text.MessageFormat; -import javax.annotation.PostConstruct; - import org.eclipse.e4.core.services.nls.Message; +import jakarta.annotation.PostConstruct; + /** * Load messages out of a class based resource bundle specified in the annotation. */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java index 6025ecf08be..a3eb989103b 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/ResourcesMessages.java @@ -2,10 +2,10 @@ import java.text.MessageFormat; -import javax.annotation.PostConstruct; - import org.eclipse.e4.core.services.nls.Message; +import jakarta.annotation.PostConstruct; + /** * Load messages from a resource folder in the plugin */ diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java index eecea6f2224..fbf6afed997 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/SimpleMessages.java @@ -2,7 +2,7 @@ import java.text.MessageFormat; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; /** * Load messages from a relative positioned resource bundle (./SimpleMessages.properties)