Beispiel #1
0
  private void saveScenario() {
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty("file.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();

    VelocityContext context = new VelocityContext();
    context.put("protocol", protocol);
    context.put("host", host);
    context.put("port", port);
    context.put("urlBase", urlBaseString);
    context.put("proxy", configuration.getProxy());
    context.put("urls", urls);
    context.put("headers", headers);
    context.put("name", "Scenario name");

    if (listEvents.size() > EVENTS_GROUPING) {
      List<List<Object>> subListsEvents = new ArrayList<List<Object>>();
      int numberOfSubLists = listEvents.size() / EVENTS_GROUPING + 1;
      for (int i = 0; i < numberOfSubLists; i++)
        subListsEvents.add(
            listEvents.subList(
                0 + EVENTS_GROUPING * i,
                Math.min(EVENTS_GROUPING * (i + 1), listEvents.size() - 1)));

      context.put("chainEvents", subListsEvents);
      context.put("events", new ArrayList<Object>());
    } else {
      context.put("events", listEvents);
      context.put("chainEvents", new ArrayList<List<Object>>());
    }

    context.put("package", Configuration.getInstance().getIdePackage());
    context.put("date", ResultType.FORMAT.format(startDate));
    URI uri = URI.create("");
    context.put("URI", uri);

    Template template = null;
    Writer writer = null;
    for (ResultType resultType : configuration.getResultTypes()) {
      try {
        template = ve.getTemplate(resultType.getTemplate());
        writer =
            new OutputStreamWriter(
                new FileOutputStream(
                    new File(getOutputFolder(), resultType.getScenarioFileName(startDate))),
                configuration.getEncoding());
        template.merge(context, writer);
        writer.flush();

      } catch (IOException e) {
        logger.error("Error, while saving '" + resultType + "' scenario..." + e.getStackTrace());

      } finally {
        closeQuietly(writer);
      }
    }
  }
Beispiel #2
0
  private void dumpRequestBody(int idEvent, String content) {
    File dir = null;
    if (configuration.getRequestBodiesFolder() == null)
      dir =
          new File(
              getOutputFolder(),
              ResultType.FORMAT.format(startDate) + "_" + GATLING_REQUEST_BODIES_DIRECTORY_NAME);
    else dir = getFolder("request bodies", configuration.getRequestBodiesFolder());

    if (!dir.exists()) dir.mkdir();

    FileWriter fw = null;
    try {
      fw =
          new FileWriter(
              new File(dir, ResultType.FORMAT.format(startDate) + "_request_" + idEvent + ".txt"));
      fw.write(content);
    } catch (IOException ex) {
      logger.error("Error, while dumping request body... {}", ex.getStackTrace());
    } finally {
      closeQuietly(fw);
    }
  }
Beispiel #3
0
  private void saveScenario() {
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty("file.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();

    VelocityContext context = new VelocityContext();
    context.put("protocol", protocol);
    context.put("host", host);
    context.put("port", port);
    context.put("urlBase", urlBaseString);
    context.put("proxy", configuration.getProxy());
    context.put("urls", urls);
    context.put("headers", headers);
    context.put("name", "Scenario name");
    context.put("events", listEvents);
    context.put("package", Configuration.getInstance().getIdePackage());
    context.put("date", ResultType.FORMAT.format(startDate));
    URI uri = URI.create("");
    context.put("URI", uri);

    Template template = null;
    FileWriter fileWriter = null;
    for (ResultType resultType : configuration.getResultTypes()) {
      try {
        template = ve.getTemplate(resultType.getTemplate());
        fileWriter =
            new FileWriter(new File(getOutputFolder(), resultType.getScenarioFileName(startDate)));
        template.merge(context, fileWriter);
        fileWriter.flush();

      } catch (IOException e) {
        logger.error("Error, while saving '" + resultType + "' scenario..." + e.getStackTrace());

      } finally {
        closeQuietly(fileWriter);
      }
    }
  }