Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.crystals.settester.test.operday.tablereports.adversting;
- import org.testng.Assert;
- import org.testng.annotations.BeforeClass;
- import org.testng.annotations.DataProvider;
- import org.testng.annotations.Test;
- import ru.crystals.ERPIntegration.discounts.model.xml.imp.AdvertisingActionType;
- import ru.crystals.cards.common.CardTypes;
- import ru.crystals.discount.processing.entity.LoyAdvActionInPurchaseEntity;
- import ru.crystals.discount.processing.entity.LoyDiscountPositionEntity;
- import ru.crystals.discount.processing.entity.LoyTransactionEntity;
- import ru.crystals.discounts.ActionType;
- import ru.crystals.discounts.ApplyMode;
- import ru.crystals.pos.check.PositionEntity;
- import ru.crystals.pos.check.PurchaseCardsEntity;
- import ru.crystals.pos.check.PurchaseEntity;
- import ru.crystals.pos.check.SentToServerStatus;
- import ru.crystals.settester.config.Config;
- import ru.crystals.settester.pages.testng.operday.tablereports.BonusConfigPage;
- import ru.crystals.settester.test.dataproviders.TableReportsDataprovider;
- import ru.crystals.settester.test.operday.tablereports.AbstractReportTest;
- import ru.crystals.settester.utils.AdverstingActionsGenerator;
- import ru.crystals.settester.utils.CashEmulator;
- import ru.crystals.settester.utils.PurchaseGenerator;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import static ru.crystals.settester.pages.testng.operday.tablereports.ReportConfigPage.EXCELREPORT;
- import static ru.crystals.settester.pages.testng.operday.tablereports.TableReportPage.REPORT_NAME_BONUSES;
- import static ru.crystals.settester.pages.testng.operday.tablereports.TableReportPage.TAB_ADVERSTING;
- @Test(groups = {"centrum"})
- public class BonusesTableReportTest extends AbstractReportTest {
- private BonusConfigPage bonusConfigPage;
- private CashEmulator cashEmulator;
- private PurchaseGenerator purchaseGenerator;
- private AdvertisingActionType advertising;
- private AdverstingActionsGenerator adverstingGenerator = new AdverstingActionsGenerator();
- @BeforeClass
- public void navigateToAdverstingReport() {
- generateCheque();
- bonusConfigPage = navigateToReportConfig(
- Config.CENTRUM_URL,
- Config.MANAGER,
- Config.MANAGER_PASSWORD,
- BonusConfigPage.class,
- TAB_ADVERSTING,
- REPORT_NAME_BONUSES);
- doHTMLReport(bonusConfigPage, true);
- }
- void generateCheque() {
- //рабочий кусок кода, без РА на начисление
- // // Генерация чека
- purchaseGenerator = new PurchaseGenerator();
- cashEmulator = CashEmulator.getCashEmulator(TARGET_HOST, TARGET_SHOP, Config.CASH_NUMBER_COMMON);
- cashEmulator.useNextShift();
- PurchaseEntity purchaseEntity = purchaseGenerator.generatePurchaseWithPositions(2);
- //
- // /* сгенерить акцию */
- // advertising = adverstingGenerator.generateAdverstingForCheckReport(purchaseEntity.getPositions().get(0).getName(), 10);
- PurchaseCardsEntity card = new PurchaseCardsEntity("9905100100008", CardTypes.InternalCard, purchaseEntity);
- card.setCardTypeGUID(555L);
- purchaseEntity.getCards().add(card);
- //
- // LoyTransactionEntity loyTransaction;
- // loyTransaction = addDiscount(purchaseEntity);
- // cashEmulator.sendLoy(loyTransaction, purchaseEntity);
- cashEmulator.nextPurchase(purchaseEntity);
- }
- @Test(description = "SR-1972. Проверка шапки отчета",
- dataProvider = "Шапка отчета по Бонусам", dataProviderClass = TableReportsDataprovider.class)
- public void testBonusHTMLReportTableHead(String fieldName) {
- log.info("Проверить название/наличие поля: " + fieldName);
- Assert.assertTrue(htmlReportResults.containsValue(fieldName), "Неверное значение поля в шапке отчета: " + fieldName);
- }
- @Test(description = "Проверка возможности скачивания отчета в формате xls",
- dataProvider = "Доступные форматы для скачивания")
- public void testAdverstingSaveFormats(String reportFormat, String reportNamePattern) {
- long fileSize;
- fileSize = bonusConfigPage.exportFileData(chromeDownloadPath, reportNamePattern, bonusConfigPage, reportFormat).length();
- log.info("Размер сохраненного файла: " + reportNamePattern + " равен " + fileSize);
- Assert.assertTrue(fileSize > 0, "Файл отчета сохранился некорректно");
- }
- @DataProvider(name = "Доступные форматы для скачивания")
- private Object[][] reportFormats() {
- return new Object[][]{
- {EXCELREPORT, "BonusesByCards*.xls"}
- };
- }
- LoyTransactionEntity addDiscount(PurchaseEntity purchase) {
- LoyTransactionEntity loyTransaction = new LoyTransactionEntity();
- loyTransaction.setCashNumber(777L);
- loyTransaction.setShopNumber(888L);
- loyTransaction.setShiftNumber(50L);
- loyTransaction.setPurchaseNumber(10L);
- loyTransaction.setSaleTime(new Date());
- loyTransaction.setTransactionTime(new Date());
- loyTransaction.setOperationType(purchase.isSale());
- loyTransaction.setNeedSendAccumulation(false);
- loyTransaction.setNeedSendBonus(false);
- loyTransaction.setNeedSendToErp(true);
- loyTransaction.setStatus(0);
- loyTransaction.setSentToServerStatus(SentToServerStatus.NO_SENT);
- loyTransaction.setTransactionTime(loyTransaction.getSaleTime());
- List<LoyDiscountPositionEntity> discounts = new ArrayList<>();
- long sumDiscountPurchase = 0;
- long sumDiscountPosition = 0;
- LoyDiscountPositionEntity discountPosition = new LoyDiscountPositionEntity();
- PositionEntity firstPosition = purchase.getPositions().get(0);
- discountPosition.setPositionOrder(firstPosition.getNumberInt());
- discountPosition.setGoodCode(firstPosition.getItem());
- discountPosition.setQnty(firstPosition.getQnty());
- discountPosition.setDiscountAmount(firstPosition.getPriceEnd() / 10);
- discountPosition.setDiscountFullId(advertising.getName());
- LoyAdvActionInPurchaseEntity loyAdvAction = new LoyAdvActionInPurchaseEntity();
- loyAdvAction.setActionName(advertising.getName());
- loyAdvAction.setGuid(Long.valueOf(advertising.getAdvertActGUID()));
- loyAdvAction.setApplyMode(ApplyMode.AUTOMATIC);
- loyAdvAction.setActionType(ActionType.DISCOUNT_GOODS);
- loyAdvAction.setDiscountType(advertising.getDiscountType());
- loyAdvAction.setExternalCode(advertising.getExternalCode());
- discountPosition.setAdvAction(loyAdvAction);
- discounts.add(discountPosition);
- // скидка на чек, или на позиции
- discountPosition.setDiscountPurchase(false);
- sumDiscountPosition = firstPosition.getPriceEnd() / 10;
- sumDiscountPurchase = +sumDiscountPosition;
- PositionEntity purchasePosition = purchase.getPositions().get(0);
- purchasePosition.setSumDiscount(sumDiscountPosition);
- purchasePosition.setPriceEnd(purchasePosition.getPriceEnd() - sumDiscountPosition);
- purchase.setDiscountValueTotal(sumDiscountPurchase);
- purchase.setCheckSumEnd(purchase.getCheckSumStart() - sumDiscountPurchase);
- loyTransaction.setDiscountValueTotal(sumDiscountPurchase);
- loyTransaction.setDiscountPositions(discounts);
- return loyTransaction;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement