-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
11 deletions.
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
81 changes: 81 additions & 0 deletions
81
...activemq-quarkus/src/test/java/webapp/tier/service/ActiveMqSubscribeServiceErrorTest.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,81 @@ | ||
package webapp.tier.service; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import javax.inject.Inject; | ||
import javax.jms.ConnectionFactory; | ||
import javax.jms.JMSContext; | ||
import javax.jms.Session; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.artemis.test.ArtemisTestResource; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusMock; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import webapp.tier.bean.MsgBean; | ||
import webapp.tier.util.CreateId; | ||
import webapp.tier.util.MsgUtils; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(ArtemisTestResource.class) | ||
class ActiveMqSubscribeServiceErrorTest { | ||
|
||
@Inject | ||
ConnectionFactory connectionFactory; | ||
|
||
@ConfigProperty(name = "common.message") | ||
String message; | ||
@ConfigProperty(name = "activemq.split.key") | ||
String splitkey; | ||
@ConfigProperty(name = "activemq.topic.name") | ||
String topicname; | ||
|
||
private static final String respbody = "Test Response OK from Mock"; | ||
|
||
private static MockDeliverService mock = null; | ||
|
||
@BeforeAll | ||
static void init() { | ||
mock = mock(MockDeliverService.class); | ||
} | ||
|
||
@BeforeEach | ||
void setup() { | ||
clearInvocations(mock); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
reset(mock); | ||
} | ||
|
||
@Test | ||
void testSubscribeError() { | ||
when(mock.random()).thenThrow(new RuntimeException("Rest response error")); | ||
QuarkusMock.installMockForType(mock, MockDeliverService.class); | ||
|
||
try { | ||
MsgBean msgbean = new MsgBean(CreateId.createid(), message, "Publish"); | ||
String body = MsgUtils.createBody(msgbean, splitkey); | ||
try (JMSContext context = connectionFactory | ||
.createContext(Session.AUTO_ACKNOWLEDGE)) { | ||
context.createProducer().send(context.createTopic(topicname), | ||
context.createTextMessage(body)); | ||
} | ||
Thread.sleep(1000); | ||
assertThat(msgbean.getFullmsg(), not(containsString(respbody))); | ||
verify(mock, atLeastOnce()).random(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
fail(); | ||
} | ||
} | ||
} |
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