Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyanli-amazon committed Mar 2, 2023
1 parent 1af6bd6 commit 7bf4611
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import jakarta.jms.JMSException;

import jakarta.jms.JMSRuntimeException;
import org.junit.jupiter.api.Test;

import com.amazonaws.regions.Regions;
Expand All @@ -24,6 +25,7 @@

import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

public class SQSConnectionFactoryTest {
Expand Down Expand Up @@ -85,4 +87,18 @@ public void factoryWithCustomBuilderWillCreateNewClient() throws JMSException {
connection1.close();
connection2.close();
}

// Test unsupported methods
@Test
public void testUnsupportedFeature() {
SQSConnectionFactory factory = SQSConnectionFactory.builder().build();
assertThrows(JMSRuntimeException.class, factory::createContext,
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
assertThrows(JMSRuntimeException.class, () -> factory.createContext("userName", "password"),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
assertThrows(JMSRuntimeException.class, () -> factory.createContext("userName", "password", 2),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
assertThrows(JMSRuntimeException.class, () -> factory.createContext(1),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
}
}
10 changes: 10 additions & 0 deletions src/test/java/com/amazon/sqs/javamessaging/SQSConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ public void testCreateSessionWhenClosing() {
// Start connection
assertThrows(IllegalStateException.class, () -> sqsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE),
"Connection is closed or closing");
assertThrows(IllegalStateException.class, () -> sqsConnection.createSession(Session.AUTO_ACKNOWLEDGE),
"Connection is closed or closing");

// Verify results
assertEquals(2, sqsConnection.getSessions().size());
Expand All @@ -602,6 +604,14 @@ public void testCreateSessionUnknownAckMode() {
assertEquals(2, sqsConnection.getSessions().size());
}

/**
* Test create session must parse in a parameter
*/
@Test
public void testCreateSessionWithNoParseInValue() {
assertThrows(JMSException.class, () -> sqsConnection.createSession(), "Unsupported Method");
}

/**
* Test create session when connection running
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.amazonaws.services.sqs.model.SendMessageResult;
import com.amazonaws.util.Base64;
import jakarta.jms.CompletionListener;
import jakarta.jms.Destination;
import jakarta.jms.IllegalStateException;
import jakarta.jms.InvalidDestinationException;
Expand All @@ -47,8 +48,8 @@
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doNothing;
Expand Down Expand Up @@ -639,8 +640,7 @@ public void testSetDeliveryDelay() throws JMSException {

assertEquals(2, requestCaptor.getValue().getDelaySeconds().intValue());
}



@Test
public void testSetDeliveryDelayInvalidDelays() {
assertThrows(IllegalArgumentException.class, () -> producer.setDeliveryDelay(-1));
Expand All @@ -650,8 +650,24 @@ public void testSetDeliveryDelayInvalidDelays() {

assertThrows(IllegalArgumentException.class, () -> producer.setDeliveryDelay(20));
}



// Test unsupported methods
@Test
public void testUnsupportedFeature() {
Message message = mock(Message.class);
CompletionListener listener = mock(CompletionListener.class);
Destination msgDestination = mock(Destination.class);

assertThrows(JMSException.class, () -> producer.send(message, listener),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
assertThrows(JMSException.class, () -> producer.send(message, 1, 1, 100L, listener),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
assertThrows(JMSException.class, () -> producer.send(msgDestination, message, listener),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
assertThrows(JMSException.class, () -> producer.send(destination, message, 0, 0, 20L, listener),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
}

private Map<String, MessageAttributeValue> createMessageAttribute(String type) {
MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
messageAttributeValue.setDataType("String");
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/amazon/sqs/javamessaging/SQSSessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,25 @@ public void testUnsupportedFeature() throws JMSException {

assertThrows(JMSException.class, () -> sqsSession.createMapMessage(),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);

assertThrows(JMSException.class, () -> sqsSession.createSharedConsumer(null, "name"),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);

assertThrows(JMSException.class, () -> sqsSession.createSharedConsumer(null, "name", "messageSelector"),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);

assertThrows(JMSException.class, () -> sqsSession.createDurableConsumer(null, "name"),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);

assertThrows(JMSException.class, () ->
sqsSession.createDurableConsumer(null, "name", "messageSelector", true),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);

assertThrows(JMSException.class, () -> sqsSession.createSharedDurableConsumer(null, "name"),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);

assertThrows(JMSException.class, () -> sqsSession.createSharedDurableConsumer(null, "name", "messageSelector"),
SQSMessagingClientConstants.UNSUPPORTED_METHOD);
}

/**
Expand Down

0 comments on commit 7bf4611

Please sign in to comment.