2

I am using a MockWebServiceServer to test the REST APIs. I am passing the values to it using @Runwith(Parameterized.class).

   @RunWith(Parameterized.class)
   public class MyAPITest {

        protected static MockWebServiceServer mockServer;
        private Message message;

        public MyAPITest(Message messageIn) {
            this.message = messageIn;
        }

        @BeforeClass
        public static void setup(){
            mockServer = MockWebServiceServer.createServer(applicationContext);
        }

        @Test
        public final void testMethod() throws Throwable {
            Source reqPayload1 = new StringSource("...");
            Source reqPayload2 = new StringSource("...");
            Source resPayload1 = new StringSource("...");
            Source resPayload2 = new StringSource("...");
            mockServer.expect(RequestMatchers.payload(reqPayload1 )).andRespond(ResponseCreators.withPayload(resPayload1 ));
            //Unable to add below line as it throws exception. Unable to set multiple expectation
            //mockServer.expect(RequestMatchers.payload(reqPayload2 )).andRespond(ResponseCreators.withPayload(resPayload2 ));
            myClass.onMessage(this.message);
            mockServer.verify();
        }

        @Parameters
        public static Collection<Object[]> getParameters() {
            //Read input data from file
        }
    }

Code works fine when I've only 1 input.

But it throws exception when I've more than one input.

java.lang.IllegalStateException: Can not expect another connection, the test is already underway
    at org.springframework.util.Assert.state(Assert.java:385)
    at org.springframework.ws.test.client.MockWebServiceMessageSender.expectNewConnection(MockWebServiceMessageSender.java:64)
    at org.springframework.ws.test.client.MockWebServiceServer.expect(MockWebServiceServer.java:162)
    at com.rakuten.gep.newsletter.batch.ExacttargetMQJobTest.testOnMessage(ExacttargetMQJobTest.java:82)

I'm using Spring 3.2. I want to test my api with multiple inputs.

rupesh
  • 413
  • 9
  • 19

0 Answers0