public void addRepository(
      final Project project,
      final RedmineRepositoryConfig config,
      final SCMConnectorConfig scmConfig,
      final String username,
      final String password)
      throws MalformedURLException, IOException, SAXException {
    login(config);
    LOGGER.info("Redmine add Repository: " + scmConfig.getScmUrl());

    // Check if Repository should be added
    if (!config.isAddRepositoryConfiguration()) {
      LOGGER.debug("Redmine Repository config is disabled.");
      return;
    }

    List<Cookie> cookies = (List<Cookie>) _wt.getDialog().getCookies();
    for (Cookie cookie : cookies) {
      _wc.putCookie(cookie.getName(), cookie.getValue());
    }
    String token = getAuthenticityToken(_wt.getPageSource());
    LOGGER.debug("Token: {}", token);

    String scm = getScmType(scmConfig);
    LOGGER.debug("SCM CONFIG: {}", scm);

    postData(config, project, scmConfig, username, password, scm);
  }
Example #2
0
  @Test(groups = "web")
  public void testUnsuccessfulLogin() throws IOException {

    tester.assertTitleEquals("Home Page");
    tester.setTextField("userName", "*****@*****.**");
    tester.setTextField("password", "xxx");
    tester.clickButtonWithText(getProperty("action.login"));
    tester.assertTextPresent("User cannot be log in");
  }
Example #3
0
 /**
  * Create a new branch
  *
  * @param pageLinkId From the TestPage, what link to click to get to new branch page
  */
 public static void seedBranch(WebTester tester, int count) {
   for (int i = 0; i < count; i++) {
     SiteTestHelper.home(tester);
     tester.clickLink("link:branches");
     tester.clickLink("branch:add");
     tester.setWorkingForm("branchForm");
     tester.setTextField("item:name", "seedBranch" + i);
     tester.clickButton("form:ok");
   }
 }
Example #4
0
  @Test(groups = "web")
  public void testEmptyFieldsLogin() throws IOException {

    tester.assertTitleEquals("Home Page");
    tester.setTextField("userName", "");
    tester.setTextField("password", "");
    tester.clickButtonWithText(getProperty("action.login"));
    tester.assertTextPresent("Field 'userName' is required");
    tester.assertTextPresent("Field 'password' is required");
  }
Example #5
0
  @BeforeMethod(groups = "web")
  public void setUp() {
    if (!personDao.usernameExists("*****@*****.**")) {
      Person person = TestUtils.createPersonForTesting("*****@*****.**", Util.ROLE_USER);
      person.setConfirmed(true);
      personDao.create(person);
    }
    tester = new WebTester();
    tester.setScriptingEnabled(false);

    //   tester.setBaseUrl("http://eeg2.kiv.zcu.cz:8080");
    tester.setBaseUrl(url);
    tester.beginAt("/home-page");
  }
  protected boolean login(final String url, final String username, final String password)
      throws MalformedURLException, IOException, SAXException {
    _wt.setBaseUrl(url);
    _wt.beginAt("/login");
    _wt.setTextField("username", username);
    _wt.setTextField("password", password);
    _wt.submit();

    if (_wt.getDialog().getPageURL().toExternalForm().endsWith("/my/page")) {
      return true;
    } else {
      return false;
    }
  }
Example #7
0
 @Test(groups = "web")
 public void testListLeftMenu() throws IOException {
   tester.clickLinkWithText(getProperty("menuItem.lists"));
   tester.assertTextPresent(getProperty("pageTitle.listOfDefinitions"));
   tester.assertLinkPresentWithText(getProperty("menuItem.hardwareDefinitions"));
   tester.assertLinkPresentWithText(getProperty("menuItem.optionalParametersForPeople"));
   tester.assertLinkPresentWithText(getProperty("menuItem.optionalParametersForExperiments"));
   tester.assertLinkPresentWithText(getProperty("menuItem.fileMetadataDefinitions"));
   tester.assertLinkPresentWithText(getProperty("menuItem.weatherDefinitions"));
   tester.assertLinkPresentWithText(getProperty("menuItem.artifactDefinitions"));
   // TODO other definitions (sw, disease, pharmaceuticals, ...)
   tester.clickLinkWithText(getProperty("action.logout"));
 }
  /**
   * @throws SAXException
   * @throws IOException
   * @throws MalformedURLException
   */
  private void postData(
      final RedmineRepositoryConfig config,
      final Project project,
      final SCMConnectorConfig scmConfig,
      final String username,
      final String password,
      final String scm) {
    LOGGER.info("Redmine add Repository: " + scmConfig.getScmUrl());

    // Check if Repository should be added
    if (!config.isAddRepositoryConfiguration()) {
      LOGGER.debug("Repository config is disabled");
      return;
    }

    List<Cookie> cookies = (List<Cookie>) _wt.getDialog().getCookies();
    for (Cookie cookie : cookies) {
      LOGGER.debug("Cookie: {}", cookie);
      _wc.putCookie(cookie.getName(), cookie.getValue());
    }

    PostMethodWebRequest form =
        new PostMethodWebRequest(
            config.getServer().getUrl() + "/projects/" + project.getName() + "/repositories");
    form.setParameter("authenticity_token", getAuthenticityToken(_wt.getPageSource()));
    form.setParameter("repository_scm", scm);
    form.setParameter("repository[url]", scmConfig.getProjectScmUrl(project.getName()));
    form.setParameter("repository[login]", username);
    form.setParameter("repository[password]", password);
    form.setParameter("commit", "Create");
    try {
      LOGGER.debug("Posting: {}", form);
      _wc.getResponse(form);
      LOGGER.debug("Posted");
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #9
0
 public static void waitForElement(WebTester tester, String xpath) {
   int timeout = 7;
   for (int i = 0; i < timeout; i++) {
     try {
       tester.getElementByXPath(xpath);
       return;
     } catch (AssertionFailedError e) {
       // keep trying
     }
     try {
       Thread.sleep(200 + i * 500);
     } catch (InterruptedException e) {
       fail(e.getMessage());
     }
   }
   fail("Element not found (timeout: " + timeout + ") - " + xpath);
 }
  @Test
  public void Test19_AdminMain_page2() {
    tester.beginAt("index.php");
    tester.setTextField("username", TestKeys.USER_ADMIN);
    tester.setTextField("password", TestKeys.PASSWORD_ADMIN);
    TestUtil.addFormTextField(
        tester, "login", "page2", "0'> <a href=\"http://unitn.it\">XSS</a> </ br '");

    tester.submit();
    tester.assertMatch("Manage Classes");

    tester.assertLinkNotPresentWithText("XSS");
  }
  @Test
  public void Test19_index_page() {
    tester.beginAt("index.php");
    tester.setWorkingForm("login");
    tester.setTextField("login", "0");
    TestUtil.addFormTextField(
        tester, "login", "page", "0'><a href='http://unitn.it'>XSS</a><br class='");
    TestUtil.addFormSubmitButton(tester, "login");
    tester.submit("submit");
    tester.assertMatch("Today's Message");

    tester.assertLinkNotPresentWithText("XSS");
  }
Example #12
0
  @BeforeMethod(groups = "web")
  public void setUp() throws IOException {
    if (!personDao.usernameExists("*****@*****.**")) {
      Person person = TestUtils.createPersonForTesting("*****@*****.**", Util.ROLE_ADMIN);
      person.setConfirmed(true);
      personDao.create(person);
    }

    tester = new WebTester();
    // tester.setBaseUrl("http://eeg2.kiv.zcu.cz:8080");
    tester.setBaseUrl(url);
    tester.beginAt("/home-page");
    tester.setTextField("userName", "*****@*****.**");
    tester.setTextField("password", "stebjan");
    tester.clickButtonWithText(getProperty("action.login"));
    tester.assertTextPresent(getProperty("action.logout"));
  }
  @Test
  public void Test19_AddTerm_page2() {
    tester.beginAt("index.php");
    tester.setTextField("username", TestKeys.USER_ADMIN);
    tester.setTextField("password", TestKeys.USER_ADMIN);
    tester.submit();

    tester.assertMatch("Manage Classes");

    tester.clickLinkWithText("Terms");
    tester.assertMatch("Manage Terms");

    tester.setWorkingForm("terms");
    tester.setTextField("page2", "8'> <a href=\"http://unitn.it\">XSS</a> </ br '");
    tester.setTextField("page", "1");

    // add submit button
    TestUtil.addFormSubmitButton(tester, "terms");
    tester.submit();

    tester.assertMatch("Add New Term");

    tester.assertLinkNotPresentWithText("XSS");
  }
 @Before
 public void setup() {
   tester = new WebTester();
   tester.setBaseUrl(TestKeys.BASE_URL);
 }
Example #15
0
  @Test(groups = "web")
  public void testListDefaultGroupsValidationAdmin() throws IOException {
    tester.clickLinkWithText(getProperty("menuItem.lists"));
    tester.assertTextPresent(getProperty("pageTitle.listOfDefinitions"));
    tester.assertLinkPresentWithText(getProperty("menuItem.hardwareDefinitions"));
    tester.clickLinkWithText(getProperty("menuItem.hardwareDefinitions"));
    tester.assertSelectOptionPresent("groups", "Default hardware");

    tester.clickLinkWithText(getProperty("menuItem.optionalParametersForPeople"));
    tester.assertSelectOptionPresent("groups", "Default optional parameters");

    tester.clickLinkWithText(getProperty("menuItem.optionalParametersForExperiments"));
    tester.assertSelectOptionPresent("groups", "Default optional parameters");

    tester.clickLinkWithText(getProperty("menuItem.fileMetadataDefinitions"));
    tester.assertSelectOptionPresent("groups", "Default metadata parameters");

    tester.clickLinkWithText(getProperty("menuItem.weatherDefinitions"));
    tester.assertSelectOptionPresent("groups", "Default weather");

    tester.clickLinkWithText(
        getProperty("menuItem.artifactDefinitions")); // Artifact do not have the Default group
    tester.assertSelectOptionNotPresent("groups", "Default artifact");

    tester.clickLinkWithText(getProperty("action.logout"));
  }
Example #16
0
  @Test(groups = "web")
  public void testListDefaultGroupsValidationUser() throws IOException {
    tester.clickLinkWithText(getProperty("action.logout"));
    if (!personDao.usernameExists("*****@*****.**")) {
      Person person = TestUtils.createPersonForTesting("*****@*****.**", Util.ROLE_USER);
      person.setConfirmed(true);
      personDao.create(person);
    }
    tester.setTextField("userName", "*****@*****.**");
    tester.setTextField("password", "stebjan");
    tester.clickButtonWithText(getProperty("action.login"));
    tester.assertTextPresent(getProperty("action.logout"));

    tester.clickLinkWithText(getProperty("menuItem.lists"));
    tester.assertTextPresent(getProperty("pageTitle.listOfDefinitions"));
    tester.assertLinkPresentWithText(getProperty("menuItem.hardwareDefinitions"));
    tester.clickLinkWithText(getProperty("menuItem.hardwareDefinitions"));
    tester.assertSelectOptionNotPresent("groups", "Default hardware");

    tester.clickLinkWithText(getProperty("menuItem.optionalParametersForPeople"));
    tester.assertSelectOptionNotPresent("groups", "Default optional parameters");

    tester.clickLinkWithText(getProperty("menuItem.optionalParametersForExperiments"));
    tester.assertSelectOptionNotPresent("groups", "Default optional parameters");

    tester.clickLinkWithText(getProperty("menuItem.fileMetadataDefinitions"));
    tester.assertSelectOptionNotPresent("groups", "Default metadata parameters");

    tester.clickLinkWithText(getProperty("menuItem.weatherDefinitions"));
    tester.assertSelectOptionNotPresent("groups", "Default weather");

    tester.clickLinkWithText(getProperty("action.logout"));
  }