adamcin commented on PR #31:
URL: 
https://github.com/apache/sling-org-apache-sling-testing-osgi-mock/pull/31#issuecomment-1759710542

   > which brings me to another question: consider you have the use case to 
apply a certain osgi config to all tests in a test class. can you apply the 
config annotations or ConfigType/UpdateConfig also on class level? (but that 
makes it more complicated to handle cases when there are used both on class 
level and method level, with different config values)
   
   @stefanseifert The existing annotations are all inheritable and locally 
overridable, in their own way. 
   
   `@UpdateConfig` annotations are applied in declaration, first on the class 
level then on the method level, so method configs end up overwriting class 
level configs when they have the same pid. 
   
   `@ConfigType` annotations are injected (or streamed from `ConfigCollector`) 
in declaration order on the *method level* first, then on the class level.
   
   This is currently supported for JUnit5:
   
   ```java
   import org.apache.sling.testing.mock.osgi.config.annotations.ConfigType;
   import 
org.apache.sling.testing.mock.osgi.junit5.OsgiConfigParametersExtension;
   import org.junit.jupiter.api.Assertions;
   import org.junit.jupiter.api.extension.ExtendWith;
   
   @ConfigType(type = MyService.Config.class, property = "myConfigValue=first 
class value")
   @MyService.Config(myConfigValue = "second class value")
   @ExtendWith(OsgiConfigParametersExtension.class)
   class MyServiceTest {
   
       @MyService.Config(myConfigValue = "first method value")
       @ConfigType(type = MyService.Config.class, property = 
"myConfigValue=second method value")
       @Test
       void myServiceMethod(MyService.Config config1,
                            MyService.Config config2,
                            MyService.Config config3,
                            MyService.Config config4) {
           MyService myService1 = new MyService(config1);
           Assertions.assertEquals("first method value", 
myService1.getMyConfigValue());
   
           MyService myService2 = new MyService(config2);
           Assertions.assertEquals("second method value", 
myService2.getMyConfigValue());
   
           MyService myService3 = new MyService(config3);
           Assertions.assertEquals("first class value", 
myService3.getMyConfigValue());
   
           MyService myService4 = new MyService(config4);
           Assertions.assertEquals("second class value", 
myService4.getMyConfigValue());
       }
   }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to