Beispiel #1
0
 @Override
 @Secured
 public void removeParameter(TestExecutionParameter tep) throws ServiceException {
   TestExecution exec = testExecutionDAO.get(tep.getTestExecution().getId());
   if (exec == null) {
     throw new ServiceException(
         "serviceException.testExecutionNotFound", tep.getTestExecution().getName());
   }
   TestExecutionParameter tepRemove = testExecutionParameterDAO.get(tep.getId());
   testExecutionParameterDAO.remove(tepRemove);
 }
Beispiel #2
0
  @Override
  @Secured
  public TestExecutionParameter updateParameter(TestExecutionParameter tep)
      throws ServiceException {
    TestExecution exec = testExecutionDAO.get(tep.getTestExecution().getId());
    if (exec == null) {
      throw new ServiceException(
          "serviceException.testExecutionNotFound", tep.getTestExecution().getName());
    }
    if (testExecutionParameterDAO.hasTestParam(exec.getId(), tep)) {
      throw new ServiceException("serviceException.parameterExists", tep.getName());
    }

    return testExecutionParameterDAO.update(tep);
  }
Beispiel #3
0
  @Override
  @Secured
  public void removeTestExecution(TestExecution testExecution) throws ServiceException {
    TestExecution freshTestExecution = testExecutionDAO.get(testExecution.getId());
    if (freshTestExecution == null) {
      throw new ServiceException("serviceException.testExecutionNotFound", testExecution.getName());
    }
    for (TestExecutionParameter testExecutionParameter : freshTestExecution.getParameters()) {
      testExecutionParameterDAO.remove(testExecutionParameter);
    }
    for (Value value : freshTestExecution.getValues()) {
      for (ValueParameter valueParameter : value.getParameters()) {
        valueParameterDAO.remove(valueParameter);
      }
      valueDAO.remove(value);
    }

    Iterator<TestExecutionAttachment> allTestExecutionAttachments =
        freshTestExecution.getAttachments().iterator();
    while (allTestExecutionAttachments.hasNext()) {
      testExecutionAttachmentDAO.remove(allTestExecutionAttachments.next());
      allTestExecutionAttachments.remove();
    }
    testExecutionDAO.remove(freshTestExecution);
  }
Beispiel #4
0
 @Override
 public List<String> getParametersByPrefix(String prefix) {
   List<TestExecutionParameter> parameters = testExecutionParameterDAO.findByPrefix(prefix);
   List<String> result = new ArrayList<>();
   for (TestExecutionParameter parameter : parameters) {
     result.add(parameter.getName());
   }
   return result;
 }
Beispiel #5
0
  @Override
  public TestExecutionParameter getFullParameter(Long paramId) {
    TestExecutionParameter p = testExecutionParameterDAO.get(paramId);
    if (p == null) {
      return null;
    }

    TestExecutionParameter pclone = p.clone();
    pclone.setTestExecution(p.getTestExecution().clone());

    return pclone;
  }
Beispiel #6
0
  @Override
  @Secured
  public TestExecution createTestExecution(TestExecution testExecution) throws ServiceException {
    // The test referred by test execution has to be an existing test
    Test test = testDAO.get(testExecution.getTest().getId());
    testExecution.setTest(test);
    TestExecution storedTestExecution = testExecutionDAO.create(testExecution);
    // execution params
    if (testExecution.getParameters() != null && testExecution.getParameters().size() > 0) {
      for (TestExecutionParameter param : testExecution.getParameters()) {
        param.setTestExecution(storedTestExecution);
        testExecutionParameterDAO.create(param);
      }
    }
    // tags
    if (testExecution.getTags() != null && testExecution.getTags().size() > 0) {
      for (Tag teg : testExecution.getTags()) {
        Tag tag = tagDAO.findByName(teg.getName());
        if (tag == null) {
          tag = tagDAO.create(teg);
        }

        Collection<TestExecution> tagTestExecutions = tag.getTestExecutions();
        if (tagTestExecutions == null) {
          tag.setTestExecutions(new ArrayList<>());
        }

        tag.getTestExecutions().add(storedTestExecution);
      }
    }
    // values
    if (testExecution.getValues() != null && !testExecution.getValues().isEmpty()) {
      for (Value value : testExecution.getValues()) {
        value.setTestExecution(storedTestExecution);
        if (value.getMetricName() == null) {
          throw new IllegalArgumentException("Metric name is mandatory");
        }
        Metric metric =
            test.getMetrics()
                .stream()
                .filter(m -> m.getName().equals(value.getMetricName()))
                .findFirst()
                .get();
        if (metric == null) {
          throw new ServiceException(
              "serviceException.metricNotInTest",
              test.getName(),
              test.getId().toString(),
              value.getMetricName());
        }
        value.setMetric(metric);
        valueDAO.create(value);
        if (value.getParameters() != null && value.getParameters().size() > 0) {
          for (ValueParameter vp : value.getParameters()) {
            vp.setValue(value);
            valueParameterDAO.create(vp);
          }
        }
      }
    }

    TestExecution clone = cloneAndFetch(storedTestExecution, true, true, true, true, true);
    log.debug("Created new test execution " + clone.getId());

    alertingService.processAlerts(clone);

    return clone;
  }