-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests for JmsPut and JmsGet #237
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Added tests for JmsPut and JmsGet
- Loading branch information
commit 541dea6bba69ab0c433c5ce04bc7bdba46794eff
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* (c) Copyright IBM Corporation 2024 | ||
* | ||
* 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 com.ibm.mq.samples.jms; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Enumeration; | ||
|
||
import javax.jms.JMSContext; | ||
import javax.jms.JMSException; | ||
import javax.jms.Queue; | ||
import javax.jms.QueueBrowser; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class JmsGetTest { | ||
private JMSContext context = null; | ||
private Queue destination = null; | ||
private QueueBrowser browser = null; | ||
private ConnectionHelper ch = null; | ||
@Test | ||
public void testJmsGet(){ | ||
JmsPut.main(null); | ||
JmsGet.main(null); | ||
|
||
ch = new ConnectionHelper("Basic Get", 0); | ||
context = ch.getContext(); | ||
destination = (Queue)ch.getDestination(); | ||
browser = context.createBrowser(destination); | ||
try { | ||
Enumeration<?> messages = browser.getEnumeration(); | ||
assertFalse(messages.hasMoreElements()); | ||
} catch (JMSException jmsex) { | ||
chughts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
jmsex.printStackTrace(); | ||
} | ||
ch.closeContext();; | ||
} | ||
|
||
} |
131 changes: 131 additions & 0 deletions
131
JMS/src/test/java/com/ibm/mq/samples/jms/JmsPutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* (c) Copyright IBM Corporation 2024 | ||
* | ||
* 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 com.ibm.mq.samples.jms; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import javax.jms.JMSConsumer; | ||
import javax.jms.JMSContext; | ||
import javax.jms.JMSException; | ||
import javax.jms.Destination; | ||
import javax.jms.Message; | ||
import javax.jms.TextMessage; | ||
import javax.jms.JMSRuntimeException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.ibm.mq.MQException; | ||
import com.ibm.mq.constants.MQConstants; | ||
|
||
|
||
public class JmsPutTest { | ||
private JMSContext context = null; | ||
private Destination destination = null; | ||
private JMSConsumer consumer = null; | ||
private ConnectionHelper ch = null; | ||
private static long TIMEOUTTIME = 5000; | ||
@Test | ||
public void testJmsPut(){ | ||
clearQueue(); | ||
chughts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
JmsPut.main(null); | ||
|
||
ch = new ConnectionHelper("Basic Get", 0); | ||
context = ch.getContext(); | ||
destination = ch.getDestination(); | ||
consumer = context.createConsumer(destination); | ||
for(int i = 1 ; i <= 10 ; i++){ | ||
try { | ||
Message recievedMessage = consumer.receive(TIMEOUTTIME); | ||
String value = "This is message number " + i + "."; | ||
String message = getMessageBody(recievedMessage); | ||
assertEquals(value, message); | ||
waitAWhile(1000); | ||
} catch (JMSRuntimeException jmsex) { | ||
jmsex.printStackTrace(); | ||
waitAWhile(1000); | ||
} | ||
} | ||
ch.closeContext(); | ||
} | ||
|
||
|
||
@Test | ||
public void testIncorrectQM(){ | ||
System.setProperty("QMGR", "INVALID_QM"); | ||
JMSRuntimeException jmsex = assertThrows(JMSRuntimeException.class , () -> { | ||
JmsPut.main(null); | ||
}); | ||
|
||
MQException inException = (MQException) jmsex.getCause(); | ||
assertEquals(MQConstants.MQRC_Q_MGR_NAME_ERROR, inException.getReason()); | ||
System.clearProperty("QMGR"); | ||
} | ||
|
||
@Test | ||
public void testIncorrectQueue(){ | ||
System.setProperty("QUEUE_NAME" , "INVALID_QUEUE"); | ||
JMSRuntimeException jmsex = assertThrows(JMSRuntimeException.class, () -> { | ||
JmsPut.main(null); | ||
}); | ||
|
||
MQException inException = (MQException) jmsex.getCause(); | ||
assertEquals(MQConstants.MQRC_UNKNOWN_OBJECT_NAME, inException.getReason()); | ||
System.clearProperty("QUEUE_NAME"); | ||
} | ||
|
||
@Test | ||
public void testIncorrectChannel(){ | ||
System.setProperty("CHANNEL" , "INCORRECT_CHANNEL"); | ||
JMSRuntimeException jmsex = assertThrows(JMSRuntimeException.class, () -> { | ||
JmsPut.main(null); | ||
}); | ||
MQException inException = (MQException) jmsex.getCause(); | ||
assertEquals(MQConstants.MQRC_UNKNOWN_CHANNEL_NAME, inException.getReason()); | ||
System.clearProperty("CHANNEL"); | ||
} | ||
|
||
|
||
private void clearQueue(){ | ||
BasicConsumer bc = new BasicConsumer(BasicConsumer.CONSUMER_GET, 0); | ||
bc.receive(1000); | ||
bc.close(); | ||
} | ||
|
||
private static String getMessageBody(Message receivedMessage) { | ||
if (receivedMessage instanceof TextMessage) { | ||
TextMessage textMessage = (TextMessage) receivedMessage; | ||
try { | ||
return textMessage.getText(); | ||
} catch (JMSException jmsex) { | ||
return "Error getting a message"; | ||
} | ||
} else if (receivedMessage instanceof Message) { | ||
return "Message received was not of type TextMessage."; | ||
} else { | ||
return "Received object not of JMS Message type!"; | ||
} | ||
} | ||
|
||
private static void waitAWhile(int duration) { | ||
try { | ||
Thread.sleep(duration); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atleast
- typo.