Esempio n. 1
0
  @Override
  public void addTagsToTestExecutions(
      Collection<String> tags, Collection<TestExecution> testExecutions) {
    for (TestExecution testExecutionItem : testExecutions) {
      TestExecution testExecution = testExecutionDAO.get(testExecutionItem.getId());
      if (testExecution == null) {
        continue;
      }

      for (String tagName : tags) {
        if (!testExecution.getTags().contains(tagName)) {
          Tag tag = tagDAO.findByName(tagName);
          if (tag == null) {
            Tag newTag = new Tag();
            newTag.setName(tagName);
            tag = tagDAO.create(newTag);
          }

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

          tag.getTestExecutions().add(testExecution);
          testExecution.getTags().add(tag);
        }
      }

      testExecutionDAO.update(testExecution);
    }
  }
Esempio n. 2
0
  @Override
  @Secured
  public TestExecution updateTestExecution(TestExecution testExecution) throws ServiceException {
    TestExecution execEntity = testExecutionDAO.get(testExecution.getId());
    if (execEntity == null) {
      throw new ServiceException("serviceException.testExecutionNotFound", testExecution.getName());
    }
    // this is what can be updated here
    execEntity.setName(testExecution.getName());
    execEntity.setStarted(testExecution.getStarted());
    execEntity.setComment(testExecution.getComment());
    execEntity.setTags(new ArrayList<>());

    for (Tag tag : testExecution.getTags()) {
      Tag tagEntity = tagDAO.findByName(tag.getName());
      if (tagEntity == null) {
        Tag newTag = new Tag();
        newTag.setName(tag.getName());
        tagEntity = tagDAO.create(newTag);
      }

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

      tagEntity.getTestExecutions().add(execEntity);
      execEntity.getTags().add(tagEntity);
    }
    TestExecution execClone = cloneAndFetch(execEntity, true, true, true, true, true);
    return execClone;
  }
Esempio n. 3
0
 @Override
 public List<String> getTagsByPrefix(String prefix) {
   List<String> tags = new ArrayList<String>();
   for (Tag tag : tagDAO.findByPrefix(prefix)) {
     tags.add(tag.getName());
   }
   return tags;
 }
Esempio n. 4
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;
  }