Spring-boot test not working with code coverage but works without code coverage - junit4

I have a spring-boot service with spring-security, version -2.1.2.RELEASE. Java-11.0.2
I have test cases written for my API integration testing.
When I run my test cases without code coverage it works, but when I run it with code coverage it fails.
The exception is basically from a configuration file called WebSecurityConfig.java which extends WebSecurityConfigurerAdapter. I have my ldap security check done here and also I am Auto Wiring a settings object called LdapSettings.java which is again a configuration.
Here is a glimpse of the exception which I get when I run with test with code coverage.
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class
Caused by: java.lang.ClassFormatError: Nest member class_info_index 49 has bad constant type in class file com/acumenllc/notifications/config/security/WebSecurityConfig
Also please suggest me if I am doing anything wrong in the design here.

Related

scalafix.sbt.ScalafixFailed: TestError

I have a unit test written using scalatest and running fine locally.
But on jenkins it fails with no specific error, just this:
[error] (scalafixAll) scalafix.sbt.ScalafixFailed: TestError
No test method is mentioned in traces, hence no hint about the cause.
How to really find the cause?

New dependency causing java.lang.NoSuchMethodError exception

I'm working on a project that is making use of a Scala ETCD client (https://github.com/nikore/scala-etcd), this has been all fine and good until I added a Scala Fleet client (https://github.com/MonsantoCo/fleet-client) into the mix.
When I compile it is fine but once I run the project it throws the following exception on the lines where the ETCDClient is constructed
Exception in thread "main" java.lang.NoSuchMethodError: spray.json.StandardFormats$class.optionFormat(Lspray/json/StandardFormats;Lspray/json/JsonFormat;)Lspray/json/StandardFormats$OptionFormat;
at net.nikore.etcd.EtcdJsonProtocol$.optionFormat(EtcdJsonProtocol.scala:5)
at net.nikore.etcd.EtcdJsonProtocol$.<init>(EtcdJsonProtocol.scala:18)
at net.nikore.etcd.EtcdJsonProtocol$.<clinit>(EtcdJsonProtocol.scala)
at net.nikore.etcd.EtcdClient.<init>(EtcdClient.scala:76)
at net.nikore.etcd.EtcdClient$.apply(EtcdClient.scala:20)
at au.com.someproject.helpers.SomeProjectService$class.main(SomeProjectService.scala:116)
at au.com.someproject.some_agent.ServiceMain$.main(ServiceMain.scala:17)
at au.com.someproject.some_agent.ServiceMain.main(ServiceMain.scala)
The only thing that I call tell that might be causing this is that the ETCD Client requires spray-json 1.3.1 but the Fleet Client requires spray-json 1.3.2. Having a look at the compiled package, spray-json 1.3.2 is packaged.
What is the cause of this (if I am wrong about the dependencies) and how can I go about resolving this?
EDIT:
Bellow is the code at SomeProjectService.scala:116:
etcdClient = EtcdClient(s"http://${serviceConfiguration.getString("someproject.etcd.host")}:${serviceConfiguration.getString("someproject.etcd.port")}")
And bellow is the code at ServiceMain.scala:17:
object ServiceMain extends SomeProjectService {
ServiceMain is the entry point for the service but the main function is declared in the SomeProjectService trait where the etcdClient is declared

Play 2.5.3: Cryptic error message: Exception caught in Netty java.lang.NoClassDefFoundError

[error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$
at
I get error message and my app doesn't start in dev mode.
The error doesn't give me any details about what went wrong. I changed log level in logback.xml to DEBUG, but it didn't help.
Any suggestions how to investigate the problem? A week ago it worked just fine and since then there was no any changes in sources and configuration. It stopped working for an unknown reason.
Edit1: How do I enable more verbose logging? Otherwise it's absolutely unclear where the error comes from.
Edit2: changed the title
(Server started, use Ctrl+D to stop and go back to the console...)
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using no
de.js.
[error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$
at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:45)
at play.core.server.Server$class.getHandlerFor(Server.scala:65)
at play.core.server.NettyServer.getHandlerFor(NettyServer.scala:47)
at play.core.server.netty.PlayRequestHandler.handle(PlayRequestHandler.scala:82)
at play.core.server.netty.PlayRequestHandler.channelRead(PlayRequestHandler.scala:163)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)
at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
[error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$
at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:45)
at play.core.server.Server$class.getHandlerFor(Server.scala:65)
at play.core.server.NettyServer.getHandlerFor(NettyServer.scala:47)
at play.core.server.netty.PlayRequestHandler.handle(PlayRequestHandler.scala:82)
at play.core.server.netty.PlayRequestHandler.channelRead(PlayRequestHandler.scala:163)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)
at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
I don't know exactly what your problem is, but I encountered this cryptic, unhelpful error when I discovered an error in my application.conf where I was attempting to set a configuration based on an environment variable that may or may not be there. Clearly, the cause of the exception and the place it becomes apparent are pretty far apart.
So I would suggest checking your application.conf for a misconfiguration. Consider also any dependencies that might have been built for Play versions < 2.5. Basically anything that might cause the application to be "mis-initalized" for lack of a better term.
EDIT: I just discovered another cause of this error that falls under the category of "mis-initialization." I changed the name of a route in my routes file but forgot to change the corresponding reverse route in my template. I feel this should be caught sooner and with a more intuitive error, but regardless, look out for this (or something similar) as well in application.conf or routes.
Oops.. java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$ tells nothing what went wrong.
One such reason I have encountered is when I had missing/typos in my configuration properties and use guice injectors.
You can run your app in prod mode to see more informative error message activator clean compile start.
....
[info] Done packaging.
(Starting server. Type Ctrl+D to exit logs, the server will remain in background)
Oops, cannot start the server.
Configuration error: Configuration error[storage.conf # file:/myproject/mymodule/target/universal/stage/conf/storage.conf: 16: Could not resolve substitution to a value: ${storage.cluster.name}]
at play.api.Configuration$.configError(Configuration.scala:154)
....
In my case the below dependency was what was causing the error
libraryDependencies += "com.google.cloud" % "gcloud-java-storage" % "0.2.5"
Source Getting ChannelException when adding Google cloud client library to Play 2.5
In my case it was a missed } in the application.conf file :( .

NoClassDefFoundError when using instrumentation on Bluemix

I am trying to add a javaagent to my bluemix app, this agent uses Instrumentation. The thing is that when I run the application I get the following error:
premain() - Instrumentation is already running
...
CWWKF0004E: An unknown exception occurred while installing or removing features. Exception: java.lang.NoClassDefFoundError: agent.ClassInstrumentorTransform
ERR at com.ibm.ws.kernel.feature.internal.subsystem.SubsystemFeatureDefinitionImpl.setHeader(SubsystemFeatureDefinitionImpl.java)
ERR at [internal classes]
I have tried creating another agent with the same Premain-Class and Agent-Class structure but with my own classes and it works, I have tried uploading my own copy of Instrumentation classes and point the javaagent to it using Class-Path but the error still appears.
Any sugestion what can be the problem?
I suspect maybe the Bluemix enviorment uses the Instrumentation, any ideas how this might be checked and how I can solve the inter dependency?
Based on the error message, it looks like you have a class in a feature bundle that is trying to access a class from the javaagent, but you have not added the javaagent package to org.osgi.framework.bootdelegation as described in the Specifying Liberty profile bootstrap properties" topic in the knowledge center topic.

Powermock and problem loading jar file file during unit test with JUnit 4 in eclipse

I am using powermock 1.2.5 to perform a class that saves data into Oracle database. When I run my test my unit test fails with the following exception:
NoSuchAlgorithmException : DES Algorithm can be found.
After debugging the code I found out that this exception is thrown when my application is trying to set the password to establish a database connection.
Some of my observations are:
If I run my unit test without power mock , then the exception does not occur.
I manage to run the unit test if I manually include the sun-jce.jar file into the unit test bootstrap in eclipse.sun-jce.jar is one of the jar file within jre library folder. I am using SUN java jre version 1.5.0_10
So I am guessing that somehow power mock unloads this particular jar file during unit test runtime. Does any one encounter similiar problem when using powermock ?
A work around that I am thinking at the moment is to load the jar file programmatically under the setup() of my unit test.
Manage to resove this problem. It seems PowerMock loads its own crypto library. So if we add ignore the javax.crypto when we run power mock: #PowerMockIgnore({"javax.crypto" }), the test will work.