Skip to content

Commit 9feab86

Browse files
Udayaraj MsUdayaraj Ms
authored andcommitted
Merge pull request in28minutes#16 in ESP-SERVICES/sdp36-streaming-research from SUBS-7422 to develop
* commit 'dfb320f60830316e0d89bcea4dd885d492d2f9bf': SUBS-7422 N/A as value for not applicable fields based on vendor.
2 parents 5c431fa + dfb320f commit 9feab86

File tree

7 files changed

+27
-29
lines changed

7 files changed

+27
-29
lines changed

src/main/java/com/bestbuy/esp/dao/StreamingResearchDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public StreamingResearchResponse vendorResearch(StreamingResearchRequest streami
5858
} else {
5959
SdpExcpMsgLog excpMsgLog = StreamingResearchUtil.createExcpMsgLog(sdpId, "", streamingResearchRequest.toString(), Constants.SDP36, e, e.getStatusCode().toString(), e.getMessage());
6060
new ExceptionMessageLogCommand(excpMsgLog, exceptionMessageLogDAO).observe().subscribeOn(Schedulers.io()).subscribe();
61-
return StreamingResearchUtil.vendorErrorResponse(e.getResponseBodyAsString(), streamingResearchRequest);
61+
return StreamingResearchUtil.vendorErrorResponse(e.getResponseBodyAsString(), streamingResearchRequest, vendorId);
6262
}
6363
} catch (ResourceAccessException e) {
6464
throw new InternalServerErrorException("Resource access exception occurred", e);

src/main/java/com/bestbuy/esp/service/StreamingResearchService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ private List<StreamingResearchResponse> aggregateVendorResponse(Object... vendor
8686
}
8787

8888
private StreamingResearchResponse errorResponse(StreamingResearchRequest request, String clientId) {
89-
StreamingResearchResponse response = new StreamingResearchResponse();
90-
response.setSerialNumber(request.getSerialNumber());
91-
response.setKeyCode(request.getKeyCode());
92-
response.setSubscriptionId(request.getSubscriptionId());
93-
response.setErrorMessage((clientId.equalsIgnoreCase(Constants.TIDAL)) ? Constants.VALIDATION_ERROR_MSG_TIDAL : Constants.VALIDATION_ERROR_MSG_PANDORA);
89+
String errorMessage = (clientId.equalsIgnoreCase(Constants.TIDAL)) ? Constants.VALIDATION_ERROR_MSG_TIDAL : Constants.VALIDATION_ERROR_MSG_PANDORA;
90+
StreamingResearchResponse response = StreamingResearchUtil.vendorResponse(request.toString(), clientId, Constants.RESEARCH_RESPONSE);
91+
response.setErrorMessage(errorMessage);
9492
response.setErrorCode(Constants.VALIDATION_ERROR_CODE);
9593
return response;
9694
}

src/main/java/com/bestbuy/esp/util/Constants.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ private Constants() {
66
throw new IllegalAccessError("Utility class");
77
}
88

9-
public static final String FAIL = "Fail";
109
public static final String SUCCESS = "Success";
1110
public static final String SERVICE_URL = ".research.subscription.url";
1211
public static final String EXCEPTION_FORMAT = "%s - %s";
@@ -18,7 +17,6 @@ private Constants() {
1817
public static final String REQ_TYPE_VENDOR_RESEARCH = "VDR";
1918
public static final String RESEARCH_REQUEST = "_RESEARCH_REQUEST";
2019
public static final String RESEARCH_RESPONSE = "_RESEARCH_RESPONSE";
21-
public static final String RESEARCH_ERROR_RESPONSE = "_RESEARCH_ERROR_RESPONSE";
2220
public static final String VENDOR_ERROR_CODE = "SRH_INT_ERR";
2321
public static final String VALIDATION_ERROR_CODE = "SRH_VAL_ERR";
2422
public static final String VALIDATION_ERROR_MSG_TIDAL = "Serial Number/Key Code is required.";

src/main/java/com/bestbuy/esp/util/StreamingResearchUtil.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ public static StreamingResearchResponse vendorResponse(String vendorResponse, St
120120
return SimpleJson.readValue(responseStr, StreamingResearchResponse.class);
121121
}
122122

123-
public static StreamingResearchResponse vendorErrorResponse(String vendorResponse, StreamingResearchRequest request) {
124-
StreamingResearchResponse response = new StreamingResearchResponse();
125-
response.setSerialNumber(request.getSerialNumber());
126-
response.setKeyCode(request.getKeyCode());
127-
response.setSubscriptionId(request.getSubscriptionId());
123+
public static StreamingResearchResponse vendorErrorResponse(String vendorResponse, StreamingResearchRequest request, String vendorId) {
124+
StreamingResearchResponse response = vendorResponse(request.toString(), vendorId, Constants.RESEARCH_RESPONSE);
128125
ErrorInfo errorInfo = SimpleJson.readValue(vendorResponse, ErrorInfo.class);
129126
response.setErrorMessage(errorInfo.getMessage());
130127
response.setErrorCode(errorInfo.getStatus());

src/main/resources/application.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
#sdp9.esp-service.url=https://zuul-esp-services-dt-bdc-na.dt01-lcp-a.na.bestbuy.com/sdp9/CreateReqRespLog
1414
#
1515
#TDL00_RESEARCH_REQUEST={"serialNumber": "$.serialNumber","partnerSubscriptionCode": "$.keyCode"}
16-
#TDL00_RESEARCH_RESPONSE={"contractId":"$.bbyContractNumber","serialNumber":"$.serialNumber","keyCode":"$.partnerSubscriptionCode","subscriptionId":"$.partnerSubscriptionId","subscriptionStatus":"$.partnerSubscriptionStatus","redemptionDate":"$.redemptionDate","startDate":"$.startDate","endDate":"$.expirationDate","subscriptionDescription":"$.partnerSubscriptionService","errorCode":"$.statusDetails.code","errorMessage":"$.statusDetails.message"}
17-
#TDL00_RESEARCH_ERROR_RESPONSE={"serialNumber":"$.serialNumber","keyCode":"$.partnerSubscriptionCode","errorCode":"$.statusDetails[*].code","errorMessage":"$.statusDetails[*].message"}
16+
#TDL00_RESEARCH_RESPONSE={"contractId":"$.bbyContractNumber","serialNumber":"$.serialNumber","webUrl":"NA","keyCode":"$.partnerSubscriptionCode","subscriptionId":"$.partnerSubscriptionId","subscriptionStatus":"$.partnerSubscriptionStatus","redemptionDate":"$.redemptionDate","startDate":"$.startDate","endDate":"$.expirationDate","subscriptionDescription":"$.partnerSubscriptionService","errorCode":"$.statusDetails.code","errorMessage":"$.statusDetails.message"}
17+
#TDL00_RESEARCH_ERROR_RESPONSE={"serialNumber":"$.serialNumber","keyCode":"$.partnerSubscriptionCode","webUrl":"N/A",errorCode":"$.statusDetails[*].code","errorMessage":"$.statusDetails[*].message"}
1818
#
1919
#PAD00.research.subscription.url=sdp42.esp-service.url.research
2020
#sdp42.esp-service.url.research=https://zuul-esp-services-dt-bdc-na.dt01-lcp-a.na.bestbuy.com/sdp42/ResearchSubscription
2121
#PAD00_RESEARCH_REQUEST={\"serialNumber\": \"$.serialNumber\",\"partnerSubscriptionId\": \"$.subscriptionId\"}
22-
#PAD00_RESEARCH_RESPONSE= {\"contractId\":\"$.bbyContractNumber\",\"serialNumber\":\"$.serialNumber\",\"subscriptionId\":\"$.partnerSubscriptionId\",\"webUrl\":\"$.webUrl\",\"subscriptionStatus\":\"$.partnerSubscriptionStatus\",\"redemptionDate\":\"$.redemptionDate\",\"startDate\":\"$.startDate\",\"endDate\":\"$.expirationDate\",\"subscriptionDescription\":\"$.partnerSubscriptionService\",\"errorCode\":\"$.statusDetails[0].code\",\"errorMessage\":\"$.statusDetails[0].message\"}
22+
#PAD00_RESEARCH_RESPONSE= {\"contractId\":\"$.bbyContractNumber\",\"keyCode\":\"N/A\",\"serialNumber\":\"$.serialNumber\",\"subscriptionId\":\"$.partnerSubscriptionId\",\"webUrl\":\"$.webUrl\",\"subscriptionStatus\":\"$.partnerSubscriptionStatus\",\"redemptionDate\":\"$.redemptionDate\",\"startDate\":\"$.startDate\",\"endDate\":\"$.expirationDate\",\"subscriptionDescription\":\"$.partnerSubscriptionService\",\"errorCode\":\"$.statusDetails[0].code\",\"errorMessage\":\"$.statusDetails[0].message\"}
2323
################## Hystrix ###############
2424
#hystrix.command.StreamingResearchCommand.group.key=StreamingResearchCommand
2525
#hystrix.threadpool.StreamingResearchCommand.coreSize=4

src/test/java/com/bestbuy/esp/controller/StreamingResearchControllerTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import com.bestbuy.esp.model.*;
44
import com.bestbuy.esp.util.StreamingResearchUtil;
5-
import com.bestbuy.integration.foundation.FoundationConstants;
65
import com.bestbuy.integration.foundation.config.PropertyManager;
76
import com.bestbuy.integration.foundation.configuration.TestConfiguration;
87
import io.restassured.http.ContentType;
98
import io.restassured.module.mockmvc.RestAssuredMockMvc;
109
import io.restassured.module.mockmvc.response.MockMvcResponse;
1110
import io.restassured.module.spring.commons.config.AsyncConfig;
1211
import io.restassured.response.ExtractableResponse;
12+
import org.apache.commons.lang3.StringUtils;
1313
import org.apache.http.conn.ConnectTimeoutException;
1414
import org.junit.After;
1515
import org.junit.Assert;
@@ -49,6 +49,7 @@ public class StreamingResearchControllerTest {
4949
private static final String CLIENT_ID = "client-id";
5050
private static final String CLIENT_ID_VALUE_TDL = "TDL00";
5151
private static final String CLIENT_ID_VALUE_PAD = "PAD00";
52+
private static final String NOT_APPLICABLE = "N/A";
5253
private static final String VENDOR_RESEARCH_END_POINT = "/VendorResearch";
5354
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.\"}}";
5455
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() {
101102
.extract();
102103
sleep();
103104
Assert.assertEquals(HttpStatus.OK.value(), response.statusCode());
105+
validResponse(response, CLIENT_ID_VALUE_TDL);
104106
verify(restTemplate, times(1)).postForEntity(any(URI.class), any(), eq(SdpReqRespLog.class));
105107
}
106-
108+
107109
@Test
108110
public void testVendorResearchSingleSuccessPad() {
109111
when(restTemplate.postForEntity(eq(sdp42Uri), any(), eq(String.class))).thenReturn(ResponseEntity.ok(VALID_RESPONSE));
@@ -121,9 +123,10 @@ public void testVendorResearchSingleSuccessPad() {
121123
.extract();
122124
sleep();
123125
Assert.assertEquals(HttpStatus.OK.value(), response.statusCode());
126+
validResponse(response, CLIENT_ID_VALUE_PAD);
124127
verify(restTemplate, times(1)).postForEntity(any(URI.class), any(), eq(SdpReqRespLog.class));
125128
}
126-
129+
127130
@Test
128131
public void testVendorResearchSingleInvalidRequestPad() {
129132
when(restTemplate.postForEntity(eq(sdp42Uri), any(), eq(String.class))).thenReturn(ResponseEntity.ok(VALID_RESPONSE));
@@ -203,7 +206,7 @@ public void testVendorResearchDTVSuccess() {
203206
Assert.assertEquals(2, response.as(List.class).size());
204207
verify(restTemplate, times(1)).postForEntity(any(URI.class), any(), eq(SdpReqRespLog.class));
205208
}
206-
209+
207210
@Test
208211
public void testVendorResearchDTVSuccessPad() {
209212
when(restTemplate.postForEntity(eq(sdp42Uri), any(), eq(String.class))).thenReturn(ResponseEntity.ok(VALID_RESPONSE));
@@ -272,18 +275,20 @@ private List<StreamingResearchRequest> getDtvStreamingResearchRequests() {
272275
return Arrays.asList(req1, req2);
273276
}
274277

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-
282278
private void sleep() {
283279
try {
284280
Thread.sleep(200); // NOSONAR
285281
} catch (InterruptedException e) {
286282
throw new RuntimeException("error sleeping", e);
287283
}
288284
}
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+
}
289294
}

src/test/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ sdp8.esp-service.url=https://zuul-esp-services-dt-bdc-na.dt01-lcp-a.na.bestbuy.c
1111
sdp9.esp-service.url=https://zuul-esp-services-dt-bdc-na.dt01-lcp-a.na.bestbuy.com/sdp9/CreateReqRespLog
1212

1313
TDL00_RESEARCH_REQUEST={"serialNumber": "$.serialNumber","partnerSubscriptionCode": "$.keyCode"}
14-
TDL00_RESEARCH_RESPONSE={"contractId":"$.bbyContractNumber","serialNumber":"$.serialNumber","keyCode":"$.partnerSubscriptionCode","subscriptionId":"$.partnerSubscriptionId","subscriptionStatus":"$.partnerSubscriptionStatus","redemptionDate":"$.redemptionDate","startDate":"$.startDate","endDate":"$.expirationDate","subscriptionDescription":"$.partnerSubscriptionService","errorCode":"$.statusDetails.code","errorMessage":"$.statusDetails.message"}
14+
TDL00_RESEARCH_RESPONSE={"contractId":"$.bbyContractNumber","webUrl":"N/A","serialNumber":"$.serialNumber","keyCode":"$.partnerSubscriptionCode","subscriptionId":"$.partnerSubscriptionId","subscriptionStatus":"$.partnerSubscriptionStatus","redemptionDate":"$.redemptionDate","startDate":"$.startDate","endDate":"$.expirationDate","subscriptionDescription":"$.partnerSubscriptionService","errorCode":"$.statusDetails.code","errorMessage":"$.statusDetails.message"}
1515
TDL00_RESEARCH_ERROR_RESPONSE={"serialNumber":"$.serialNumber","keyCode":"$.partnerSubscriptionCode","errorCode":"$.statusDetails.code","errorMessage":"$.statusDetails.message"}
1616

1717
PAD00_RESEARCH_REQUEST={\"serialNumber\": \"$.serialNumber\",\"partnerSubscriptionId\": \"$.subscriptionId\"}
18-
PAD00_RESEARCH_RESPONSE= {\"contractId\":\"$.bbyContractNumber\",\"serialNumber\":\"$.serialNumber\",\"subscriptionId\":\"$.partnerSubscriptionId\",\"webUrl\":\"$.webUrl\",\"subscriptionStatus\":\"$.partnerSubscriptionStatus\",\"redemptionDate\":\"$.redemptionDate\",\"startDate\":\"$.startDate\",\"endDate\":\"$.expirationDate\",\"subscriptionDescription\":\"$.partnerSubscriptionService\",\"errorCode\":\"$.statusDetails[0].code\",\"errorMessage\":\"$.statusDetails[0].message\"}
18+
PAD00_RESEARCH_RESPONSE= {\"contractId\":\"$.bbyContractNumber\",\"keyCode\":\"N/A\",\"serialNumber\":\"$.serialNumber\",\"subscriptionId\":\"$.partnerSubscriptionId\",\"webUrl\":\"$.webUrl\",\"subscriptionStatus\":\"$.partnerSubscriptionStatus\",\"redemptionDate\":\"$.redemptionDate\",\"startDate\":\"$.startDate\",\"endDate\":\"$.expirationDate\",\"subscriptionDescription\":\"$.partnerSubscriptionService\",\"errorCode\":\"$.statusDetails[0].code\",\"errorMessage\":\"$.statusDetails[0].message\"}
1919
#
2020
################ Hystrix ###############
2121

0 commit comments

Comments
 (0)