Skip to content
Permalink
Browse files

Experimental JMS testing

  • Loading branch information...
Alex Stockinger
Alex Stockinger committed Sep 8, 2017
1 parent 81e4043 commit de1220a227b9551d12b3e664b3938f4ec7501580
Showing with 2,703 additions and 3 deletions.
  1. +1 −0 changelog.txt
  2. +9 −1 core/src/main/java/fi/testee/deployment/BeanArchive.java
  3. +2 −2 core/src/main/java/fi/testee/services/ResourceInjectionServicesImpl.java
  4. +13 −0 jms/build.gradle
  5. +297 −0 jms/src/main/java/fi/testee/jms/AbstractMessageImpl.java
  6. +47 −0 jms/src/main/java/fi/testee/jms/ConnectionFactoryResourceProvider.java
  7. +47 −0 jms/src/main/java/fi/testee/jms/JmsExtension.java
  8. +32 −0 jms/src/main/java/fi/testee/jms/JmsExtensionFactory.java
  9. +45 −0 jms/src/main/java/fi/testee/jms/MessageDrivenBeanRegistry.java
  10. +44 −0 jms/src/main/java/fi/testee/jms/QueueResourceProvider.java
  11. +37 −0 jms/src/main/java/fi/testee/jms/ReceivedJmsMessage.java
  12. +133 −0 jms/src/main/java/fi/testee/jms/TestEEfiConnection.java
  13. +61 −0 jms/src/main/java/fi/testee/jms/TestEEfiConnectionFactory.java
  14. +188 −0 jms/src/main/java/fi/testee/jms/TestEEfiMessageProducer.java
  15. +32 −0 jms/src/main/java/fi/testee/jms/TestEEfiQueue.java
  16. +262 −0 jms/src/main/java/fi/testee/jms/TestEEfiSession.java
  17. +32 −0 jms/src/main/java/fi/testee/jms/TestEEfiTopic.java
  18. +25 −0 jms/src/main/java/fi/testee/jms/TestQueue.java
  19. +61 −0 jms/src/main/java/fi/testee/jms/TestQueueImpl.java
  20. +46 −0 jms/src/main/java/fi/testee/jms/TestQueueResourceProvider.java
  21. +44 −0 jms/src/main/java/fi/testee/jms/TopicResourceProvider.java
  22. +899 −0 jms/src/main/java/fi/testee/jms/message/JmsMessage.java
  23. +41 −0 jms/src/main/java/fi/testee/jms/message/JmsMessagingClientConstants.java
  24. +101 −0 jms/src/main/java/fi/testee/jms/message/JmsTextMessage.java
  25. +21 −0 jms/src/main/java/fi/testee/jms/message/package-info.java
  26. 0 jms/src/main/resources/META-INF/beans.xml
  27. 0 jms/src/main/resources/META-INF/testee.fi
  28. +170 −0 jms/src/test/java/fi/testee/jms/JavaMessagingTest.java
  29. +12 −0 jms/src/test/resources/logback.xml
  30. +1 −0 settings.gradle
@@ -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
@@ -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;
@@ -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;
@@ -58,7 +66,7 @@ public BeanArchive(
}

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

public JavaArchive getClasspathEntry() {
@@ -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();
}
@@ -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")
}
@@ -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;
}
}
Oops, something went wrong.

0 comments on commit de1220a

Please sign in to comment.
You can’t perform that action at this time.