Hi !

I'm struggling with a issue in pax exam and declarative services for 
several days now which I'm not able to solve. I've created a very simple 
declarative services greeter project with metatype and configadmin to help 
illustrate the problem (in attach). The main issue is that the test times 
out with the error org.ops4j.pax.swissbox.tracker.ServiceLookupException: 
gave up waiting for service com.paxexam.ds.api.Greeter. 

This is happening because in the declarative service the configuration is 
mandatory (RQUIRED), the problem naturally disappears when the 
ConfigurationPolicy is IGNORE or OPTIONAL. However this should work. 
Besides, the service is not bound with the configuration in the lifetime of 
the test even with IGNORE or OPTIONAL. 
I'm using configuration admin support and from the tests that I've done it 
seems that the configuration is becoming attached to the probe. The bundle 
location extracted from the configuration object is valid but it shows as 
local (the same as the probe). The problem seems similar to the one 
reported in https://ops4j1.jira.com/browse/PAXEXAM-725 however I'm not able 
to influence the bundle location. From what I've seen 
in 
https://github.com/ops4j/org.ops4j.pax.exam2/blob/master/core/pax-exam-cm/src/main/java/org/ops4j/pax/exam/cm/internal/ConfigurationOptionConfigurationListener.java
 
everything seems correct namely the null in the bundle location parameter, 
so I'm a bit lost here :-(

My service is something as simples as the presented bellow:

// @formatter:off
@Component(
configurationPid = GreeterConfig.CPID,
configurationPolicy = ConfigurationPolicy.REQUIRE,
immediate = true)
// @formatter:on
public final class GreeterImpl implements Greeter {
private GreeterConfig config;
@Activate
public void activate(ComponentContext ctx, GreeterConfig config) {
this.config = config;
}
@Modified
public void modified(GreeterConfig config) {
this.config = config;
}

@Override
public String sayHello() {
return config.message();
}
}


The configuration is:

@ObjectClassDefinition(pid = GreeterConfig.CPID, name = "%name", 
description = "%description", localization = "OSGI-INF/l10n/greeter")
public @interface GreeterConfig {
public static final String CPID = "paxexam.greeter";
@AttributeDefinition(name = "%message.name", description = 
"%message.description")
String message() default "Hello !!";
}


The Pax exam test is:


@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class GreeterTest extends BaseTestSupport {
private static String MESSAGE = "Hello from a declarative service";

@Inject
private Greeter greeter;

@Override
protected Option bundles() {
return composite(super.bundles(), mavenBundle("com.paxexam.ds", 
"ri").versionAsInProject());
}

@Override
protected Option configurations() {
return composite(super.configurations(),
newConfiguration("paxexam.greeter").put("message", MESSAGE).asOption());
}

@Test
public void hello1() {
System.out.println("============= " + greeter.sayHello() + " 
=============");
}
}

In the end this example should have presented "Hello from a declarative 
service" instead of error.

Best Regards,
Ivo Leitão

dqweqwe

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: samples.tar.gz
Description: Binary data

Reply via email to