20
20
public class HappyPathTests extends BaseTest {
21
21
22
22
private List <OrderData > orderList ;
23
+ private int orderId ;
24
+ private String userId ;
25
+ private String productId ;
23
26
24
27
@ BeforeClass
25
28
public void testSetup () {
@@ -28,7 +31,7 @@ public void testSetup() {
28
31
29
32
@ Test
30
33
public void testShouldPerformHealthCheckOfServer () {
31
- final APIResponse response = this .request .get ("/getAllOrders " );
34
+ final APIResponse response = this .request .get ("/health " );
32
35
33
36
final Logger logger = new Logger (response );
34
37
logger .logResponseDetails ();
@@ -62,6 +65,12 @@ public void testShouldCreateNewOrders() {
62
65
assertEquals (this .orderList .get (0 ).getUserId (), ordersArray .getJSONObject (0 ).get ("user_id" ));
63
66
assertEquals (this .orderList .get (0 ).getProductId (), ordersArray .getJSONObject (0 ).get ("product_id" ));
64
67
assertEquals (this .orderList .get (0 ).getTotalAmt (), ordersArray .getJSONObject (0 ).get ("total_amt" ));
68
+
69
+ this .orderId = ordersArray .getJSONObject (0 ).getInt ("id" );
70
+ this .userId =ordersArray .getJSONObject (0 ).getString ("user_id" );
71
+ this .productId =ordersArray .getJSONObject (0 ).getString ("product_id" );
72
+
73
+
65
74
}
66
75
67
76
@ Test
@@ -101,9 +110,8 @@ public void testShouldGetOrderUsingOrderId() {
101
110
102
111
@ Test
103
112
public void testShouldGetOrdersUsingUserId () {
104
- final String userId = "2" ;
105
113
106
- final APIResponse response = this .request .get ("/getOrder" , RequestOptions .create ().setQueryParam ("user_id" , userId ));
114
+ final APIResponse response = this .request .get ("/getOrder" , RequestOptions .create ().setQueryParam ("user_id" , this . userId ));
107
115
108
116
final Logger logger = new Logger (response );
109
117
logger .logResponseDetails ();
@@ -113,16 +121,14 @@ public void testShouldGetOrdersUsingUserId() {
113
121
114
122
assertEquals (response .status (), 200 );
115
123
assertEquals (responseObject .get ("message" ), "Order found!!" );
116
- assertEquals (ordersArray .getJSONObject (0 ).get ("user_id" ), userId );
124
+ assertEquals (ordersArray .getJSONObject (0 ).get ("user_id" ), this . userId );
117
125
118
126
}
119
127
120
128
@ Test
121
129
public void testShouldGetOrdersUsingProductId () {
122
- final String productId = "332" ;
123
-
124
130
125
- final APIResponse response = this .request .get ("/getOrder" , RequestOptions .create ().setQueryParam ("product_id" , productId ));
131
+ final APIResponse response = this .request .get ("/getOrder" , RequestOptions .create ().setQueryParam ("product_id" , this . productId ));
126
132
127
133
final Logger logger = new Logger (response );
128
134
logger .logResponseDetails ();
@@ -132,10 +138,35 @@ public void testShouldGetOrdersUsingProductId() {
132
138
133
139
assertEquals (response .status (), 200 );
134
140
assertEquals (responseObject .get ("message" ), "Order found!!" );
135
- assertEquals (ordersArray .getJSONObject (0 ).get ("product_id" ), productId );
141
+ assertEquals (ordersArray .getJSONObject (0 ).get ("product_id" ), this .productId );
142
+
143
+ }
144
+
145
+ @ Test
146
+ public void testShouldGetOrdersUsingOrderIdProductIdAndUserId () {
147
+
148
+ final APIResponse response = this .request .get ("/getOrder" , RequestOptions .create ()
149
+ .setQueryParam ("id" , this .orderId )
150
+ .setQueryParam ("product_id" , this .productId )
151
+ .setQueryParam ("user_id" , this .userId ));
152
+
153
+ final Logger logger = new Logger (response );
154
+ logger .logResponseDetails ();
155
+
156
+ assertEquals (response .status (), 200 );
157
+
158
+
159
+ final JSONObject responseObject = new JSONObject (response .text ());
160
+ final JSONArray ordersArray = responseObject .getJSONArray ("orders" );
161
+
162
+ assertEquals (responseObject .get ("message" ), "Order found!!" );
163
+ assertEquals (ordersArray .getJSONObject (0 ).get ("id" ), this .orderId );
164
+ assertEquals (ordersArray .getJSONObject (0 ).get ("product_id" ), this .productId );
165
+ assertEquals (ordersArray .getJSONObject (0 ).get ("user_id" ), this .userId );
136
166
137
167
}
138
168
169
+
139
170
@ Test
140
171
public void testTokenGeneration () {
141
172
final APIResponse response = this .request .post ("/auth" , RequestOptions .create ().setData (getCredentials ()));
@@ -238,7 +269,7 @@ public void testShouldNotRetrieveDeletedOrder() {
238
269
239
270
assertEquals (response .status (), 404 );
240
271
241
- JSONObject jsonObject = new JSONObject (response .text ());
272
+ final JSONObject jsonObject = new JSONObject (response .text ());
242
273
assertEquals (jsonObject .get ("message" ), "No Order found with the given parameters!" );
243
274
}
244
275
0 commit comments