How to use setId method of mock.contract.Payment class

Best Karate code snippet using mock.contract.Payment.setId

Source:DefaultSapRevenueCloudSubscriptionIntegrationTest.java Github

copy

Full Screen

...146 //Input147 SubscriptionData subscriptionData = new SubscriptionData();148 subscriptionData.setVersion("23");149 subscriptionData.setValidTillDate("2019-10-19");150 subscriptionData.setId(SUBSCRIPTION_ID);151 //Mocks152 mockDestinationService();153 Metadata metadata = new Metadata();154 metadata.setVersion(123);155 CancellationResponse response = new CancellationResponse();156 response.setCancellationReason("Some Reason");157 response.setChangedAt(new Date());158 response.setChangedBy("some.user@sap.com");159 response.setMetadata(metadata);160 response.setRequestedCancellationDate("2019-10-31");161 when(mockSubscriptionService.cancelSubscription(any(String.class), any(CancellationRequest.class)))162 .thenReturn(response);163 //Execute164 sapRevenueCloudSubscriptionFacade.cancelSubscription(subscriptionData);165 }166 //@Test167 public void shouldWithdrawSubscription() throws SubscriptionFacadeException {168 //Input169 SubscriptionData subscriptionData = new SubscriptionData();170 subscriptionData.setVersion("10");171 subscriptionData.setId(SUBSCRIPTION_ID);172 //Mocks173 mockDestinationService();174 Metadata metadata = new Metadata();175 metadata.setVersion(10);176 WithdrawalResponse withdrawalResponse = new WithdrawalResponse();177 withdrawalResponse.setChangedAt(new Date());178 withdrawalResponse.setChangedBy("some.user@sap.com");179 withdrawalResponse.setMetadata(metadata);180 ResponseEntity<WithdrawalResponse> response = getResponseEntity(withdrawalResponse);181 when(mockRestOperations.postForEntity(any(URI.class), any(WithdrawalRequest.class), eq(WithdrawalResponse.class)))182 .thenReturn(response);183 //Execute184 sapRevenueCloudSubscriptionFacade.withdrawSubscription(subscriptionData);185 }186 //@Test187 public void shouldComputeCancellationDate() throws SubscriptionFacadeException, SubscriptionServiceException {188 //Response189 EffectiveExpirationDate response = new EffectiveExpirationDate();190 response.setEffectiveExpirationDate(new Date());191 //Mocks192 mockDestinationService();193 when(mockSubscriptionService.computeCancellationDate(eq(SUBSCRIPTION_ID), any(String.class))).thenReturn(response);194 //Execute195 SubscriptionData result = sapRevenueCloudSubscriptionFacade.computeCancellationDate(SUBSCRIPTION_ID);196 //Verify197 Assert.assertEquals(COMPUTED_CANCELLATION_DATE, result.getValidTillDate());198 }199 //@Test200 public void shouldReverseCancellation() throws SubscriptionFacadeException, SubscriptionServiceException {201 //Input202 SubscriptionData subscriptionData = new SubscriptionData();203 subscriptionData.setVersion("23");204 subscriptionData.setId(SUBSCRIPTION_ID);205 //Mocks206 mockDestinationService();207 CancellationReversalResponse response = new CancellationReversalResponse();208 response.setValidUntil(new Date());209 response.setValidUntilIsUnlimited(false);210 when(mockSubscriptionService.reverseCancellation(eq(SUBSCRIPTION_ID), any(CancellationReversalRequest.class))).thenReturn(response);211 //Execute212 sapRevenueCloudSubscriptionFacade.reverseCancellation(subscriptionData);213 }214 //@Test215 public void shouldChangePaymentDetailsAsCard() throws SubscriptionFacadeException, SubscriptionServiceException {216 //Input217 SubscriptionData subscriptionData = new SubscriptionData();218 subscriptionData.setVersion("23");219 subscriptionData.setId(SUBSCRIPTION_ID);220 //SetUp221 customerData.setUid(CUSTOMER_EMAIL);222 CreditCardPaymentInfoModel ccPaymentInfoModel = new CreditCardPaymentInfoModel();223 ccPaymentInfoModel.setSubscriptionId(SUBSCRIPTION_ID);224 SAPRevenueCloudConfigurationModel revenueCloudModel = new SAPRevenueCloudConfigurationModel();225 revenueCloudModel.setInvoiceMethod("Invoice");226 revenueCloudModel.setPaymentMethod("Payment Card");227 revenueCloudModel.setName("name");228 List<SAPRevenueCloudConfigurationModel> revenueCloudConfigs = new LinkedList<>();229 revenueCloudConfigs.add(revenueCloudModel);230 //Mocks231 when(mockGenericDao.find()).thenReturn(revenueCloudConfigs);232 when(mockSAPRevenueCloudConfigurationModel.getPaymentMethod()).thenReturn(PAYMENT_METHOD);233 when(mockCustomerFacade.getCurrentCustomer()).thenReturn(customerData);234 when(mockUserService.getCurrentUser()).thenReturn(mockUser);235 when(mockCustomerAccountService.getCreditCardPaymentInfoForCode(any(CustomerModel.class), any(String.class))).thenReturn(ccPaymentInfoModel);236 when(mockCustomerAccountDao.findCreditCardPaymentInfoByCustomer(any(CustomerModel.class), eq(PAYMENT_CARD_ID))).thenReturn(ccPaymentInfoModel);237 mockDestinationService();238 Metadata metadata = new Metadata();239 metadata.setVersion(123);240 Payment payment = new Payment();241 payment.setPaymentCardToken("External Card");242 payment.setPaymentCardToken("Some_card_token");243 PaymentResponse response = new PaymentResponse();244 response.setChangedAt(new Date());245 response.setChangedBy("some.user@sap.com");246 response.setMetadata(metadata);247 response.setPayment(payment);248 when(mockSubscriptionService.updatePayment(any(String.class), any(PaymentRequest.class)))249 .thenReturn(response);250 //Verify251 Assert.assertNotNull("Payment Card Id should not be null.", PAYMENT_CARD_ID);252 Assert.assertNotNull("Payment Card Id is invalid or doesn't belong to customer", PAYMENT_CARD_TOKEN);253 //Execute254 sapRevenueCloudSubscriptionFacade.changePaymentDetailsAsCard(subscriptionData, PAYMENT_CARD_ID);255 }256 //@Test257 public void shouldChangePaymentDetailsAsInvoice() throws SubscriptionFacadeException, SubscriptionServiceException {258 //Input259 SubscriptionData subscriptionData = new SubscriptionData();260 subscriptionData.setVersion("23");261 subscriptionData.setId(SUBSCRIPTION_ID);262 //SetUp263 customerData.setUid(CUSTOMER_EMAIL);264 SAPRevenueCloudConfigurationModel revenueCloudModel = new SAPRevenueCloudConfigurationModel();265 revenueCloudModel.setInvoiceMethod("Invoice");266 revenueCloudModel.setPaymentMethod("Payment Card");267 revenueCloudModel.setName("name");268 List<SAPRevenueCloudConfigurationModel> revenueCloudConfigs = new LinkedList<>();269 revenueCloudConfigs.add(revenueCloudModel);270 //Mocks271 when(mockGenericDao.find()).thenReturn(revenueCloudConfigs);272 when(mockSAPRevenueCloudConfigurationModel.getInvoiceMethod()).thenReturn(PAYMENT_INVOICE);273 when(mockCustomerFacade.getCurrentCustomer()).thenReturn(customerData);274 mockDestinationService();275 Metadata metadata = new Metadata();276 metadata.setVersion(123);277 Payment payment = new Payment();278 payment.setPaymentCardToken("Invoice");279 PaymentResponse response = new PaymentResponse();280 response.setChangedAt(new Date());281 response.setChangedBy("some.user@sap.com");282 response.setMetadata(metadata);283 response.setPayment(payment);284 when(mockSubscriptionService.updatePayment(any(String.class), any(PaymentRequest.class)))285 .thenReturn(response);286 //Execute287 sapRevenueCloudSubscriptionFacade.changePaymentDetailsAsInvoice(subscriptionData);288 }289 //@Test290 public void shouldFetchBillDetails() throws SubscriptionFacadeException, SubscriptionServiceException {291 //Mocks292 mockDestinationService();293 Bill bill = getSampleBill();294 when(mockBillService.getBill(any(String.class))).thenReturn(bill);295 //Execute296 List<SubscriptionBillingData> subscriptionBillDetails = sapRevenueCloudSubscriptionFacade.getSubscriptionBills("2019-10-31","121");297 Assert.assertNotNull(subscriptionBillDetails);298 }299 @Test300 public void shouldFetchSubscriptions_details(){301 }302 public Bill getSampleBill() {303 BillMetadata metadata = new BillMetadata();304 metadata.setCreatedAt(stringToDate("2019-11-16T06:01:33.006Z"));305 Closing closing = new Closing();306 closing.setMethod("AUTO");307 closing.setMetaData(metadata);308 BillMarket market = new BillMarket();309 market.setId("US");310 market.setTimeZone("America/New_York");311 market.setCurrency("USD");312 market.setPriceType("Net");313 Customer customer = new Customer();314 customer.setId("6301453447");315 customer.setType("INDIVIDUAL");316 BillPayment payment = new BillPayment();317 payment.setMethod("External Card");318 payment.setToken("0a099acd-2a32-48c1-8da7-d980ad6e210e");319 payment.setPaymentStatus("NOT_SETTLED");320 MonetaryAmount monetaryAmount = new MonetaryAmount();321 monetaryAmount.setCurrency("USD");322 monetaryAmount.setAmount(24f);323 BillItem billItem = getSampleBillItem();324 Bill bill = new Bill();325 bill.setId("2E7F17D2-C14C-4B6D-AFFE-A395B0035DEC");326 bill.setDocumentNumber(116);327 bill.setMetaData(metadata);328 bill.setBillingType("CHARGE");329 bill.setBillStatus("OPEN");330 bill.setClosing(closing);331 bill.setTransferStatus("NOT_TRANSFERRED");332 bill.setBillingDate(stringToDate("2019-12-14", SUBSCRIPTION_BILL_DATE_FORMAT));333 bill.setCreateInvoice(true);334 bill.setMarket(market);335 bill.setCustomer(customer);336 bill.setPayment(payment);337 bill.setNetAmount(monetaryAmount);338 bill.setBillItems(List.of(billItem));339 return bill;340 }341 private BillItem getSampleBillItem() {342 BillSubscription subscription = new BillSubscription();343 subscription.setId("0DF60592-62FE-4EBC-B446-03395D0E60AA");344 subscription.setDocumentNumber(83);345 subscription.setItemId("4e686eed-b367-485d-b341-20a8da8ac327");346 BillProduct product = new BillProduct();347 product.setId("ab4bb66a-8ffa-48ea-8226-86cdf23b5372");348 product.setCode("MZ-SR-P004");349 product.setName("Pump Monitoring Service - Standard Edition");350 BillRatePlan ratePlan = new BillRatePlan();351 ratePlan.setId("501c6ea0-db1c-4c8c-be55-ab527e1aa3e4");352 MonetaryAmount netAmount = new MonetaryAmount();353 netAmount.setCurrency("USD");354 netAmount.setAmount(-15.2f);355 Charge charge = getSampleCharge();356 BillItem billItem = new BillItem();357 billItem.setSubscription(subscription);358 billItem.setProduct(product);359 billItem.setRatePlan(ratePlan);360 billItem.setNetAmount(netAmount);361 billItem.setCharges(List.of(charge));362 billItem.setCredits(Collections.emptyList());363 return billItem;364 }365 private Charge getSampleCharge() {366 RatingPeriod ratingPeriod = new RatingPeriod();367 ratingPeriod.setStart(stringToDate("2019-11-11T05:00:00Z"));368 ratingPeriod.setEnd(stringToDate("2019-12-11T05:00:00Z"));369 Quantity consumedQuantity = new Quantity();370 consumedQuantity.setUnit("Each");371 consumedQuantity.setValue(1f);372 Quantity chargedQuantity = new Quantity();373 chargedQuantity.setUnit("Each");374 chargedQuantity.setValue(1f);375 Quantity includedQuantity = new Quantity();376 includedQuantity.setUnit("Each");377 includedQuantity.setValue(0f);378 MonetaryAmount netAmount = new MonetaryAmount();379 netAmount.setCurrency("USD");380 netAmount.setAmount(-19f);381 Charge charge = new Charge();382 charge.setMetricId("Recurrring");383 charge.setRatingPeriod(ratingPeriod);384 charge.setConsumedQuantity(consumedQuantity);385 charge.setNetAmount(netAmount);386 charge.setReversal(true);387 return charge;388 }389 private Subscription getSampleSubscription() {390 Metadata metadata = new Metadata();391 metadata.setVersion(2);392 BusinessPartner customer = new BusinessPartner();393 customer.setId("6301453447");394 Market market = new Market();395 market.setId("US");396 market.setTimeZone("America/New_York");397 market.setCurrency("USD");398 CancellationPolicy cancellationPolicy = new CancellationPolicy();399 cancellationPolicy.setAllowMidBillCycleExpiration(false);400 cancellationPolicy.setWithdrawalPeriod(15);401 cancellationPolicy.setWithdrawalPeriodEndDate(stringToDate("2019-11-27T05:00:00.000Z"));402 Payment payment = new Payment();403 payment.setPaymentMethod("External Card");404 payment.setPaymentCardToken("0a099acd-2a32-48c1-8da7-d980ad6e210e");405 PrecedingDocument precedingDocument = new PrecedingDocument();406 precedingDocument.setId("6887e969-0b93-48a0-b414-02e255cc8de8");407 precedingDocument.setItemId("78e53648-cf42-4803-b43e-c2af9af16131_1");408 precedingDocument.setDocumentNumber(129);409 precedingDocument.setSource("provisioning-request");410 Product product = new Product();411 product.setId("ab4bb66a-8ffa-48ea-8226-86cdf23b5372");412 product.setCode("MZ-SR-P004");413 product.setName("Pump Monitoring Service - Standard Edition");414 RatePlan ratePlan = new RatePlan();415 ratePlan.setId("501c6ea0-db1c-4c8c-be55-ab527e1aa3e4");416 ratePlan.setSource("product");417 Pricing pricing = new Pricing();418 Item item = new Item();419 item.setItemId("78e53648-cf42-4803-b43e-c2af9af16131");420 item.setLineNumber("1");421 item.setProduct(product);422 item.setRatePlan(ratePlan);423 item.setPricing(pricing);424 item.setTechnicalResources(Collections.emptyList());425 item.setSubscriptionType("Commercial");426 item.setCreateBill(true);427 item.setCreateInvoice(true);428 item.setCreateRating(true);429 item.setSubscriptionParameters(Collections.emptyList());430 item.setCustomReferences(Collections.emptyList());431 Snapshot snapshot = new Snapshot();432 snapshot.setEffectiveDate(stringToDate("2019-11-11T11:15:20.144Z"));433 snapshot.setPrecedingDocument(precedingDocument);434 snapshot.setItems(List.of(item));435 ContractTerm contractTerm = new ContractTerm();436 contractTerm.setStartDate(stringToDate("2019-11-11T11:15:20.144Z"));437 contractTerm.setPeriod(1);438 contractTerm.setEndDate(stringToDate("2019-12-11T05:00:00.000Z"));439 Subscription subscription = new Subscription();440 subscription.setSubscriptionId(SUBSCRIPTION_ID);441 subscription.setDocumentNumber(84);442 subscription.setMetadata(metadata);443 subscription.setValidFrom(stringToDate("2019-11-11T11:16:42.906Z"));444 subscription.setBillingCycleReferenceDate(stringToDate("2019-11-11T05:00:00.000Z"));445 subscription.setCreatedAt(stringToDate("2019-11-11T11:16:42.906Z"));446 subscription.setCreatedBy("Provisioning-Request");447 subscription.setCustomer(customer);448 subscription.setMarket(market);449 subscription.setCancellationPolicy(cancellationPolicy);450 subscription.setCustomReferences(Collections.emptyList());451 subscription.setContractTerm(contractTerm);452 subscription.setCancelledWithOverruledTerms(false);453 subscription.setStatus("Active");454 subscription.setBillingCycle("anniversary-monthly");455 subscription.setSnapshots(List.of(snapshot));456 return subscription;457 }458 public void mockCurrentUser() {459 when(mockUserService.getCurrentUser()).thenReturn(mockUser);460 when(mockUser.getRevenueCloudCustomerId()).thenReturn(CUSTOMER_ID);461 }462 private void mockDestinationService() {463 AbstractDestinationModel destinationModel = new ExposedDestinationModel();464 destinationModel.setActive(true);465 destinationModel.setCredential(new ExposedOAuthCredentialModel());466 destinationModel.setDestinationTarget(new DestinationTargetModel());467 destinationModel.setEndpoint(new EndpointModel());468 destinationModel.setId("sapSubscriptionBilling");469 destinationModel.setUrl("https://sample.subscriptionbilling.url");470 when(mockDestinationService.getDestinationById(anyString())).thenReturn(destinationModel);471 }472 private <T> ResponseEntity<T> getResponseEntity(T obj){473 MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();474 headers.add("x-count", "100");475 headers.add("x-pagecount", "10");476 return new ResponseEntity<>(obj, headers, HttpStatus.valueOf(200));477 }478 private static class BillMetadata extends de.hybris.platform.sap.saprevenuecloudorder.pojo.bill.v2.Metadata {479 }480 private static class BillMarket extends de.hybris.platform.sap.saprevenuecloudorder.pojo.bill.v2.Market {481 }482 private static class BillPayment extends de.hybris.platform.sap.saprevenuecloudorder.pojo.bill.v2.Payment {...

Full Screen

Full Screen

Source:ContractServiceTest.java Github

copy

Full Screen

...60 User owner = new User();61 owner.setAccountName("owner");62 User borrower = new User();63 borrower.setAccountName("borrower");64 borrower.setId((long) 1);65 ItemRental itemRental = new ItemRental(owner);66 LocalDateTime start = LocalDateTime.now();67 LocalDateTime end = LocalDateTime.now();68 end = end.plusDays(3);69 Offer offer = new Offer(itemRental, borrower, start, end);70 borrowContract = new BorrowContract(offer);71 borrowContract.setBorrower(borrower);72 borrowContract.setId((long) 1);73 List<Conflict> conflicts = new ArrayList<>();74 borrowContract.setConflicts(conflicts);75 borrowContract.setFinished(false);76 Conflict conflict = new Conflict();77 conflict.setContract(borrowContract);78 conflict.setId(1);79 }80 @Test81 public void createContractTest() {82 setUpTests();83 User owner = new User();84 User borrower = new User();85 ItemRental itemRental = new ItemRental(owner);86 LocalDateTime start = LocalDateTime.now();87 LocalDateTime end = LocalDateTime.now();88 end = end.plusDays(3);89 Offer offer = new Offer(itemRental, borrower, start, end);90 ArgumentCaptor<BorrowContract> argument = ArgumentCaptor.forClass(BorrowContract.class);91 contractService.create(offer);92 verify(borrowContractRepo, times(1)).save(argument.capture());93 }94 @Test95 public void returnItemTest() {96 User owner = new User();97 User borrower = new User();98 borrower.setAccountName("borrower");99 borrower.setId((long) 1);100 ItemRental itemRental = new ItemRental(owner);101 LocalDateTime start = LocalDateTime.now();102 LocalDateTime end = LocalDateTime.now();103 end = end.plusDays(3);104 Offer offer = new Offer(itemRental, borrower, start, end);105 borrowContract = new BorrowContract(offer);106 borrowContract.setBorrower(borrower);107 borrowContract.setId((long) 1);108 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);109 ArgumentCaptor<BorrowContract> argument = ArgumentCaptor.forClass(BorrowContract.class);110 contractService.returnItem(borrowContract.getId(), borrower.getAccountName());111 verify(borrowContractRepo, times(1)).save(argument.capture());112 }113 @Test114 public void acceptReturnTest() {115 User owner = new User();116 owner.setAccountName("owner");117 User borrower = new User();118 borrower.setAccountName("borrower");119 borrower.setId((long) 1);120 ItemRental itemRental = new ItemRental(owner);121 LocalDateTime start = LocalDateTime.now();122 LocalDateTime end = LocalDateTime.now();123 end = end.plusDays(3);124 Offer offer = new Offer(itemRental, borrower, start, end);125 borrowContract = new BorrowContract(offer);126 borrowContract.setBorrower(borrower);127 borrowContract.setId((long) 1);128 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);129 ArgumentCaptor<BorrowContract> argument = ArgumentCaptor.forClass(BorrowContract.class);130 contractService.acceptReturn(borrowContract.getId(), owner.getAccountName());131 verify(borrowContractRepo, times(1)).save(argument.capture());132 }133 @Test134 public void openConflictTest() {135 User owner = new User();136 owner.setAccountName("owner");137 User borrower = new User();138 borrower.setAccountName("borrower");139 borrower.setId((long) 1);140 ItemRental itemRental = new ItemRental(owner);141 LocalDateTime start = LocalDateTime.now();142 LocalDateTime end = LocalDateTime.now();143 end = end.plusDays(3);144 Offer offer = new Offer(itemRental, borrower, start, end);145 borrowContract = new BorrowContract(offer);146 borrowContract.setBorrower(borrower);147 borrowContract.setId((long) 1);148 List<Conflict> conflicts = new ArrayList<>();149 borrowContract.setConflicts(conflicts);150 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);151 ArgumentCaptor<BorrowContract> argument = ArgumentCaptor.forClass(BorrowContract.class);152 contractService.openConflict("desc", "borrower", borrowContract.getId());153 verify(borrowContractRepo, times(1)).save(argument.capture());154 }155 @Test156 public void calcPriceTest() {157 ArgumentCaptor<Contract> argument = ArgumentCaptor.forClass(Contract.class);158 when(borrowContractRepo.findOneById(anyLong())).thenReturn(borrowContract);159 contractService.calcPrice(anyLong());160 verify(paymentService, times(1)).createPayment(argument.capture());161 assertEquals(borrowContract, argument.getValue());162 }163 @Test164 public void calcPriceNotInDbTest() {165 ArgumentCaptor<Contract> argument = ArgumentCaptor.forClass(Contract.class);166 when(contractRepo.findOneById(anyLong())).thenReturn(null);167 contractService.calcPrice(anyLong());168 verify(paymentService, times(1)).createPayment(argument.capture());169 Assert.assertNull(argument.getValue());170 }171 @Test172 public void buySaleItemTest() {173 User owner = new User();174 owner.setAccountName("owner");175 owner.setId((long) 1);176 Item item = new ItemSale();177 item.setId((long) 1);178 ((ItemSale) item).setPrice(1);179 item.setOwner(owner);180 User customer = new User();181 customer.setId((long) 2);182 customer.setAccountName("customer");183 customer.setPropayId("1");184 when(userService.fetchUserByAccountName("customer")).thenReturn(customer);185 when(itemService.findItem(item.getId())).thenReturn(item);186 ArgumentCaptor<SellContract> argument = ArgumentCaptor.forClass(SellContract.class);187 contractService.buySaleItem(item.getId(), customer.getAccountName());188 verify(sellContractRepo, times(1)).save(argument.capture());189 }190 @Test191 public void endContractTest() {192 User owner = new User();193 owner.setAccountName("owner");194 User borrower = new User();195 borrower.setAccountName("borrower");196 borrower.setId((long) 1);197 ItemRental itemRental = new ItemRental(owner);198 LocalDateTime start = LocalDateTime.now();199 LocalDateTime end = LocalDateTime.now();200 end = end.plusDays(3);201 Offer offer = new Offer(itemRental, borrower, start, end);202 borrowContract = new BorrowContract(offer);203 borrowContract.setBorrower(borrower);204 borrowContract.setId((long) 1);205 List<Conflict> conflicts = new ArrayList<>();206 borrowContract.setConflicts(conflicts);207 borrowContract.setFinished(false);208 Conflict conflict = new Conflict();209 conflict.setContract(borrowContract);210 conflict.setId(1);211 when(conflictService.fetchConflictById(conflict.getId())).thenReturn(conflict);212 ArgumentCaptor<BorrowContract> argument = ArgumentCaptor.forClass(BorrowContract.class);213 contractService.endContract(1);214 verify(borrowContractRepo, times(1)).save(argument.capture());215 }216 @Test217 public void cancelContractTest() {218 User owner = new User();219 owner.setAccountName("owner");220 User borrower = new User();221 borrower.setAccountName("borrower");222 borrower.setId((long) 1);223 ItemRental itemRental = new ItemRental(owner);224 LocalDateTime start = LocalDateTime.now();225 LocalDateTime end = LocalDateTime.now();226 end = end.plusDays(3);227 Offer offer = new Offer(itemRental, borrower, start, end);228 borrowContract = new BorrowContract(offer);229 borrowContract.setBorrower(borrower);230 borrowContract.setId((long) 1);231 List<Conflict> conflicts = new ArrayList<>();232 borrowContract.setConflicts(conflicts);233 borrowContract.setFinished(false);234 Conflict conflict = new Conflict();235 conflict.setContract(borrowContract);236 conflict.setId(1);237 when(conflictService.fetchConflictById(conflict.getId())).thenReturn(conflict);238 ArgumentCaptor<BorrowContract> argument = ArgumentCaptor.forClass(BorrowContract.class);239 contractService.cancelContract(1);240 verify(borrowContractRepo, times(1)).save(argument.capture());241 }242 @Test243 public void continiueContract() {244 User owner = new User();245 owner.setAccountName("owner");246 User borrower = new User();247 borrower.setAccountName("borrower");248 borrower.setId((long) 1);249 ItemRental itemRental = new ItemRental(owner);250 LocalDateTime start = LocalDateTime.now();251 LocalDateTime end = LocalDateTime.now();252 end = end.plusDays(3);253 Offer offer = new Offer(itemRental, borrower, start, end);254 borrowContract = new BorrowContract(offer);255 borrowContract.setBorrower(borrower);256 borrowContract.setId((long) 1);257 List<Conflict> conflicts = new ArrayList<>();258 borrowContract.setConflicts(conflicts);259 borrowContract.setFinished(false);260 Conflict conflict = new Conflict();261 conflict.setContract(borrowContract);262 conflict.setId(1);263 when(conflictService.fetchConflictById(conflict.getId())).thenReturn(conflict);264 ArgumentCaptor<BorrowContract> argument = ArgumentCaptor.forClass(BorrowContract.class);265 contractService.continueContract(1);266 verify(borrowContractRepo, times(1)).save(argument.capture());267 }268 269 @Test270 public void returnItemWrongAccountname() {271 boolean thrown = false;272 User owner = new User();273 owner.setAccountName("owner");274 User borrower = new User();275 borrower.setAccountName("borrower");276 borrower.setId((long) 1);277 ItemRental itemRental = new ItemRental(owner);278 LocalDateTime start = LocalDateTime.now();279 LocalDateTime end = LocalDateTime.now();280 end = end.plusDays(3);281 Offer offer = new Offer(itemRental, borrower, start, end);282 borrowContract = new BorrowContract(offer);283 borrowContract.setBorrower(borrower);284 borrowContract.setId((long) 1);285 List<Conflict> conflicts = new ArrayList<>();286 borrowContract.setConflicts(conflicts);287 borrowContract.setFinished(false);288 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);289 try {290 contractService.returnItem(1, "falseName");291 } catch (ResponseStatusException rse) {292 thrown = true;293 assertEquals("403 FORBIDDEN \"This contract does not involve you\"", rse.getMessage());294 }295 assertTrue(thrown);296 }297 @Test298 public void acceptReturnWrongPerson() {299 boolean thrown = false;300 User owner = new User();301 owner.setAccountName("owner");302 User borrower = new User();303 borrower.setAccountName("borrower");304 borrower.setId((long) 1);305 ItemRental itemRental = new ItemRental(owner);306 LocalDateTime start = LocalDateTime.now();307 LocalDateTime end = LocalDateTime.now();308 end = end.plusDays(3);309 Offer offer = new Offer(itemRental, borrower, start, end);310 borrowContract = new BorrowContract(offer);311 borrowContract.setBorrower(borrower);312 borrowContract.setId((long) 1);313 List<Conflict> conflicts = new ArrayList<>();314 borrowContract.setConflicts(conflicts);315 borrowContract.setFinished(false);316 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);317 try {318 contractService.acceptReturn(1, "falseName");319 } catch (ResponseStatusException rse) {320 thrown = true;321 assertEquals("403 FORBIDDEN \"This contract does not involve you\"", rse.getMessage());322 }323 assertTrue(thrown);324 }325 @Test326 public void validateOwnerFailure() {327 boolean thrown = false;328 User owner = new User();329 owner.setAccountName("owner");330 User borrower = new User();331 borrower.setAccountName("borrower");332 borrower.setId((long) 1);333 ItemRental itemRental = new ItemRental(owner);334 LocalDateTime start = LocalDateTime.now();335 LocalDateTime end = LocalDateTime.now();336 end = end.plusDays(3);337 Offer offer = new Offer(itemRental, borrower, start, end);338 borrowContract = new BorrowContract(offer);339 borrowContract.setBorrower(borrower);340 borrowContract.setId((long) 1);341 List<Conflict> conflicts = new ArrayList<>();342 borrowContract.setConflicts(conflicts);343 borrowContract.setFinished(false);344 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);345 try {346 contractService.validateOwner(1, "falseName");347 } catch (ResponseStatusException rse) {348 thrown = true;349 assertEquals("403 FORBIDDEN \"This contract does not involve you\"", rse.getMessage());350 }351 assertTrue(thrown);352 }353 @Test354 public void validateOwnerCorrectOwner() {355 boolean thrown = false;356 User owner = new User();357 owner.setAccountName("owner");358 User borrower = new User();359 borrower.setAccountName("borrower");360 borrower.setId((long) 1);361 ItemRental itemRental = new ItemRental(owner);362 LocalDateTime start = LocalDateTime.now();363 LocalDateTime end = LocalDateTime.now();364 end = end.plusDays(3);365 Offer offer = new Offer(itemRental, borrower, start, end);366 borrowContract = new BorrowContract(offer);367 borrowContract.setBorrower(borrower);368 borrowContract.setId((long) 1);369 List<Conflict> conflicts = new ArrayList<>();370 borrowContract.setConflicts(conflicts);371 borrowContract.setFinished(false);372 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);373 try {374 contractService.validateOwner(1, "owner");375 } catch (ResponseStatusException rse) {376 thrown = true;377 assertEquals("403 FORBIDDEN \"This contract does not involve you\"", rse.getMessage());378 }379 assertFalse(thrown);380 }381 @Test382 public void openConflictTooManyConflicts() {383 boolean thrown = false;384 User owner = new User();385 owner.setAccountName("owner");386 User borrower = new User();387 borrower.setAccountName("borrower");388 borrower.setId((long) 1);389 ItemRental itemRental = new ItemRental(owner);390 LocalDateTime start = LocalDateTime.now();391 LocalDateTime end = LocalDateTime.now();392 end = end.plusDays(3);393 Offer offer = new Offer(itemRental, borrower, start, end);394 borrowContract = new BorrowContract(offer);395 borrowContract.setBorrower(borrower);396 borrowContract.setId((long) 1);397 Conflict conflict = new Conflict();398 conflict.setContract(borrowContract);399 conflict.setId(1);400 conflict.setStatus(Status.PENDING);401 List<Conflict> conflicts = new ArrayList<>();402 conflicts.add(conflict);403 borrowContract.setConflicts(conflicts);404 borrowContract.setFinished(false);405 when(borrowContractRepo.findOneById(borrowContract.getId())).thenReturn(borrowContract);406 try {407 contractService.openConflict("desc", "owner", 1);408 } catch (ResponseStatusException rse) {409 thrown = true;410 assertEquals("400 BAD_REQUEST \"There can only be one open conflict at a time\"",411 rse.getMessage());412 }413 assertTrue(thrown);...

Full Screen

Full Screen

Source:GSPPlanFactory.java Github

copy

Full Screen

...11 * Builds mock data used for testing12 */13 public static GSPPlan getGSPPlan() {14 GSPPlan mockPlan = new GSPPlan();15 mockPlan.setId("id");16 mockPlan.setDataSharingKey("dataSharingKey");17 mockPlan.setBillingType("billingType");18 mockPlan.setBusinessDate(new Date());19 mockPlan.setCancel(false);20 mockPlan.setContractSKU("contractSKU");21 mockPlan.setContractSKUDescription("contractSKUDescription");22 mockPlan.setExpirationDate(new Date());23 mockPlan.setMonthlyPayment("monthlyPayment");24 mockPlan.setPlanType("planType");25 mockPlan.setProtectionPlanId("protectionPlanId");26 mockPlan.setRegisterTransactionNumber("registerTransactionNumber");27 mockPlan.setStoreId("storeId");28 mockPlan.setWorkstationId("workstationId");29 return mockPlan;30 }31 public static GSPPlan getGspPlan(String id, String dataSharingKey, String billingType, Date businessDate,32 boolean cancel, String contractSKU, String contractSKUDescription, Date expirationDate,33 String monthlyPayment, String planType, String protectionPlanId, String registerTransactionNumber,34 String storeId, String workstationId, String createdBy, String modifiedBy) {35 GSPPlan mockPlan = new GSPPlan();36 mockPlan.setCreatedBy(createdBy);37 mockPlan.setModifiedBy(modifiedBy);38 mockPlan.setId(id);39 mockPlan.setDataSharingKey(dataSharingKey);40 mockPlan.setBillingType(billingType);41 mockPlan.setBusinessDate(businessDate);42 mockPlan.setCancel(cancel);43 mockPlan.setContractSKU(contractSKU);44 mockPlan.setContractSKUDescription(contractSKUDescription);45 mockPlan.setExpirationDate(expirationDate);46 mockPlan.setMonthlyPayment(monthlyPayment);47 mockPlan.setPlanType(planType);48 mockPlan.setProtectionPlanId(protectionPlanId);49 mockPlan.setRegisterTransactionNumber(registerTransactionNumber);50 mockPlan.setStoreId(storeId);51 mockPlan.setWorkstationId(workstationId);52 return mockPlan;...

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1import mock.contract.Payment;2public class 4 {3 public static void main(String[] args) {4 Payment payment = new Payment();5 payment.setId(1);6 System.out.println(payment.getId());7 }8}9import mock.contract.Payment;10public class 5 {11 public static void main(String[] args) {12 Payment payment = mock(Payment.class);13 payment.setId(1);14 System.out.println(payment.getId());15 }16}17import mock.contract.Payment;18public class 6 {19 public static void main(String[] args) {20 Payment payment = mock(Payment.class);21 payment.setId(1);22 System.out.println(payment.getId());23 }24}25import mock.contract.Payment;26public class 7 {27 public static void main(String[] args) {28 Payment payment = mock(Payment.class);29 payment.setId(1);30 System.out.println(payment.getId());31 }32}33import mock.contract.Payment;34public class 8 {35 public static void main(String[] args) {36 Payment payment = mock(Payment.class);37 payment.setId(1);38 System.out.println(payment.getId());39 }40}

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1package mock.contract;2public class Payment {3private int id;4public void setId(int id) {5this.id = id;6}7public int getId() {8return id;9}10}11package mock.contract;12public class Payment {13private int id;14public void setId(int id) {15this.id = id;16}17public int getId() {18return id;19}20}21package mock.contract;22public class Payment {23private int id;24public void setId(int id) {25this.id = id;26}27public int getId() {28return id;29}30}31package mock.contract;32public class Payment {33private int id;34public void setId(int id) {35this.id = id;36}37public int getId() {38return id;39}40}41package mock.contract;42public class Payment {43private int id;44public void setId(int id) {45this.id = id;46}47public int getId() {48return id;49}50}51package mock.contract;52public class Payment {53private int id;54public void setId(int id) {55this.id = id;56}57public int getId() {58return id;59}60}61package mock.contract;62public class Payment {63private int id;64public void setId(int id) {65this.id = id;66}67public int getId() {68return id;69}70}71package mock.contract;72public class Payment {73private int id;74public void setId(int id) {75this.id = id;76}77public int getId() {78return id;79}80}81package mock.contract;82public class Payment {83private int id;84public void setId(int id) {85this.id = id;86}87public int getId() {88return id;89}90}91package mock.contract;92public class Payment {93private int id;

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1package mock.contract;2public class Payment {3 public void setId(String id) {4 }5}6package mock.contract;7public class Payment {8 public void setId(String id) {9 }10}11package mock.contract;12public class Payment {13 public void setId(String id) {14 }15}16package mock.contract;17public class Payment {18 public void setId(String id) {19 }20}21package mock.contract;22public class Payment {23 public void setId(String id) {24 }25}26package mock.contract;27public class Payment {28 public void setId(String id) {29 }30}31package mock.contract;32public class Payment {33 public void setId(String id) {34 }35}36package mock.contract;37public class Payment {38 public void setId(String id) {39 }40}41package mock.contract;42public class Payment {43 public void setId(String id) {44 }45}46package mock.contract;47public class Payment {48 public void setId(String id) {49 }50}51package mock.contract;52public class Payment {53 public void setId(String id) {54 }55}56package mock.contract;57public class Payment {58 public void setId(String id) {59 }60}

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String args[]) {3 Payment payment = new Payment();4 payment.setId(1);5 System.out.println(payment.getId());6 }7}8public class 5 {9 public static void main(String args[]) {10 Payment payment = new Payment();11 payment.setId(1);12 System.out.println(payment.getId());13 }14}15In the above example, we have also used Mockito.doThrow() method. Mockito.doThrow() method is used to set the return value of a method to an exception. It takes two parameters. The first parameter is the exception to be returned by the method and the second parameter is the method name. In the above example

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 Payment payment = new Payment();4 payment.setId(1234);5 System.out.println("Id: "+payment.getId());6 }7}8public class 5 {9 public static void main(String[] args) {10 Payment payment = new Payment();11 payment.setId(1234);12 System.out.println("Id: "+payment.getId());13 }14}15public class 6 {16 public static void main(String[] args) {17 Payment payment = new Payment();18 payment.setId(1234);19 System.out.println("Id: "+payment.getId());20 }21}22public class 7 {23 public static void main(String[] args) {24 Payment payment = new Payment();25 payment.setId(1234);26 System.out.println("Id: "+payment.getId());27 }28}29public class 8 {30 public static void main(String[] args) {31 Payment payment = new Payment();32 payment.setId(1234);33 System.out.println("Id: "+payment.getId());34 }35}36public class 9 {37 public static void main(String[] args) {38 Payment payment = new Payment();39 payment.setId(1234);40 System.out.println("Id: "+payment.getId());41 }42}43public class 10 {44 public static void main(String[] args) {45 Payment payment = new Payment();46 payment.setId(1234);47 System.out.println("Id: "+payment.getId());48 }49}50public class 11 {51 public static void main(String[] args) {52 Payment payment = new Payment();53 payment.setId(1234);54 System.out.println("Id: "+payment.getId());55 }56}

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.*;3public class PaymentTest {4 public static void main(String[] args) {5 Payment payment = new Payment();6 payment.setId(1);7 System.out.println(payment.getId());8 }9}10package mock.contract;11import java.util.*;12public class PaymentTest {13 public static void main(String[] args) {14 Payment payment = new Payment();15 payment.setId(1);16 System.out.println(payment.getId());17 }18}19package mock.contract;20import java.util.*;21public class PaymentTest {22 public static void main(String[] args) {23 Payment payment = new Payment();24 payment.setId(1);25 System.out.println(payment.getId());26 }27}28package mock.contract;29import java.util.*;30public class PaymentTest {31 public static void main(String[] args) {32 Payment payment = new Payment();33 payment.setId(1);34 System.out.println(payment.getId());35 }36}37package mock.contract;38import java.util.*;39public class PaymentTest {40 public static void main(String[] args) {41 Payment payment = new Payment();42 payment.setId(1);43 System.out.println(payment.getId());44 }45}46package mock.contract;47import java.util.*;48public class PaymentTest {49 public static void main(String[] args) {50 Payment payment = new Payment();51 payment.setId(1);52 System.out.println(payment.getId());53 }54}55package mock.contract;56import java.util.*;57public class PaymentTest {58 public static void main(String[] args) {59 Payment payment = new Payment();60 payment.setId(1);61 System.out.println(payment.getId());62 }63}64package mock.contract;65import java.util.*;66public class PaymentTest {67 public static void main(String[] args) {68 Payment payment = new Payment();69 payment.setId(1);70 System.out.println(payment.getId());

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1import mock.contract.Payment;2import mock.contract.PaymentImpl;3public class 4 {4 public static void main(String[] args) {5 Payment payment = new PaymentImpl();6 payment.setId(1);7 }8}9import mock.contract.Payment;10import mock.contract.PaymentImpl;11public class 5 {12 public static void main(String[] args) {13 Payment payment = new PaymentImpl();14 int id = payment.getId();15 }16}17import mock.contract.Payment;18import mock.contract.PaymentImpl;19public class 6 {20 public static void main(String[] args) {21 Payment payment = new PaymentImpl();22 payment.setId(1);23 int id = payment.getId();24 }25}26import mock.contract.Payment;27import mock.contract.PaymentImpl;28public class 7 {29 public static void main(String[] args) {30 Payment payment = new PaymentImpl();31 payment.setId(1);32 int id = payment.getId();33 payment.setId(2);34 }35}36import mock.contract.Payment;37import mock.contract.PaymentImpl;38public class 8 {39 public static void main(String[] args) {40 Payment payment = new PaymentImpl();41 payment.setId(1);42 int id = payment.getId();43 payment.setId(2);44 int id2 = payment.getId();45 }46}47import mock.contract.Payment;48import mock.contract.PaymentImpl;

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1package mock;2import contract.Payment;3import static org.mockito.Mockito.*;4import org.mockito.invocation.InvocationOnMock;5import org.mockito.stubbing.Answer;6import org.junit.Test;7import static org.junit.Assert.*;8public class TestMock4 {9public void testSetId() {10Payment mockPayment = mock(Payment.class);11doAnswer(new Answer() {12public Object answer(InvocationOnMock invocation) {13Object[] args = invocation.getArguments();14Object mock = invocation.getMock();15System.out.println("Method Name: "+invocation.getMethod().getName());16System.out.println("Arguments: "+args[0]);17return null;18}19}).when(mockPayment).setId(anyInt());20mockPayment.setId(10);21}22}

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.Date;3import java.util.List;4public class Payment {5 private Long id;6 private Date date;7 private List items;8 public Payment() {9 }10 public Payment(Long id, Date date, List items) {11 this.id = id;12 this.date = date;13 this.items = items;14 }15 public Long getId() {16 return id;17 }18 public void setId(Long id) {19 this.id = id;20 }21 public Date getDate() {22 return date;23 }24 public void setDate(Date date) {25 this.date = date;26 }27 public List getItems() {28 return items;29 }30 public void setItems(List items) {31 this.items = items;32 }33 public String toString() {34 return "Payment: " + id + ", " + date + ", " + items;35 }36}37package mock.contract;38import java.util.Date;39import java.util.List;40public class Payment {41 private Long id;42 private Date date;43 private List items;44 public Payment() {45 }46 public Payment(Long id, Date date, List items) {47 this.id = id;48 this.date = date;49 this.items = items;50 }51 public Long getId() {52 return id;53 }54 public void setId(Long id) {55 this.id = id;56 }57 public Date getDate() {58 return date;59 }60 public void setDate(Date date) {61 this.date = date;62 }63 public List getItems() {64 return items;65 }66 public void setItems(List items) {67 this.items = items;68 }69 public String toString() {70 return "Payment: " + id + ", " + date + ", " + items;71 }72}73package mock.contract;74import java.util.Date;75import java.util.List;76public class Payment {77 private Long id;78 private Date date;79 private List items;80 public Payment() {81 }82 public Payment(Long id, Date date, List items) {83 this.id = id;84 this.date = date;85 this.items = items;86 }87 public Long getId() {88 return id;89 }

Full Screen

Full Screen

setId

Using AI Code Generation

copy

Full Screen

1import mock.contract.Payment;2public class PaymentTest {3 public static void main(String[] args) {4 Payment payment = new Payment();5 payment.setId(10);6 }7}8import mock.contract.Payment;9import mock.contract.PaymentImpl;10public class PaymentTest {11 public static void main(String[] args) {12 Payment payment = new PaymentImpl();13 payment.setId(10);14 }15}16import mock.contract.Payment;17import mock.contract.PaymentImpl;18public class PaymentTest {19 public static void main(String[] args) {20 Payment payment = new PaymentImpl();21 payment.setId(10);22 }23}24import mock.contract.Payment;25import mock.contract.PaymentImpl;26public class PaymentTest {27 public static void main(String[] args) {28 Payment payment = new PaymentImpl();29 payment.setId(10);30 }31}32import mock.contract.Payment;33import mock.contract.PaymentImpl;34public class PaymentTest {35 public static void main(String[] args) {36 Payment payment = new PaymentImpl();37 payment.setId(10);38 }39}40import mock.contract.Payment;41import mock.contract.PaymentImpl;42public class PaymentTest {43 public static void main(String[] args) {44 Payment payment = new PaymentImpl();45 payment.setId(10);46 }47}48import mock.contract.Payment;49import mock.contract.PaymentImpl;50public class PaymentTest {51 public static void main(String[] args) {52 Payment payment = new PaymentImpl();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Karate automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful