UpdateTokenRequestTransformer implements ServiceRequestTransformer { @Override public PaymentService transform(final ServiceRequest request) throws WorldpayModelTransformationException { if (request == null) { throw new WorldpayModelTransformationException("Request provided to update token is invalid."); } final UpdateTokenServiceRequest updateTokenRequest = (UpdateTokenServiceRequest) request; final PaymentService paymentService = new PaymentService(); paymentService.setMerchantCode(updateTokenRequest.getMerchantInfo().getMerchantCode()); paymentService.setVersion(configurationService.getConfiguration().getString(WORLDPAY_CONFIG_VERSION)); final PaymentTokenUpdate updateToken = (PaymentTokenUpdate) updateTokenRequest.getUpdateTokenRequest().transformToInternalModel(); final Modify modify = new Modify(); modify.getOrderModificationOrBatchModificationOrAccountBatchModificationOrFuturePayAgreementModificationOrPaymentTokenUpdateOrPaymentTokenDelete().add(updateToken); paymentService.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(modify); return paymentService; }  @Override PaymentService transform(final ServiceRequest request); @Required void setConfigurationService(final ConfigurationService configurationService);  }
@Test(expected = WorldpayModelTransformationException.class) public void shouldRaiseExceptionWhenServiceRequestIsNull() throws Exception { testObj.transform(null); }
@Test public void shouldReturnPaymentServiceWithPaymentTokenUpdate() throws Exception { when(serviceRequestMock.getUpdateTokenRequest().transformToInternalModel()).thenReturn(paymentTokenUpdateMock); when(serviceRequestMock.getMerchantInfo().getMerchantCode()).thenReturn(MERCHANT_CODE); final PaymentService result = testObj.transform(serviceRequestMock); assertEquals(MERCHANT_CODE, result.getMerchantCode()); assertTrue(result.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().get(0) instanceof Modify); final Modify modify = (Modify) result.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().get(0); assertTrue(modify.getOrderModificationOrBatchModificationOrAccountBatchModificationOrFuturePayAgreementModificationOrPaymentTokenUpdateOrPaymentTokenDelete().get(0) instanceof PaymentTokenUpdate); final PaymentTokenUpdate paymentTokenUpdate = (PaymentTokenUpdate) modify.getOrderModificationOrBatchModificationOrAccountBatchModificationOrFuturePayAgreementModificationOrPaymentTokenUpdateOrPaymentTokenDelete().get(0); assertEquals(paymentTokenUpdateMock, paymentTokenUpdate); }