如何使用mockrunner设置模拟队列来测试xml过滤器?

时间:2022-10-27 17:14:59

I'm using the mockrunner package from http://mockrunner.sourceforge.net/ to set up a mock queue for JUnit testing an XML filter which operates like this:

我正在使用来自http://mockrunner.sourceforge.net/的mockrunner包来为JUnit设置一个模拟队列来测试XML过滤器,其运行方式如下:

  1. sets recognized properties for an ftp server to put and get xml input and a jms queue server that keeps track of jobs. Remotely there waits a server that actually parses the xml once a queue message is received.
  2. 设置用于放置和获取xml输入的ftp服务器的已识别属性以及用于跟踪作业的jms队列服务器。远程等待服务器在收到队列消息后实际解析xml。

  3. creates a remote directory using ftp and starts a queue connection using mqconnectionfactory to the given address of the queue server.
  4. 使用ftp创建远程目录,并使用mqconnectionfactory启动队列连接到队列服务器的给定地址。

  5. once the new queue entry is made in 2), the filter waits for a new queue message to appear signifying the job has been completed by the remote server. The filter then grabs the modified xml file from the ftp and passes it along to the next filter.
  6. 一旦在2)中创建新队列条目,过滤器将等待出现新的队列消息,表示远程服务器已完成作业。然后,过滤器从ftp中获取修改后的xml文件,并将其传递给下一个过滤器。

The JUnit test I am working on simply needs to emulate this environment by starting a local ftp and mock queue server for the filter to connect to, then waiting for the filter to connect to the queue and put the new xml input file on a local directory via a local ftp server, wait for the queue message and then modify the xml input slightly, put the modified xml in a new directory and post another message to the queue signifying the job has completed.

我正在处理的JUnit测试只需要通过启动本地ftp和模拟队列服务器来连接到过滤器来模拟这个环境,然后等待过滤器连接到队列并将新的xml输入文件放在本地目录中通过本地ftp服务器,等待队列消息,然后稍微修改xml输入,将修改后的xml放入新目录,并将另一条消息发送到队列,表示作业已完成。

All of the tutorials I have found on the net have used EJB and JNDI to lookup the queue server once it has been made. If possible, I'd like to sidestep that route by just creating a mock queue on my local machine and connecting to it in the simplest manner possible, not using EJB and JNDI.

我在网上找到的所有教程都使用EJB和JNDI来查找队列服务器。如果可能的话,我想通过在我的本地机器上创建一个模拟队列并以最简单的方式连接到它来避开该路由,而不是使用EJB和JNDI。

Thanks in advance!

提前致谢!

2 个解决方案

#1


3  

I'm using MockEjb and there are some examples among them one for using mock queues, so take a look to the info and to the example Hopefully it helps.

我正在使用MockEjb,其中有一些例子用于使用模拟队列,所以看看信息和示例希望它有所帮助。

#2


2  

I'd recommend having a look at using Apache Camel to create your test case. Then its really easy to switch your test case from any of the available components and most importantly Camel comes with some really handy Mock Endpoints which makes it super easy to test complex routing logic particularly with asynchronous operations.

我建议看一下使用Apache Camel来创建测试用例。然后很容易从任何可用组件切换测试用例,最重要的是Camel带有一些非常方便的Mock端点,这使得测试复杂的路由逻辑非常容易,尤其是异步操作。

If you also use Spring, then maybe start by trying out these Spring unit tests with mock endpoints in Camel which let you inject the mock endpoints to perform assertions on together with the ProducerTemplate object to make it really easy to fire your messages for your test case. e.g. see the last example on that page.

如果您也使用Spring,那么可以首先尝试使用Camel中的模拟端点进行这些Spring单元测试,它允许您注入模拟端点以与ProducerTemplate对象一起执行断言,以便为您的测试用例发送消息非常容易。例如请参阅该页面上的最后一个示例。

Start off using simple endpoints like the SEDA endpoint - then when you've got your head around the core spring/mock framework, try using the JMS endpoint or FTP endpoint endpoints etc.

开始使用像SEDA端点这样的简单端点 - 然后当你了解核心spring / mock框架时,尝试使用JMS端点或FTP端点端点等。

#1


3  

I'm using MockEjb and there are some examples among them one for using mock queues, so take a look to the info and to the example Hopefully it helps.

我正在使用MockEjb,其中有一些例子用于使用模拟队列,所以看看信息和示例希望它有所帮助。

#2


2  

I'd recommend having a look at using Apache Camel to create your test case. Then its really easy to switch your test case from any of the available components and most importantly Camel comes with some really handy Mock Endpoints which makes it super easy to test complex routing logic particularly with asynchronous operations.

我建议看一下使用Apache Camel来创建测试用例。然后很容易从任何可用组件切换测试用例,最重要的是Camel带有一些非常方便的Mock端点,这使得测试复杂的路由逻辑非常容易,尤其是异步操作。

If you also use Spring, then maybe start by trying out these Spring unit tests with mock endpoints in Camel which let you inject the mock endpoints to perform assertions on together with the ProducerTemplate object to make it really easy to fire your messages for your test case. e.g. see the last example on that page.

如果您也使用Spring,那么可以首先尝试使用Camel中的模拟端点进行这些Spring单元测试,它允许您注入模拟端点以与ProducerTemplate对象一起执行断言,以便为您的测试用例发送消息非常容易。例如请参阅该页面上的最后一个示例。

Start off using simple endpoints like the SEDA endpoint - then when you've got your head around the core spring/mock framework, try using the JMS endpoint or FTP endpoint endpoints etc.

开始使用像SEDA端点这样的简单端点 - 然后当你了解核心spring / mock框架时,尝试使用JMS端点或FTP端点端点等。