Search in sources :

Example 11 with EncodingException

use of io.joynr.smrf.EncodingException in project joynr by bmwcarit.

the class MessagingServiceResponseMatchers method containsPayload.

public static Matcher<List<ImmutableMessage>> containsPayload(final String payload) {
    return new BaseMatcher<List<ImmutableMessage>>() {

        @Override
        public boolean matches(Object item) {
            @SuppressWarnings("unchecked") List<ImmutableMessage> messages = (List<ImmutableMessage>) item;
            byte[] binaryPayload = payload.getBytes(Charsets.UTF_8);
            for (ImmutableMessage message : messages) {
                try {
                    if (Arrays.equals(message.getUnencryptedBody(), binaryPayload)) {
                        return true;
                    }
                } catch (EncodingException e) {
                    e.printStackTrace();
                    return false;
                }
            }
            return false;
        }

        @Override
        public void describeTo(Description arg0) {
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) EncodingException(io.joynr.smrf.EncodingException) ImmutableMessage(joynr.ImmutableMessage) List(java.util.List)

Aggregations

EncodingException (io.joynr.smrf.EncodingException)11 ImmutableMessage (joynr.ImmutableMessage)9 UnsuppportedVersionException (io.joynr.smrf.UnsuppportedVersionException)8 IOException (java.io.IOException)5 URI (java.net.URI)4 POST (javax.ws.rs.POST)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 JoynrHttpException (io.joynr.communications.exceptions.JoynrHttpException)3 Produces (javax.ws.rs.Produces)3 Consumes (javax.ws.rs.Consumes)2 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)2 OneWayRequest (joynr.OneWayRequest)2 Request (joynr.Request)2 SubscriptionRequest (joynr.SubscriptionRequest)2 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Path (javax.ws.rs.Path)1