private boolean doVerify(
      ProdIterator l_iterator, ProdIterator s_iterator, FuncVP fvp, Map<String, String> infop) {

    if (scheme == 2) {
      for (int i = 0; i < 1200; i++) {
        if (l_iterator.hasNext() & s_iterator.hasNext()) {

          String l_product_id = XMLParser.product_id(l_iterator.next());
          String s_product_id = XMLParser.product_id(s_iterator.next());
          if (!l_product_id.equals(s_product_id)) {
            logger.error(
                " - [LOG_FAILED] - verify function 【"
                    + fvp.getFvpname()
                    + "】 for l_product_id: "
                    + l_product_id
                    + "s_product_id:"
                    + s_product_id);
            return false;
          }
        } else if (!l_iterator.hasNext() & !s_iterator.hasNext()) {
          break;
        } else {
          logger.error(
              " - [LOG_FAILED] - verify function 【"
                  + fvp.getFvpname()
                  + "】 : totalCount is not fit");
          break;
        }
      }
      // 方案3
    } else if (scheme == 3) {

    }

    return true;
  }
  // @Test(enabled = true, groups = "p2")
  public void Run(boolean flag) {
    try {
      List<String> pids = new ArrayList<String>();
      for (String url : RequestURLs) {
        logger.info("Start:" + url);
        pids.clear();
        // 取到结果集中的pid,写入list
        ProdIterator initialIterator1 = new ProdIterator(1200, url, true);
        while (initialIterator1.hasNext()) {
          Node node = initialIterator1.next(url, true);
          String pid = XMLParser.product_id(node);
          pids.add(pid);
        }

        // 这个地方文件的命名只是用来做参考
        // 需要对比的有:部署后开缓存机制&不开缓存机制;部署后第一次写入缓存&后续命中缓存;部署前&部署后;
        // 以上每组,2个结果集都应该一样
        String filepath1 =
            "E:\\manual_automation\\txtFiles\\" + RequestURLs.indexOf(url) + "_newwithcache.txt";
        String filepath2 =
            "E:\\manual_automation\\txtFiles\\" + RequestURLs.indexOf(url) + "_newnocache.txt";

        // flag代表第几次执行程序, true表示第一次,false表示第二次,这两次分别代表新、旧版本
        // 把list中的pid写入文件
        if (flag) {
          FileUtil.writeToTxt(pids.toString(), filepath1);
        } else FileUtil.writeToTxt(pids.toString(), filepath2);

        // 只有两次都跑完了,才会有前缀、后缀以_1/_2区分的文件名,然后比较一下其中的内容
        File file1 = new File(filepath1);
        File file2 = new File(filepath2);

        if (file1.exists() && file2.exists()) FileUtil.compareFiles(filepath1, filepath2);
        // compareFile(filepath1,filepath2);
        logger.info("Done:" + url);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 3
0
  @Override
  public boolean Verifier(ProdIterator iterator, Map<String, String> map) {
    // 相比当前的商品,上一个商品
    Product pre_Product = null;
    Product pre_Product_reco = null;
    try {
      // 暂时不验总商品数量
      //					int totalCount = iterator.getTotalCount();
      //					int preTotalCount = Integer.valueOf(map.get("totalCount"));
      //					if(!NumVerifier(totalCount, preTotalCount)){
      //						return false;
      //					}
      // 遍历所有商品节点,比较相邻的2个商品的价格是否按照降序排列
      while (iterator.hasNext()) {
        logger.debug("/****************************product**************************/");
        // 给product节点赋值
        Node subNode = iterator.next();
        Product product = new Product();
        product.setProduct_id(XMLParser.product_id(subNode));
        product.setDd_sale_price(XMLParser.product_dd_sale_price(subNode));
        product.setStype(XMLParser.product_stype(subNode));
        if (product.getStype().equals("")) {
          if (pre_Product == null) {
            pre_Product = product;

          } else {
            // 比较前一个商品的价格是不是比后一个商品价格高
            if (Double.valueOf(pre_Product.getDd_sale_price())
                >= Double.valueOf(product.getDd_sale_price())) {
              pre_Product = product;

            } else {
              // logger.error("Failed! Previous one is cheaper than current one;");
              logger.error(
                  " - [PRICEDESC] - "
                      + "pre_product_id:"
                      + pre_Product.getProduct_id()
                      + ";"
                      + "sale_price:"
                      + pre_Product.getDd_sale_price());
              logger.error(
                  " - [PRICEDESC] - "
                      + "product_id:"
                      + product.getProduct_id()
                      + ";"
                      + "sale_price:"
                      + product.getDd_sale_price());
              return false;
            }
          }
        } else if (product.getStype().equals("reco")) { // 推荐品排序
          if (pre_Product_reco == null) {
            pre_Product_reco = product;

          } else {
            // 比较前一个商品的价格是不是比后一个商品价格高
            if (Double.valueOf(pre_Product_reco.getDd_sale_price())
                >= Double.valueOf(product.getDd_sale_price())) {
              pre_Product_reco = product;

            } else {
              // logger.error("Failed! Previous one is cheaper than current one;");
              logger.error(
                  " - [PRICEDESC] - "
                      + "pre_product_id:"
                      + pre_Product_reco.getProduct_id()
                      + ";"
                      + "sale_price:"
                      + pre_Product_reco.getDd_sale_price());
              logger.error(
                  " - [PRICEDESC] - "
                      + "product_id:"
                      + product.getProduct_id()
                      + ";"
                      + "sale_price:"
                      + product.getDd_sale_price());
              return false;
            }
          }
        }

        logger.debug("/****************************end**************************/");
      }
    } catch (Exception e) {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      e.printStackTrace(new PrintStream(baos));
      String exception = baos.toString();
      logger.error(" - [LOG_EXCEPTION] - " + exception);
    }

    return true;
  }