2
2
3
3
import com .bestbuy .esp .model .*;
4
4
import com .bestbuy .esp .util .StreamingResearchUtil ;
5
- import com .bestbuy .integration .foundation .FoundationConstants ;
6
5
import com .bestbuy .integration .foundation .config .PropertyManager ;
7
6
import com .bestbuy .integration .foundation .configuration .TestConfiguration ;
8
7
import io .restassured .http .ContentType ;
9
8
import io .restassured .module .mockmvc .RestAssuredMockMvc ;
10
9
import io .restassured .module .mockmvc .response .MockMvcResponse ;
11
10
import io .restassured .module .spring .commons .config .AsyncConfig ;
12
11
import io .restassured .response .ExtractableResponse ;
12
+ import org .apache .commons .lang3 .StringUtils ;
13
13
import org .apache .http .conn .ConnectTimeoutException ;
14
14
import org .junit .After ;
15
15
import org .junit .Assert ;
@@ -49,6 +49,7 @@ public class StreamingResearchControllerTest {
49
49
private static final String CLIENT_ID = "client-id" ;
50
50
private static final String CLIENT_ID_VALUE_TDL = "TDL00" ;
51
51
private static final String CLIENT_ID_VALUE_PAD = "PAD00" ;
52
+ private static final String NOT_APPLICABLE = "N/A" ;
52
53
private static final String VENDOR_RESEARCH_END_POINT = "/VendorResearch" ;
53
54
private static final String VALID_RESPONSE = "{\" bbyContractNumber\" : \" 89876545\" ,\" serialNumber\" : \" ABC8928X987\" ,\" partnerSubscriptionId\" : \" a0f9-4d9f-ab59-ba3499dce6da\" ,\" partnerSubscriptionCode\" : \" ad706-0ba0f-94d9f-12ab1\" ,\" partnerServiceId\" : \" ba3499dce6da\" ,\" partnerSubscriptionService\" : \" Premium\" ,\" partnerSubscriptionStatus\" : \" Active\" ,\" startDate\" : \" 2019-12-12\" ,\" expirationDate\" : \" 2019-12-12\" ,\" redemptionDate\" : \" 2019-12-12\" ,\" statusDetails\" : {\" code\" : \" 0\" ,\" message\" : \" Subscription modified successfully.\" }}" ;
54
55
private static final String ERROR_RESPONSE = "{\" message\" :\" No results found for serialNumber: TDLDMY687888338602\" ,\" status\" :\" 400\" ,\" internalCode\" :\" TDL_RSR_ERR\" }" ;
@@ -101,9 +102,10 @@ public void testVendorResearchSingleSuccessTdl() {
101
102
.extract ();
102
103
sleep ();
103
104
Assert .assertEquals (HttpStatus .OK .value (), response .statusCode ());
105
+ validResponse (response , CLIENT_ID_VALUE_TDL );
104
106
verify (restTemplate , times (1 )).postForEntity (any (URI .class ), any (), eq (SdpReqRespLog .class ));
105
107
}
106
-
108
+
107
109
@ Test
108
110
public void testVendorResearchSingleSuccessPad () {
109
111
when (restTemplate .postForEntity (eq (sdp42Uri ), any (), eq (String .class ))).thenReturn (ResponseEntity .ok (VALID_RESPONSE ));
@@ -121,9 +123,10 @@ public void testVendorResearchSingleSuccessPad() {
121
123
.extract ();
122
124
sleep ();
123
125
Assert .assertEquals (HttpStatus .OK .value (), response .statusCode ());
126
+ validResponse (response , CLIENT_ID_VALUE_PAD );
124
127
verify (restTemplate , times (1 )).postForEntity (any (URI .class ), any (), eq (SdpReqRespLog .class ));
125
128
}
126
-
129
+
127
130
@ Test
128
131
public void testVendorResearchSingleInvalidRequestPad () {
129
132
when (restTemplate .postForEntity (eq (sdp42Uri ), any (), eq (String .class ))).thenReturn (ResponseEntity .ok (VALID_RESPONSE ));
@@ -203,7 +206,7 @@ public void testVendorResearchDTVSuccess() {
203
206
Assert .assertEquals (2 , response .as (List .class ).size ());
204
207
verify (restTemplate , times (1 )).postForEntity (any (URI .class ), any (), eq (SdpReqRespLog .class ));
205
208
}
206
-
209
+
207
210
@ Test
208
211
public void testVendorResearchDTVSuccessPad () {
209
212
when (restTemplate .postForEntity (eq (sdp42Uri ), any (), eq (String .class ))).thenReturn (ResponseEntity .ok (VALID_RESPONSE ));
@@ -272,18 +275,20 @@ private List<StreamingResearchRequest> getDtvStreamingResearchRequests() {
272
275
return Arrays .asList (req1 , req2 );
273
276
}
274
277
275
- private HttpEntity <StreamingResearchRequest > generateGreatCallRequestEntity (StreamingResearchRequest request , String vendorId ) {
276
- HttpHeaders headers = new HttpHeaders ();
277
- headers .setContentType (MediaType .APPLICATION_JSON );
278
- headers .add (FoundationConstants .HEADER_CLIENT_ID , vendorId );
279
- return new HttpEntity <>(request , headers );
280
- }
281
-
282
278
private void sleep () {
283
279
try {
284
280
Thread .sleep (200 ); // NOSONAR
285
281
} catch (InterruptedException e ) {
286
282
throw new RuntimeException ("error sleeping" , e );
287
283
}
288
284
}
285
+
286
+ private void validResponse (ExtractableResponse <MockMvcResponse > response , String clientIdValuePad ) {
287
+ List <StreamingResearchResponse > result = (List <StreamingResearchResponse >) response .response ().getMvcResult ().getAsyncResult ();
288
+ if (StringUtils .equals (CLIENT_ID_VALUE_TDL , clientIdValuePad )) {
289
+ Assert .assertEquals (NOT_APPLICABLE , result .get (0 ).getWebUrl ());
290
+ } else {
291
+ Assert .assertEquals (NOT_APPLICABLE , result .get (0 ).getKeyCode ());
292
+ }
293
+ }
289
294
}
0 commit comments