DefaultWorldpayAdditionalInfoService implements WorldpayAdditionalInfoService { @Override public WorldpayAdditionalInfoData createWorldpayAdditionalInfoData(final HttpServletRequest request) { final WorldpayAdditionalInfoData additionalInfoData = new WorldpayAdditionalInfoData(); final String sessionId = request.getSession().getId(); additionalInfoData.setSessionId(sessionId); sessionService.setAttribute(WORLDPAY_ADDITIONAL_DATA_SESSION_ID, sessionId); additionalInfoData.setCustomerIPAddress(worldpayCustomerIpAddressStrategy.getCustomerIp(request)); additionalInfoData.setAcceptHeader(request.getHeader(ACCEPT)); additionalInfoData.setUserAgentHeader(request.getHeader(USER_AGENT)); return additionalInfoData; } DefaultWorldpayAdditionalInfoService(final WorldpayCustomerIpAddressStrategy worldpayCustomerIpAddressStrategy, final SessionService sessionService); @Override WorldpayAdditionalInfoData createWorldpayAdditionalInfoData(final HttpServletRequest request);  }
@Test public void createWorldpayAdditionalInfoDataShouldSetSessionIdFromHttpRequest() { when(httpServletRequestMock.getSession().getId()).thenReturn(SESSION_ID); final WorldpayAdditionalInfoData result = testObj.createWorldpayAdditionalInfoData(httpServletRequestMock); assertEquals(SESSION_ID, result.getSessionId()); }
@Test public void createWorldpayAdditionalInfoDataShouldSetCustomerIpFromHttpRequest() { when(worldpayCustomerIpAddressStrategyMock.getCustomerIp(httpServletRequestMock)).thenReturn(CUSTOMER_IP); final WorldpayAdditionalInfoData result = testObj.createWorldpayAdditionalInfoData(httpServletRequestMock); assertEquals(CUSTOMER_IP, result.getCustomerIPAddress()); }
@Test public void createWorldpayAdditionalInfoDataShouldSetAcceptHeaderFromHttpRequest() { when(httpServletRequestMock.getHeader(ACCEPT)).thenReturn(ACCEPT_HEADER_VALUE); final WorldpayAdditionalInfoData result = testObj.createWorldpayAdditionalInfoData(httpServletRequestMock); assertEquals(ACCEPT_HEADER_VALUE, result.getAcceptHeader()); }
@Test public void createWorldpayAdditionalInfoDataShouldSetUserAgentFromHttpRequest() { when(httpServletRequestMock.getHeader(USER_AGENT)).thenReturn(USER_AGENT_VALUE); final WorldpayAdditionalInfoData result = testObj.createWorldpayAdditionalInfoData(httpServletRequestMock); assertEquals(USER_AGENT_VALUE, result.getUserAgentHeader()); }
@Test public void createWorldpayAdditionalInfoData_ShouldStoreInSessionTheRequestSessionId() { when(httpServletRequestMock.getSession().getId()).thenReturn(SESSION_ID); testObj.createWorldpayAdditionalInfoData(httpServletRequestMock); verify(sessionServiceMock).setAttribute(WORLDPAY_ADDITIONAL_DATA_SESSION_ID, SESSION_ID); }