aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test/java/util/selenium/Selenese.java
blob: 187e33d902463ea4f5c46b38449ec486c26fb146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * SonarQube
 * Copyright (C) 2009-2017 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package util.selenium;

import com.sonar.orchestrator.Orchestrator;
import java.io.File;
import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
import org.sonarqube.tests.Tester;

/**
 * Selenium HTML tests, generally written with Selenium IDE
 * @deprecated replaced by {@link Tester}
 */
@Deprecated
public final class Selenese {

  private File[] htmlTests;

  public Selenese(Builder builder) {
    this.htmlTests = builder.htmlTests;
  }

  public File[] getHtmlTests() {
    return htmlTests;
  }

  /**
   * @deprecated replaced by {@link Tester#runHtmlTests(String...)}
   */
  @Deprecated
  public static void runSelenese(Orchestrator orchestrator, String... htmlFiles) {
    Selenese selenese = new Builder()
      .setHtmlTests(htmlFiles)
      .build();
    new SeleneseRunner().runOn(selenese, orchestrator);
  }

  private static final class Builder {
    private File[] htmlTests;

    private Builder() {
    }

    public Builder setHtmlTests(File... htmlTests) {
      this.htmlTests = htmlTests;
      return this;
    }

    public Builder setHtmlTests(String... htmlTestPaths) {
      this.htmlTests = new File[htmlTestPaths.length];
      for (int index = 0; index < htmlTestPaths.length; index++) {
        htmlTests[index] = FileUtils.toFile(getClass().getResource(htmlTestPaths[index]));
      }
      return this;
    }

    public Selenese build() {
      if (htmlTests == null || htmlTests.length == 0) {
        throw new IllegalArgumentException("HTML suite or tests are missing");
      }
      for (File htmlTest : htmlTests) {
        checkPresence(htmlTest);
      }
      return new Selenese(this);
    }

    private static void checkPresence(@Nullable File file) {
      if (file == null || !file.isFile() || !file.exists()) {
        throw new IllegalArgumentException("HTML file does not exist: " + file);
      }
    }
  }
}