hamcrest 1.3 hasItems fails test when comparing identical lists - junit4

The following line fails when trying to compare 2 lists:
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
assertThat(
actualDealSummary.getDeals(),
hasItems(expectedDealSummary.getDeals().toArray(new Deal[expectedDealSummary.getDeals().size()])));
Using JUnit 4.11, and hamcrest-all (1.3):
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
I just want to check that the actual list has the expected list's values, but I get the following error:
java.lang.AssertionError:
Expected: (a collection containing &LT;SIXRxrImUE&GT; and a collection containing &LT;RQjVbVRlyG&GT; and a collection containing &LT;avnKxogdyN&GT;)
but: a collection containing &LT;SIXRxrImUE&GT; was &LT;SIXRxrImUE&GT;, was &LT;RQjVbVRlyG&GT;, was &LT;avnKxogdyN&GT;
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)
at
How can I use hamcrest's built in Matchers to compare 2 lists of pojos?

Your Deal class will need to implement equals for this to work. You may find it simpler to check for equality:
assertEquals(expectedDealSummary.getDeals(), actualDealSummary.getDeals());
Note that hasItems is performing a slightly different check to this and confirming that the actual list is a superset of the expected list; this would cause it to pass even if unexpected items were also present.

Related

Jersery #FormDataParam and FormDataContentDisposition is not working even after adding maven dependencies

I have added these 3 maven dependency. But when i try to use #FormDataParam and FormDataContentDisposition its showing red mark as it is not found. But I can see that in the multipart lib I am attaching image for reference.
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.27</version>
</dependency>
</dependencies>
Even after adding dependency in maven it was not working .. Then it showed me suggestion to fix project on the error statement,on clicking that suggestion it asked to add org.glassfish.jersey.media.multipart library to build . Then i simply selected it and ok....It started working

Drools / Java 8 compatibility

I am trying to use Drools for rules validation, and I get an error with Java 8. As per the existing suggestions, I did upgrade to eclipse compiler to 4.4 and see the corresponding ecj-4.4.jar generated in my maven dependencies. However, I am still getting the wrong class format exception:
Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException.
I tried using different versions of drools including 6.4.0.Final, 5.0.1 as well - but the issue persists.
I get this error when I try using the Stateless kie session but not with the stateful kie session.
Any thoughts?
Best Regards,
Sadhana
If you are using drools compiler dependency then change it below in pom.xml
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</exclusion>
</exclusions>
</dependency>
If you are using drools-spring dependency:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-spring</artifactId>
<version>${drools-spring-version}</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</exclusion>
</exclusions>
</dependency>
The error you are facing could be because there are multiple version of ecj jar and Java is picking the wrong one.

spring-data-redis 1.7.x and lettuce 4.1.x - java.lang.IncompatibleClassChangeError

Things work just fine when I use lettuce version 3.4.x; Looks like lettuce has changed a class contract when it updated to 4.1.x (from abstract class to an interface) and spring-data-redis 1.7.x is not aware of that. I get the following error:
BeanInstantiationException: Failed to instantiate
[org.springframework.data.redis.core.RedisKeyValueAdapter]: Constructor threw exception;
nested exception is java.lang.IncompatibleClassChangeError:
class org.springframework.data.redis.connection.lettuce.BytesRedisCodec has
interface com.lambdaworks.redis.codec.RedisCodec as super class
Not sure if Spring data redis team is working on it? Or is there a workaround or suggestion that I can use to still keep at 4.1.x version of lettuce?
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.7.0.RC1</version>
</dependency>
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>4.1.1.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<optional>true</optional>
</dependency>

"Provider not a subtype" on org.eclipse.jetty.apache.jsp.JuliLog for Embedded Jetty

When using embedded jetty and started via
mvn jetty:run
The following exception is thrown:
Exception in thread "main" java.util.ServiceConfigurationError:
org.apache.juli.logging.Log: Provider org.eclipse.jetty.apache.jsp.JuliLog not a subtype
Here is the pom.xml snippets:
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.0.v201112011016</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
<version>8.1.19.v20160209</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.19.v20160209</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.6</version>
</dependency>
Any pointers to a correctly configured embedded jetty (preferably also using websockets) appreciated.
Don't try to enable everything all at once.
Jetty is a highly modular system, you can pick and choose what you want to run. Nothing is mandatory by default, even the Server!
If you want examples of embedded jetty with websockets, consider reviewing the example projects that the Jetty project has put together at ...
https://github.com/jetty-project/embedded-websocket-echo-examples
Some advice:
Build up your requirements layer by layer
Start with basic websocket endpoint functionality (get this working first!)
then add slf4j + logback. (be sure you use an appropriate version, see the <scope>optional</scope> dependencies present in your previous layer before you choose a version of slf4j or logback). Test this like there is no tommorrow.
then add jsp support (as your error seems to indicate your desire for jsp support)

Missing dependency for method

I am running REST Web Service and after adding some new Web Services I got some errors.
Why do I get these errors?
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK) at parameter at index 0
SEVERE: Method, public entities.ProyectoHasPersona service.ProyectoHasPersonaRESTFacade.find(entities.ProyectoHasPersonaPK), annotated with GET of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.
SEVERE: Missing dependency for method public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK) at parameter at index 0
SEVERE: Method, public javax.ws.rs.core.Response service.ProyectoHasPersonaRESTFacade.remove(entities.ProyectoHasPersonaPK), annotated with DELETE of resource, class service.ProyectoHasPersonaRESTFacade, is not recognized as valid resource method.
I am using Jersey 1.1.1, these are my dependencies:
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Looks like methods service.ProyectoHasPersonaRESTFacade.find() and service.ProyectoHasPersonaRESTFacade.remove() take one parameter which is not annotated (i.e. it means the methods expect the request entity to be passed into this parameter), however, these methods are mapped to HTTP GET and DELETE. Neither HTTP GET nor HTTP DELETE can have an entity. So the unannotated parameter on the corresponding Java methods does not make sense.
You can get the ID/PK of the object to be retrieved/deleted e.g. by putting it either in a path parameter or query parameter.