-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREST_test.java
47 lines (37 loc) · 1.46 KB
/
REST_test.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
@Test
public void test_ProductsEndpoint()
throws ClientProtocolException, IOException {
// Given
String jsonMimeType = "application/json";
int albumID = getRandomNumberInRange(1, 40);
HttpUriRequest request = new HttpGet( "https://mezzo-4413.mybluemix.net/api/products/" + albumID );
// When
HttpResponse httpResponse = HttpClientBuilder.create().build().execute( request );
// Then - ensure returned data is JSON
String mimeType = ContentType.getOrDefault(response.getEntity()).getMimeType();
assertEquals( jsonMimeType, mimeType );
}
@Test
public void test_OrdersEndpoint()
throws ClientProtocolException, IOException {
// Given
String jsonMimeType = "application/json";
int albumID = getRandomNumberInRange(1, 40);
HttpUriRequest request = new HttpGet( "https://mezzo-4413.mybluemix.net/api/orders/?aid=" + albumID );
// When
HttpResponse httpResponse = HttpClientBuilder.create().build().execute( request );
// Then ensure returned data is JSON
assertThat(
String mimeType = ContentType.getOrDefault(response.getEntity()).getMimeType();
assertEquals( jsonMimeType, mimeType );
}
/**
*Utility method
*/
private static int getRandomNumberInRange(int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}