Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Experimental JMS testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Stockinger committed Sep 11, 2017
1 parent 81e4043 commit de1220a
Show file tree
Hide file tree
Showing 30 changed files with 2,703 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -2,6 +2,7 @@ Version 0.6.0
- Hibernate support
- Custom params for @TestData methods can be contributed via TestDataSetupAccessorFactories now
- Using JUnit 5 final now
- Experimental JMS testing

Version 0.5.3
- Fixed issue with globally enabled interceptors and mocks
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/fi/testee/deployment/BeanArchive.java
Expand Up @@ -17,6 +17,7 @@

import fi.testee.classpath.JavaArchive;

import javax.ejb.MessageDriven;
import javax.ejb.Singleton;
import javax.ejb.Stateful;
import javax.ejb.Stateless;
Expand All @@ -26,6 +27,13 @@
import java.util.stream.Collectors;

public class BeanArchive {
public static final Class[] EJB_ANNOTATIONS = {
Singleton.class,
Stateless.class,
Stateful.class,
Entity.class,
MessageDriven.class
};
private final JavaArchive classpathEntry;
private final Collection<Class<? extends Annotation>> qualifyingAnnotations;
private Collection<EjbDescriptorImpl<?>> ejbs;
Expand Down Expand Up @@ -58,7 +66,7 @@ public synchronized Collection<EjbDescriptorImpl<?>> getEjbs() {
}

private boolean isEjbArchive() {
return !classpathEntry.annotatedWith(Singleton.class, Stateless.class, Stateful.class, Entity.class).isEmpty();
return !classpathEntry.annotatedWith(EJB_ANNOTATIONS).isEmpty();
}

public JavaArchive getClasspathEntry() {
Expand Down
Expand Up @@ -74,10 +74,10 @@ private static Object findResource(
.filter(Objects::nonNull)
.collect(toSet());
if (candidates.isEmpty()) {
throw new IllegalStateException("Failed to resolve resource specification " + resolver);
throw new IllegalStateException("Failed to resolve resource " + resolver);
}
if (candidates.size() > 1) {
throw new IllegalStateException("Ambiguous resource specification" + resolver + ": " + candidates);
throw new IllegalStateException("Ambiguous resource " + resolver + ": " + candidates);
}
return candidates.iterator().next();
}
Expand Down
13 changes: 13 additions & 0 deletions jms/build.gradle
@@ -0,0 +1,13 @@
apply plugin: 'java'

dependencies {
compile libWeld
compile libJavaEE
compile libSlf4j
compile project(":common")
compile project(":core-spi")

testCompile libJUnit4
testCompile libLogback
testCompile project(":core")
}
297 changes: 297 additions & 0 deletions jms/src/main/java/fi/testee/jms/AbstractMessageImpl.java
@@ -0,0 +1,297 @@
/*
* Copyright (C) 2017 Alex Stockinger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fi.testee.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public class AbstractMessageImpl implements Message {
private final Map<String, Object> props = new HashMap<>();

private String id;
private long timestamp;
private byte[] correlationId;
private Destination destination;
private Destination replyTo;
private int deliveryMode;
private boolean redelivered;
private String type;
private long expiration;
private long deliveryTime;
private int priority;

@Override
public String getJMSMessageID() throws JMSException {
return id;
}

@Override
public void setJMSMessageID(final String id) throws JMSException {
this.id = id;
}

@Override
public long getJMSTimestamp() throws JMSException {
return timestamp;
}

@Override
public void setJMSTimestamp(long timestamp) throws JMSException {
this.timestamp = timestamp;
}

@Override
public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
return correlationId;
}

@Override
public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException {
this.correlationId = correlationID;
}

@Override
public void setJMSCorrelationID(String correlationID) throws JMSException {
try {
correlationId = correlationID.getBytes("iso-8859-1");
} catch (UnsupportedEncodingException e) {
final JMSException jmsException = new JMSException("Failed to get bytes from correlationID string");
jmsException.setLinkedException(e);
throw jmsException;
}
}

@Override
public String getJMSCorrelationID() throws JMSException {
try {
return new String(correlationId, "iso-8859-1");
} catch (UnsupportedEncodingException e) {
final JMSException jmsException = new JMSException("Failed to get string from correlationID bytes");
jmsException.setLinkedException(e);
throw jmsException;
}
}

@Override
public Destination getJMSReplyTo() throws JMSException {
return replyTo;
}

@Override
public void setJMSReplyTo(Destination replyTo) throws JMSException {
this.replyTo = replyTo;
}

@Override
public Destination getJMSDestination() throws JMSException {
return destination;
}

@Override
public void setJMSDestination(Destination destination) throws JMSException {
this.destination = destination;
}

@Override
public int getJMSDeliveryMode() throws JMSException {
return deliveryMode;
}

@Override
public void setJMSDeliveryMode(int deliveryMode) throws JMSException {
this.deliveryMode = deliveryMode;
}

@Override
public boolean getJMSRedelivered() throws JMSException {
return redelivered;
}

@Override
public void setJMSRedelivered(boolean redelivered) throws JMSException {
this.redelivered = redelivered;
}

@Override
public String getJMSType() throws JMSException {
return type;
}

@Override
public void setJMSType(String type) throws JMSException {
this.type = type;
}

@Override
public long getJMSExpiration() throws JMSException {
return expiration;
}

@Override
public void setJMSExpiration(long expiration) throws JMSException {
this.expiration = expiration;
}

@Override
public long getJMSDeliveryTime() throws JMSException {
return deliveryTime;
}

@Override
public void setJMSDeliveryTime(long deliveryTime) throws JMSException {
this.deliveryTime = deliveryTime;
}

@Override
public int getJMSPriority() throws JMSException {
return priority;
}

@Override
public void setJMSPriority(int priority) throws JMSException {
this.priority = priority;
}

@Override
public void clearProperties() throws JMSException {

}

@Override
public boolean propertyExists(String name) throws JMSException {
return props.containsKey(name);
}

@Override
public boolean getBooleanProperty(String name) throws JMSException {
return false;
}

@Override
public byte getByteProperty(String name) throws JMSException {
return 0;
}

@Override
public short getShortProperty(String name) throws JMSException {
return 0;
}

@Override
public int getIntProperty(String name) throws JMSException {
return 0;
}

@Override
public long getLongProperty(String name) throws JMSException {
return 0;
}

@Override
public float getFloatProperty(String name) throws JMSException {
return 0;
}

@Override
public double getDoubleProperty(String name) throws JMSException {
return 0;
}

@Override
public String getStringProperty(String name) throws JMSException {
return null;
}

@Override
public Object getObjectProperty(String name) throws JMSException {
return null;
}

@Override
public Enumeration getPropertyNames() throws JMSException {
return null;
}

@Override
public void setBooleanProperty(String name, boolean value) throws JMSException {

}

@Override
public void setByteProperty(String name, byte value) throws JMSException {

}

@Override
public void setShortProperty(String name, short value) throws JMSException {

}

@Override
public void setIntProperty(String name, int value) throws JMSException {

}

@Override
public void setLongProperty(String name, long value) throws JMSException {

}

@Override
public void setFloatProperty(String name, float value) throws JMSException {

}

@Override
public void setDoubleProperty(String name, double value) throws JMSException {

}

@Override
public void setStringProperty(String name, String value) throws JMSException {

}

@Override
public void setObjectProperty(String name, Object value) throws JMSException {

}

@Override
public void acknowledge() throws JMSException {

}

@Override
public void clearBody() throws JMSException {

}

@Override
public <T> T getBody(Class<T> c) throws JMSException {
return null;
}

@Override
public boolean isBodyAssignableTo(Class c) throws JMSException {
return false;
}
}

0 comments on commit de1220a

Please sign in to comment.