Advertisement
fedorm

Untitled

Feb 13th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.58 KB | None | 0 0
  1. package ru.crystals.settester.test.operday.tablereports.adversting;
  2.  
  3.  
  4. import org.testng.Assert;
  5. import org.testng.annotations.BeforeClass;
  6. import org.testng.annotations.DataProvider;
  7. import org.testng.annotations.Test;
  8. import ru.crystals.ERPIntegration.discounts.model.xml.imp.AdvertisingActionType;
  9. import ru.crystals.cards.common.CardTypes;
  10. import ru.crystals.discount.processing.entity.LoyAdvActionInPurchaseEntity;
  11. import ru.crystals.discount.processing.entity.LoyDiscountPositionEntity;
  12. import ru.crystals.discount.processing.entity.LoyTransactionEntity;
  13. import ru.crystals.discounts.ActionType;
  14. import ru.crystals.discounts.ApplyMode;
  15. import ru.crystals.pos.check.PositionEntity;
  16. import ru.crystals.pos.check.PurchaseCardsEntity;
  17. import ru.crystals.pos.check.PurchaseEntity;
  18. import ru.crystals.pos.check.SentToServerStatus;
  19. import ru.crystals.settester.config.Config;
  20. import ru.crystals.settester.pages.testng.operday.tablereports.BonusConfigPage;
  21. import ru.crystals.settester.test.dataproviders.TableReportsDataprovider;
  22. import ru.crystals.settester.test.operday.tablereports.AbstractReportTest;
  23. import ru.crystals.settester.utils.AdverstingActionsGenerator;
  24. import ru.crystals.settester.utils.CashEmulator;
  25. import ru.crystals.settester.utils.PurchaseGenerator;
  26.  
  27. import java.util.ArrayList;
  28. import java.util.Date;
  29. import java.util.List;
  30.  
  31. import static ru.crystals.settester.pages.testng.operday.tablereports.ReportConfigPage.EXCELREPORT;
  32. import static ru.crystals.settester.pages.testng.operday.tablereports.TableReportPage.REPORT_NAME_BONUSES;
  33. import static ru.crystals.settester.pages.testng.operday.tablereports.TableReportPage.TAB_ADVERSTING;
  34.  
  35.  
  36. @Test(groups = {"centrum"})
  37. public class BonusesTableReportTest extends AbstractReportTest {
  38.     private BonusConfigPage bonusConfigPage;
  39.     private CashEmulator cashEmulator;
  40.     private PurchaseGenerator purchaseGenerator;
  41.     private AdvertisingActionType advertising;
  42.     private AdverstingActionsGenerator adverstingGenerator = new AdverstingActionsGenerator();
  43.  
  44.     @BeforeClass
  45.     public void navigateToAdverstingReport() {
  46.  
  47.         generateCheque();
  48.  
  49.         bonusConfigPage = navigateToReportConfig(
  50.                 Config.CENTRUM_URL,
  51.                 Config.MANAGER,
  52.                 Config.MANAGER_PASSWORD,
  53.                 BonusConfigPage.class,
  54.                 TAB_ADVERSTING,
  55.                 REPORT_NAME_BONUSES);
  56.  
  57.  
  58.         doHTMLReport(bonusConfigPage, true);
  59.     }
  60.  
  61.  
  62.     void generateCheque() {
  63.  
  64.         //рабочий кусок кода, без РА на начисление
  65. //        // Генерация чека
  66.         purchaseGenerator = new PurchaseGenerator();
  67.  
  68.  
  69.         cashEmulator = CashEmulator.getCashEmulator(TARGET_HOST, TARGET_SHOP, Config.CASH_NUMBER_COMMON);
  70.         cashEmulator.useNextShift();
  71.         PurchaseEntity purchaseEntity = purchaseGenerator.generatePurchaseWithPositions(2);
  72.  
  73. //
  74. //      /* сгенерить акцию */
  75. //        advertising = adverstingGenerator.generateAdverstingForCheckReport(purchaseEntity.getPositions().get(0).getName(), 10);
  76.  
  77.         PurchaseCardsEntity card = new PurchaseCardsEntity("9905100100008", CardTypes.InternalCard, purchaseEntity);
  78.         card.setCardTypeGUID(555L);
  79.         purchaseEntity.getCards().add(card);
  80. //
  81. //        LoyTransactionEntity loyTransaction;
  82. //        loyTransaction = addDiscount(purchaseEntity);
  83. //        cashEmulator.sendLoy(loyTransaction, purchaseEntity);
  84.  
  85.  
  86.         cashEmulator.nextPurchase(purchaseEntity);
  87.  
  88.     }
  89.  
  90.  
  91.     @Test(description = "SR-1972. Проверка шапки отчета",
  92.             dataProvider = "Шапка отчета по Бонусам", dataProviderClass = TableReportsDataprovider.class)
  93.     public void testBonusHTMLReportTableHead(String fieldName) {
  94.         log.info("Проверить название/наличие поля: " + fieldName);
  95.         Assert.assertTrue(htmlReportResults.containsValue(fieldName), "Неверное значение поля в шапке отчета: " + fieldName);
  96.     }
  97.  
  98.  
  99.     @Test(description = "Проверка возможности скачивания отчета в формате xls",
  100.             dataProvider = "Доступные форматы для скачивания")
  101.     public void testAdverstingSaveFormats(String reportFormat, String reportNamePattern) {
  102.         long fileSize;
  103.         fileSize = bonusConfigPage.exportFileData(chromeDownloadPath, reportNamePattern, bonusConfigPage, reportFormat).length();
  104.         log.info("Размер сохраненного файла: " + reportNamePattern + " равен " + fileSize);
  105.         Assert.assertTrue(fileSize > 0, "Файл отчета сохранился некорректно");
  106.     }
  107.  
  108.  
  109.     @DataProvider(name = "Доступные форматы для скачивания")
  110.     private Object[][] reportFormats() {
  111.         return new Object[][]{
  112.                 {EXCELREPORT, "BonusesByCards*.xls"}
  113.         };
  114.     }
  115.  
  116.  
  117.     LoyTransactionEntity addDiscount(PurchaseEntity purchase) {
  118.         LoyTransactionEntity loyTransaction = new LoyTransactionEntity();
  119.  
  120.         loyTransaction.setCashNumber(777L);
  121.         loyTransaction.setShopNumber(888L);
  122.         loyTransaction.setShiftNumber(50L);
  123.         loyTransaction.setPurchaseNumber(10L);
  124.         loyTransaction.setSaleTime(new Date());
  125.  
  126.         loyTransaction.setTransactionTime(new Date());
  127.         loyTransaction.setOperationType(purchase.isSale());
  128.  
  129.         loyTransaction.setNeedSendAccumulation(false);
  130.         loyTransaction.setNeedSendBonus(false);
  131.         loyTransaction.setNeedSendToErp(true);
  132.  
  133.         loyTransaction.setStatus(0);
  134.         loyTransaction.setSentToServerStatus(SentToServerStatus.NO_SENT);
  135.         loyTransaction.setTransactionTime(loyTransaction.getSaleTime());
  136.  
  137.         List<LoyDiscountPositionEntity> discounts = new ArrayList<>();
  138.         long sumDiscountPurchase = 0;
  139.         long sumDiscountPosition = 0;
  140.         LoyDiscountPositionEntity discountPosition = new LoyDiscountPositionEntity();
  141.         PositionEntity firstPosition = purchase.getPositions().get(0);
  142.  
  143.         discountPosition.setPositionOrder(firstPosition.getNumberInt());
  144.         discountPosition.setGoodCode(firstPosition.getItem());
  145.         discountPosition.setQnty(firstPosition.getQnty());
  146.         discountPosition.setDiscountAmount(firstPosition.getPriceEnd() / 10);
  147.         discountPosition.setDiscountFullId(advertising.getName());
  148.  
  149.         LoyAdvActionInPurchaseEntity loyAdvAction = new LoyAdvActionInPurchaseEntity();
  150.         loyAdvAction.setActionName(advertising.getName());
  151.         loyAdvAction.setGuid(Long.valueOf(advertising.getAdvertActGUID()));
  152.         loyAdvAction.setApplyMode(ApplyMode.AUTOMATIC);
  153.         loyAdvAction.setActionType(ActionType.DISCOUNT_GOODS);
  154.         loyAdvAction.setDiscountType(advertising.getDiscountType());
  155.         loyAdvAction.setExternalCode(advertising.getExternalCode());
  156.  
  157.         discountPosition.setAdvAction(loyAdvAction);
  158.         discounts.add(discountPosition);
  159.  
  160.         // скидка на чек, или на позиции
  161.         discountPosition.setDiscountPurchase(false);
  162.  
  163.         sumDiscountPosition = firstPosition.getPriceEnd() / 10;
  164.         sumDiscountPurchase = +sumDiscountPosition;
  165.  
  166.         PositionEntity purchasePosition = purchase.getPositions().get(0);
  167.         purchasePosition.setSumDiscount(sumDiscountPosition);
  168.         purchasePosition.setPriceEnd(purchasePosition.getPriceEnd() - sumDiscountPosition);
  169.  
  170.         purchase.setDiscountValueTotal(sumDiscountPurchase);
  171.         purchase.setCheckSumEnd(purchase.getCheckSumStart() - sumDiscountPurchase);
  172.  
  173.         loyTransaction.setDiscountValueTotal(sumDiscountPurchase);
  174.         loyTransaction.setDiscountPositions(discounts);
  175.  
  176.         return loyTransaction;
  177.     }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement