1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jitr;
18
19 import javax.ws.rs.core.MediaType;
20
21 import org.apache.commons.httpclient.HttpClient;
22 import org.apache.commons.httpclient.methods.PostMethod;
23 import org.apache.commons.httpclient.methods.PutMethod;
24 import org.apache.commons.httpclient.methods.StringRequestEntity;
25 import org.jitr.Jitr;
26 import org.jitr.annotation.JitrConfiguration;
27 import org.jitr.core.OperationalMode;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.runner.RunWith;
31 import org.springframework.test.context.ContextConfiguration;
32 import org.springframework.test.context.support.GenericXmlContextLoader;
33
34 @RunWith(Jitr.class)
35 @JitrConfiguration(mode = OperationalMode.MIXED)
36 @ContextConfiguration(locations = { "/META-INF/spring/test-beans.xml" }, loader = GenericXmlContextLoader.class)
37 public class JitrTestWithExternalSpring extends JitrTestBase {
38
39 private static final String EXTERNAL_TEST_STRING = "EXTERNAL_TEST_STRING";
40
41
42
43
44
45 @Before
46 public void before() throws Exception {
47
48 final HttpClient httpClient = new HttpClient();
49
50 final PostMethod postMethod = new PostMethod(baseUri + "string/echo");
51 postMethod.setRequestEntity(new StringRequestEntity(EXTERNAL_TEST_STRING,
52 MediaType.TEXT_PLAIN, "UTF-8"));
53
54 int statusCode = httpClient.executeMethod(postMethod);
55 Assert.assertEquals(200, statusCode);
56
57 String responseString = getInputStreamAsString(postMethod.getResponseBodyAsStream());
58 Assert.assertEquals(EXTERNAL_TEST_STRING, responseString);
59
60 final PutMethod putMethod = new PutMethod(baseUri + "string");
61 putMethod.setRequestEntity(new StringRequestEntity(EXTERNAL_TEST_STRING,
62 MediaType.TEXT_PLAIN, "UTF-8"));
63
64 statusCode = httpClient.executeMethod(putMethod);
65 Assert.assertEquals(200, statusCode);
66
67 putMethod.releaseConnection();
68 }
69
70 @Override
71 protected String getRemoteTestString() {
72 return EXTERNAL_TEST_STRING;
73 }
74 }