DeleteTokenRequestTransformer implements ServiceRequestTransformer { @Override public PaymentService transform(ServiceRequest request) throws WorldpayModelTransformationException { if (request == null) { throw new WorldpayModelTransformationException("Request provided to delete token is invalid."); } final DeleteTokenServiceRequest deleteTokenRequest = (DeleteTokenServiceRequest) request; final PaymentService paymentService = new PaymentService(); paymentService.setMerchantCode(deleteTokenRequest.getMerchantInfo().getMerchantCode()); paymentService.setVersion(configurationService.getConfiguration().getString(WORLDPAY_CONFIG_VERSION)); final PaymentTokenDelete deleteToken = (PaymentTokenDelete) deleteTokenRequest.getDeleteTokenRequest().transformToInternalModel(); final Modify modify = new Modify(); modify.getOrderModificationOrBatchModificationOrAccountBatchModificationOrFuturePayAgreementModificationOrPaymentTokenUpdateOrPaymentTokenDelete().add(deleteToken); paymentService.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().add(modify); return paymentService; }  @Override PaymentService transform(ServiceRequest request); @Required void setConfigurationService(final ConfigurationService configurationService);  }
@Test(expected = WorldpayModelTransformationException.class) public void shouldRaiseExceptionWhenServiceRequestIsNull() throws Exception { testObj.transform(null); }
@Test public void shouldReturnPaymentServiceWithPaymentTokenDelete() throws Exception { when(serviceRequestMock.getDeleteTokenRequest().transformToInternalModel()).thenReturn(paymentTokenDeleteMock); when(serviceRequestMock.getMerchantInfo().getMerchantCode()).thenReturn(MERCHANT_CODE); final PaymentService result = testObj.transform(serviceRequestMock); assertEquals(MERCHANT_CODE, result.getMerchantCode()); assertEquals(VERSION, result.getVersion()); assertTrue(result.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().get(0) instanceof Modify); final Modify modify = (Modify) result.getSubmitOrModifyOrInquiryOrReplyOrNotifyOrVerify().get(0); assertTrue(modify.getOrderModificationOrBatchModificationOrAccountBatchModificationOrFuturePayAgreementModificationOrPaymentTokenUpdateOrPaymentTokenDelete().get(0) instanceof PaymentTokenDelete); final PaymentTokenDelete paymentTokenDelete = (PaymentTokenDelete) modify.getOrderModificationOrBatchModificationOrAccountBatchModificationOrFuturePayAgreementModificationOrPaymentTokenUpdateOrPaymentTokenDelete().get(0); assertEquals(paymentTokenDeleteMock, paymentTokenDelete); }