Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide way to handle configAdmin configutations via Annotations/Extension #164

Closed
stbischof opened this issue Jul 17, 2020 · 4 comments
Closed
Milestone

Comments

@stbischof
Copy link
Contributor

stbischof commented Jul 17, 2020

The ConfigurationExtension should help to config the Config-Admin using annotations. I also should inject Fields and Parameters of the org.osgi.service.cm.Configuration Type if they are annotated.

Could you have a look at this Example and give me some feedback

/*
 * Configure the Config-Admin using the annotation `@Configuration`
 * Get or Create an new Configuration Object.
 * Inject the `org.osgi.service.cm.Configuration` (if Parameter or Field) for further updates and delete
 *
 */
@Testable
@ExtendWith(ConfigurationExtension.class)
public class ConfigAnnotationTest2
{

    /*
     *
     * Create or Get a Configuration and us it in a Test
     *
     */

    @Configuration(pid = "my.pid", factory = true, properties = {
            @ConfigEntry(key = "foo", value = "bar") })
    static org.osgi.service.cm.Configuration configuration;

    @Test
    public void testUse() throws IOException
    {
        //TODO: some Tests

        //change Config
        configuration.update(Dictionaries.dictionaryOf("foo", "barbar"));

        //TODO: some Tests

        //delete Config
        configuration.delete();

        //TODO: some Tests
    }
    /*
     *
     * Create or Get @Configuration on for the Test and use the Configuration in the Test
     *
     */
    @Test
    public void updateConfigInTest(
        @Configuration(pid = "my.pid") org.osgi.service.cm.Configuration configuration)
            throws IOException
    {
        //TODO: some Tests
        //change Config
        configuration.update(Dictionaries.dictionaryOf("foo", "barbar"));
        //TODO: some Tests
    }

    /*
     *
     * Configure a service just for this Test
     *
     */
    private final String PID_NAME = "my.pid";

    @Test
    @Configuration(pid = PID_NAME, factory = true, properties = {
            @ConfigEntry(key = "key1", value = "value") })
    public void configMethodInjectService(
        @InjectService(filter = "(%s=%s)", filterArguments = { "service.pid",
                PID_NAME }) Object service)
    {
        service.toString();
    }

@bjhargrave
Copy link
Member

I don't know what you are trying to show with the code. You seem to be defining configurations with annotations in the test case class. You need much more explanation of what you are trying to do and why.

I can see that having some configuration in ConfigurationAdmin before running test methods can be useful. But I am not sure I can see what it means to inject a configuration into a field or a method parameter means.

@bjhargrave
Copy link
Member

Also, I think we would also want a way to provide equivalent support for JUnit 4.

@stbischof
Copy link
Contributor Author

stbischof commented Jul 17, 2020

I made the Example a bit more descriptive.
The idea is to get having some configuration in ConfigurationAdmin before running test.

I think this should be done by annotating the method.

    @Test
    @Configuration(pid = PID_NAME, factory = true, properties = {
            @ConfigEntry(key = "key1", value = "value") })
    public void configMethodInjectService(
        @InjectService(filter = "(%s=%s)", filterArguments = { "service.pid",
                PID_NAME }) Object service)
    {
        service.toString();
    }

To get access to the org.osgi.service.cm.Configuration::update and org.osgi.service.cm.Configuration::delete Method it would help to inject the org.osgi.service.cm.Configuration Fields and Parameters

    /*
     *
     * Create or Get @Configuration on for the Test and use the Configuration in the Test
     *
     */
    @Test
    public void updateConfigInTest(
        @Configuration(pid = "my.pid") org.osgi.service.cm.Configuration configuration)
            throws IOException
    {
        //TODO: some Tests
        //change Config
        configuration.update(Dictionaries.dictionaryOf("foo", "barbar"));
        //TODO: some Tests
    }

I this is interesting i will Provide an PR for Junit5 and Junit4

@kriegfrj
Copy link
Contributor

Closed via #165

@bjhargrave bjhargrave added this to the 1.0.0 milestone Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants