Hello again
I’m having problems with testing my code using Adaptavist’s extension to Arquillian for JIRA. The error is as follows :
java.lang.IllegalStateException: Error launching test it.criticalpath.services.BigPictureCriticalPathServiceTest public void it.criticalpath.services.BigPictureCriticalPathServiceTest.getCriticalPathWarningsFor()
(…)
Caused by: java.lang.IllegalStateException: Error launching request at http://localhost:2990/jira/ArquillianServletRunner?outputMode=serializedObject&className=it.criticalpath.services.BigPictureCriticalPathServiceTest&methodName=getCriticalPathWarningsFor. No result returned
at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.executeWithRetry(ServletMethodExecutor.java:117)
at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.invoke(ServletMethodExecutor.java:89)
... 76 more
And I made sure that I have the class under test annotated with @ExportAsDevService
, as well that I have correct exports in <Export-Package>
section of jira-maven-plugin
configuration, so all needed classes should be available for the test plugin created by arquillian containers.
So what can be the problem here ? The error message is not especially helpful, as I can’t pinpoint the exact cause, and the internet doesn’t say much about it (at least I couldn’t find anything helpful).
Is there maybe some way to make the logging more explicit, or to access the logs that Adaptavists Arquillian extension creates (if it does create any) to see what exactly goes wrong ?
I’m having the same problem with testing my services that use active objects. Any explanation of how to fix that, or where to look for an answer would be greatly appreciated.
Hi!
There are many ways Arquillian testing can fail. Without more details over what you want to accomplish it is quite hard to pinpoint an error.
We currently use Arquillian to test our service layer, which then uses ActiveObjects deeper down. We do not need to export these services as OSGi services. Instead Arquillian, or better the Adaptavist extension, creates a complete OSGi Bundle that behaves like a bitbucket plugin. This means, that it has to contain all production code you would like to test, as well as any dependency needed for that. Similarly to a normal plugin, Spring Scanning works as well. In your test code, you can inject all the necessary services. An odd thing there, only @Autowired
has worked for us, @Inject
did not to anything.
If you could provide a stripped down version of what you want to accomplish I could probably help further. Especially the static @BeforeDeployment
annotated method is of interest, as it shows what classes and resources are packed into the test plugin.
Best regards!
That’s interesting. In every example I’ve come across up to now the class under test needed to be exported as a service, because as far as I came to understand the Adaptavists extension creates a separate test plugin that is deployed to the JIRA instance. And you say that the @BeforeDeployment
annotated method is of interest, yet I haven’t used this up to now.
So after I read your comment I’ve tried adding the @BeforeDeployment
method like this :
@BeforeDeployment
public static Archive<?> addDeploymentContent(JavaArchive archive) {
return archive.addPackages(
true,
"com.mypluginpackage");
}
And removing the @ExportAsDevService
from the class under test as well as removing it from the <Export-Package>
section in the pom.xml
. I’ve also tried changing @Inject
to @Autowired
. Nevertheless it didn’t work.
Could you maybe provide me with some example of how to set up the tests so they contain full production code along with dependencies like you said you were doing ? Or maybe point me to some resources where I could learn how to do that ?
I have not much time today, but thinking about it, maybe it would indeed be better and simpler to test the exported services of the plugin under test because would not have to provide any implementation dependency to the Arquillian bundle. At the time i did not know about @ExportAsDevService
which would be essential, as I’d rather not export all our services as OSGi Services. I will try that if I get the time.
Anyway, I think with both ways you can get it to work. As for your chosen way, this repository: arquillian-examples implements that, but uses @ExportAsService
instead @ExportAsDevService
. Keep attention on the @ComponentImport
annotation for the service at test… this is necessary because it comes from a different bundle.
My current @BeforeDeployment
method looks something like this:
@BeforeDeployment
def addToDeployment(archive: JavaArchive): Archive[_] = {
val dependencies = Maven
.configureResolver()
.loadPomFromFile("pom.xml")
.resolve( List(
"bla.package:1.0.0",
"blub.package:1.0.0")
).withTransitivity.as(classOf[JavaArchive])
val a = archive.as(classOf[AtlassianPluginArchive])
.addPackages(true, "my.plugin.package")
dependencies
.foreach(dep => {
a.merge(dep)
})
a
}
I hope this helps for now!
1 Like
I think I’ve solved it !
@christian.ott thank you for linking the arquillian-examples
repo. There I found the code that I was missing.
The thing is the service I tested implemented an interface and therefore importing into the test like this :
@ComponentImport
@Inject
MyServiceImpl service;
didn’t work. The service implementation annotated like :
@Component
@ExportAsDevService
class MyServiceImpl implements MyService{...}
wasn’t recognized properly.
So the solution was to change the annotation to :
@ExportAsDevService(MyService.class)
and import like :
@ComponentImport
@Inject
#Note this is the interface not the implementation class
MyService service;
Then everything seems to work just fine.
1 Like