-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestClientTest.java
59 lines (49 loc) · 2.29 KB
/
RestClientTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.reminder.service.integration;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* This class is used to test quickly the POST method of a service
*/
public class RestClientTest {
@Test
public void testGetMethod() {
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/reminder-service/v1/reminders/1");
String input = "{\"name\":\"Meeting\",\"description\":\"Meeting with Manager\",\"dueDate\":\"139964720\",\"status\":\"DONE\"}";
/*String input = "<reminder>\n" +
"\t<name>Meeting</name>\n" +
"\t<description>Meeting with Manager</description>\n" +
"\t<status>NOT_DONE</status>\n" +
"</reminder>";
ClientResponse response = webResource.type("application/xml")
.post(ClientResponse.class, input); */
ClientResponse response = webResource.type("application/json")
.get(ClientResponse.class);
Assert.assertEquals(response.getStatus(), 200);
String output = response.getEntity(String.class);
System.out.println("Response:" + output);
}
@Test
public void testPostMethod() {
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/reminder-service/v1/reminder/add");
String input = "{\"name\":\"Meeting\",\"description\":\"Meeting with Manager\",\"dueDate\":\"139964720\",\"status\":\"DONE\"}";
/*String input = "<reminder>\n" +
"\t<name>Meeting</name>\n" +
"\t<description>Meeting with Manager</description>\n" +
"\t<status>NOT_DONE</status>\n" +
"</reminder>";
ClientResponse response = webResource.type("application/xml")
.post(ClientResponse.class, input); */
ClientResponse response = webResource.type("application/json")
.post(ClientResponse.class, input);
Assert.assertEquals(response.getStatus(), 201);
String output = response.getEntity(String.class);
System.out.println(output);
}
}