예제 #1
0
 public void testLoginInvalidCredentials() throws Exception {
   RedmineRepository redmineRepository = new RedmineRepository();
   Project project = new Project();
   project.setName("example");
   RedmineRepositoryConfig config = new RedmineRepositoryConfig();
   config.username = "******";
   config.password = "******";
   Server server = new Server();
   server.setUrl("http://redmine.jabox.org/");
   config.setServer(server);
   boolean login = redmineRepository.login(config);
   assertFalse(login);
 }
예제 #2
0
  public boolean addProject(final Project project, final RedmineRepositoryConfig config)
      throws IOException, SAXException {
    LOGGER.info("Redmine add Project: " + project.getName());
    _redmineProject = new com.taskadapter.redmineapi.bean.Project();
    _redmineProject.setName(project.getName());
    _redmineProject.setIdentifier(getRedmineId(project));
    _redmineProject.setDescription(project.getDescription());

    try {
      _redmineProject = _mgr.createProject(_redmineProject);
      return true;
    } catch (RedmineException e) {
      e.printStackTrace();
      return false;
    }
  }
예제 #3
0
  /**
   * @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();
    }
  }
예제 #4
0
  public void testLoginValidCredentials() throws Exception {
    RedmineRepository redmineRepository = new RedmineRepository();
    Project project = new Project();
    project.setName("example");
    project.setDescription("example description");
    RedmineRepositoryConfig config = new RedmineRepositoryConfig();
    config.username = "******";
    config.password = "******";
    Server server = new Server();
    server.setUrl("http://redmine.jabox.org/");
    config.setServer(server);
    boolean login = redmineRepository.login(config);
    assertTrue(login);
    redmineRepository.addProject(project, config);
    SCMConnectorConfig scmConfig =
        new SCMConnectorConfig() {
          private static final long serialVersionUID = 6864333280150931583L;

          @Override
          public Long getId() {
            return null;
          }

          @Override
          public Server getServer() {
            return null;
          }

          @Override
          public String getPluginId() {
            return null;
          }

          @Override
          public String getUsername() {
            return null;
          }

          @Override
          public String getScmUrl() {
            return "http://www.jabox.org/";
          }

          @Override
          public String getScmMavenPrefix() {
            return null;
          }

          @Override
          public String getProjectScmUrl(String projectName) {
            return null;
          }

          @Override
          public String getPassword() {
            return null;
          }
        };
    config.setAddRepositoryConfiguration(true);
    redmineRepository.addRepository(project, config, scmConfig, config.username, config.password);
  }
예제 #5
0
 private String getRedmineId(final Project project) {
   return project.getName();
 }