1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jitr;
18
19
20 import org.apache.commons.httpclient.HttpClient;
21 import org.apache.commons.httpclient.HttpMethod;
22 import org.apache.commons.httpclient.methods.GetMethod;
23 import org.jitr.annotation.BaseUri;
24 import org.jitr.annotation.JitrConfiguration;
25 import org.jitr.annotation.Port;
26 import org.jitr.test.service.TestService;
27 import org.junit.After;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.springframework.beans.factory.annotation.Autowired;
33
34 @RunWith(Jitr.class)
35 @JitrConfiguration(contextPath = "/example")
36 public class ExampleTest {
37
38 private static final String TEST_STRING = "TEST_STRING";
39
40 @Port
41 private int port;
42
43 @BaseUri
44 private String baseUri;
45
46 @Autowired
47 private TestService testService;
48
49 private HttpClient httpClient;
50
51 private HttpMethod method;
52
53 @After
54 public void after() {
55 if (method != null) {
56 method.releaseConnection();
57 }
58 }
59
60 @Before
61 public void before() {
62
63 httpClient = new HttpClient();
64
65
66 Assert.assertNotNull(testService);
67
68
69 Assert.assertNotSame(-1, port);
70 Assert.assertNotSame(8080, port);
71
72 Assert.assertNotNull(baseUri);
73 Assert.assertTrue(baseUri.length() > 0);
74 Assert.assertTrue(baseUri.contains("http://localhost:" + port + "/example"));
75 }
76
77 @Test
78 public void testServerGet() throws Exception {
79
80
81 testService.setString(TEST_STRING);
82
83
84 Assert.assertEquals(TEST_STRING, testService.getString());
85
86
87 method = new GetMethod(baseUri + "/string");
88 httpClient.executeMethod(method);
89
90
91 Assert.assertEquals(TEST_STRING, method.getResponseBodyAsString());
92 }
93 }
94