On Tuesday, February 25, 2020 1:40:17 AM CET Andreas Schaefer wrote: > As far as I can tell this does not work for my purpose. I need to run the > tests in the project’s IT test with Sling and the full application > installed. It needs to be run before the IT tests actually run just to make > sure all references are satisfied (and maybe more later). My project has > multiple bundles with services in them and it does have services provided > by the IT test environment. All of them need to be checked in the setup() > method before any tests run.
Why do you think so? An application in this case is a bunch of bundles and configurations, right? Let's stick to the Scripting FreeMarker example and walk through. The application is configured in FreemarkerTestSupport: https://github.com/apache/sling-org-apache-sling-scripting-freemarker/blob/ master/src/test/java/org/apache/sling/scripting/freemarker/it/tests/ FreemarkerTestSupport.java#L69 Initial content is added in FreemarkerTestSupport also: https://github.com/apache/sling-org-apache-sling-scripting-freemarker/blob/ master/src/test/java/org/apache/sling/scripting/freemarker/it/tests/ FreemarkerTestSupport.java#L86 In FreemarkerScriptEngineFactoryIT additional (test) services are added: https://github.com/apache/sling-org-apache-sling-scripting-freemarker/blob/ master/src/test/java/org/apache/sling/scripting/freemarker/it/tests/ FreemarkerScriptEngineFactoryIT.java#L55 The OSGi container and application are started by Pax Exam in a forked (fully isolated) JVM: https://github.com/apache/sling-org-apache-sling-scripting-freemarker/blob/ master/src/test/java/org/apache/sling/scripting/freemarker/it/tests/ FreemarkerScriptEngineFactoryIT.java#L43 Pax Exam waits until all injection points (@Inject) are satisfied before running any test. You can also wait for content installed in JCR with the help of Resource Presence: https://github.com/apache/sling-org-apache-sling-scripting-freemarker/blob/ master/src/test/java/org/apache/sling/scripting/freemarker/it/tests/ SimpleIT.java#L58 https://github.com/apache/sling-org-apache-sling-scripting-freemarker/blob/ master/src/test/java/org/apache/sling/scripting/freemarker/it/tests/ SimpleIT.java#L50 You can have additional logic in methods annotated with @Before and @After. Anything missing? Regards, O. > Cheers - Andy > > > On Feb 24, 2020, at 2:05 PM, Oliver Lietz <[email protected]> wrote: > > > > On Friday, February 14, 2020 6:22:55 PM CET Andreas Schaefer wrote: > >> I don’t think that would work for me. > >> > >> I have a set of IT that will test services running in a Sling Start Maven > >> Plugin instance. In order to make sure that my tests can succeed and do > >> not > >> fail because of unsatisfied references I want to check the references > >> before starting the tests (I had multiple occasions where I was debugging > >> my code just to figure out that my bundles were active but some services > >> were not accessible because of these unsatisfied references). > > > > That's an OOTB feature of Pax Exam, see examples (@Inject): > > > > https://sling.apache.org/documentation/development/testing-paxexam.html > > > > O. > > > >> - Andy > >> > >>> On Feb 14, 2020, at 12:18 AM, Stefan Seifert <[email protected]> > >>> wrote: > >>> > >>> did you try to use > >>> https://sling.apache.org/documentation/development/osgi-mock.html > >>> > >>> it can be used standalone or as part of sling mocks. > >>> > >>> stefan > >>> > >>>> -----Original Message----- > >>>> From: Andreas Schaefer [mailto:[email protected]] > >>>> Sent: Thursday, February 13, 2020 10:34 PM > >>>> To: dev > >>>> Subject: Enhancing Testing Client OSGi package > >>>> > >>>> Hi > >>>> > >>>> I am working on a project with many backend OSGi services that have > >>>> many > >>>> references between them and I ran into many issues when the services > >>>> were > >>>> not fully workable due to unsatisfied references. > >>>> > >>>> The Testing Clients’ OsgiConsoleClient has a few methods to introspect > >>>> the > >>>> state of the OSGi bundles, components and services but they are not > >>>> easy > >>>> to > >>>> use. > >>>> > >>>> In my case I need to find the ‘Declarative Service Components’, then > >>>> get > >>>> their Service Info and check that any reference of these components are > >>>> satisfied. After some back and forth I was able to implement these > >>>> tests > >>>> but I could not use the OsgiConsoleClient which makes for a lot of > >>>> heavy > >>>> handed JsonNode parsing. > >>>> > >>>> So I was wondering if this is of interest for Sling to have a better > >>>> way > >>>> to > >>>> inspect the OSGi system. This is what I have in mind: > >>>> - Add additional data from the bundles into the BundleInfo class (like > >>>> the > >>>> Declarative Service Components) > >>>> - Add additional data from the components into the ComponentInfo > >>>> (references etc) > >>>> - Add a method to call the OSGi Console from the OsgiConsoleClient > >>>> directly > >>>> (it does not support depths so the SlingClient’s doGet() does not work) > >>>> > >>>> Let me know if you think this would be valuable for Sling Testing > >>>> Clients. > >>>> > >>>> - Andy
