예제 #1
0
  @Restrict(UnitRole.DEFECTCREATE)
  public static void createDefect(@Valid Defect defect) {
    defect.submittedBy = getConnectedUser();
    defect.account = getConnectedUserAccount();
    defect.project = getActiveProject();
    defect.status = DefectStatus.getDefaultDefectStatus();
    boolean created = defect.create();
    if (!created) {
      Logger.error(Logger.LogType.DB, "Error while creating defect");
      error("An error occurred while saving the defect, please try again");
    }

    // linking to test instance
    String runIdParam = params.get("runId");
    if (StringUtils.isNotEmpty(runIdParam)) {
      try {
        Long runId = Long.valueOf(runIdParam);
        if (runId != null) {
          Instance instance =
              Run.find("select r.instance from Run r where r.id = ?", runId).first();
          instance.defects.add(defect);
          try {
            instance.save();
          } catch (Throwable t) {
            Logger.error(
                Logger.LogType.DB,
                "Error while updating defect instance during linking to defefct %s",
                defect.getId());
            error(
                String.format(
                    "An error occurred while linking the newly created defect %s to test instance %s. Please try again.",
                    defect.naturalId, instance.naturalId));
          }
        }
      } catch (NumberFormatException nfe) {
        Logger.error(
            Logger.LogType.SECURITY,
            "Invalid value '%s' for runId parameter passed during defect creation",
            runIdParam);
        error();
      }
    }

    ok();
  }
예제 #2
0
  public static void create(Long runId) {
    boolean createDefect = true;

    List<RunStep> runSteps =
        RunStep.find("from RunStep rs where rs.run.id=? and rs.status=3", runId).fetch();
    Instance instance = Run.find("select r.instance from Run r where r.id=?", runId).first();

    String defectDescription = "Test instance ran: " + instance.name;

    for (RunStep runStep : runSteps) {
      defectDescription =
          defectDescription
              + "\\n\\nExpected result: "
              + runStep.getExpectedResultText()
              + "\\nActual result: "
              + runStep.actualResult;
    }

    render("Defects/index.html", createDefect, runId, defectDescription);
  }