-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoNetAPITests.java
126 lines (100 loc) · 5.34 KB
/
GeoNetAPITests.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import api.GeoNetAPI;
import model.*;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import retrofit2.Call;
import java.io.IOException;
public class GeoNetAPITests {
private static GeoNetAPI api;
@BeforeClass
public static void setUp() {
api = new GeoNetAPI();
}
@Test
public void getFeltReports_Tests() throws IOException {
Call<FeltReportCollection> feltReportCollectionCall;
// Accepted Input
feltReportCollectionCall = api.getService().getFeltReports("reported");
Assert.assertTrue(feltReportCollectionCall.execute().isSuccessful());
feltReportCollectionCall = api.getService().getFeltReports("measured");
Assert.assertTrue(feltReportCollectionCall.execute().isSuccessful());
feltReportCollectionCall = api.getService().getFeltReports("reported", "2013p407387");
Assert.assertTrue(feltReportCollectionCall.execute().isSuccessful());
// Accepted Input, although no results
feltReportCollectionCall = api.getService().getFeltReports("measured", "2013p407387");
Assert.assertFalse("measured data not available for individual publicID", feltReportCollectionCall.execute().isSuccessful());
// Invalid Inputs
feltReportCollectionCall = api.getService().getFeltReports("");
Assert.assertFalse(feltReportCollectionCall.execute().isSuccessful());
feltReportCollectionCall = api.getService().getFeltReports("abc123");
Assert.assertFalse(feltReportCollectionCall.execute().isSuccessful());
feltReportCollectionCall = api.getService().getFeltReports(null);
Assert.assertFalse(feltReportCollectionCall.execute().isSuccessful());
feltReportCollectionCall = api.getService().getFeltReports("reported", "");
Assert.assertFalse(feltReportCollectionCall.execute().isSuccessful());
feltReportCollectionCall = api.getService().getFeltReports("reported", "abc123");
Assert.assertFalse(feltReportCollectionCall.execute().isSuccessful());
}
@Test
public void getNews_Tests() throws IOException {
Call<NewsFeedCollection> newsFeedCollectionCall = api.getService().getNews();
Assert.assertTrue(newsFeedCollectionCall.execute().isSuccessful());
}
@Test
public void getQuakeStats_Tests() throws IOException {
Call<QuakeStatsCollection> quakeStatsCollectionCall = api.getService().getQuakeStats();
Assert.assertTrue(quakeStatsCollectionCall.execute().isSuccessful());
}
@Test
public void getQuakeByMagnitude_Tests() throws IOException {
// Valid Inputs
Call<QuakeInformationCollection> quakeInformationCollectionCall;
for(int i = -1; i < 9; i++) {
quakeInformationCollectionCall = api.getService().getQuakesByMagnitude(i);
Assert.assertTrue(quakeInformationCollectionCall.execute().isSuccessful());
}
//Invalid Inputs
quakeInformationCollectionCall = api.getService().getQuakesByMagnitude(1000);
Assert.assertFalse(quakeInformationCollectionCall.execute().isSuccessful());
quakeInformationCollectionCall = api.getService().getQuakesByMagnitude(-1000);
Assert.assertFalse(quakeInformationCollectionCall.execute().isSuccessful());
}
@Test
public void getQuakeInfo_Tests() throws IOException {
// Valid Inputs
Call<QuakeInformationCollection> quakeInformationCollectionCall = api.getService().getQuakeInfo("2014p715167");
Assert.assertTrue(quakeInformationCollectionCall.execute().isSuccessful());
// Invalid Inputs
quakeInformationCollectionCall = api.getService().getQuakeInfo("");
Assert.assertFalse(quakeInformationCollectionCall.execute().isSuccessful());
quakeInformationCollectionCall = api.getService().getQuakeInfo("abc123");
Assert.assertFalse(quakeInformationCollectionCall.execute().isSuccessful());
try {
quakeInformationCollectionCall = api.getService().getQuakeInfo(null);
quakeInformationCollectionCall.execute();
Assert.fail("Should not process this API call regardless of success or not.");
} catch (IllegalArgumentException e) { }
}
@Test
public void getQuakeHistory_Tests() throws IOException {
// Valid Inputs
Call<QuakeHistoryCollection> quakeHistoryCollectionCall = api.getService().getQuakeHistory("2014p715167");
Assert.assertTrue(quakeHistoryCollectionCall.execute().isSuccessful());
// Invalid Inputs
quakeHistoryCollectionCall = api.getService().getQuakeHistory("");
Assert.assertFalse(quakeHistoryCollectionCall.execute().isSuccessful());
quakeHistoryCollectionCall = api.getService().getQuakeHistory("abc123");
Assert.assertFalse(quakeHistoryCollectionCall.execute().isSuccessful());
try {
quakeHistoryCollectionCall = api.getService().getQuakeHistory(null);
quakeHistoryCollectionCall.execute();
Assert.fail("Should not process this API call regardless of success or not.");
} catch (IllegalArgumentException e) { }
}
@Test
public void getVolcanoAlertLevels_Tests() throws IOException {
Call<VolcanoCollection> volcanoCollectionCall = api.getService().getVolcanoAlertLevel();
Assert.assertTrue(volcanoCollectionCall.execute().isSuccessful());
}
}