mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Mantis support. Integration test.
This commit is contained in:
@@ -319,6 +319,7 @@ public class GitHubRepository extends BaseRepositoryImpl {
|
||||
return matcher.find() ? matcher.group(1) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(String id) throws Exception {
|
||||
String path = "/repos/" + getRepoAuthor() + "/" + getRepoName() + "/issues/" + id;
|
||||
|
||||
@@ -173,6 +173,7 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
return postMethod;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CancellableConnection createCancellableConnection() {
|
||||
PostMethod method = getLoginMethodFor4x();
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,9 +23,9 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
@Tag("Generic")
|
||||
public class GenericWebRepository extends BaseRepositoryImpl {
|
||||
private String myTasksListURL;
|
||||
private String myTaskPattern;
|
||||
private String myLoginURL;
|
||||
private String myTasksListURL = "";
|
||||
private String myTaskPattern = "";
|
||||
private String myLoginURL = "";
|
||||
|
||||
final static String SERVER_URL_PLACEHOLDER = "{serverUrl}";
|
||||
final static String USERNAME_PLACEHOLDER = "{username}";
|
||||
@@ -132,18 +131,16 @@ public class GenericWebRepository extends BaseRepositoryImpl {
|
||||
return new GenericWebRepository(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTasksListURL() {
|
||||
return myTasksListURL == null ? "" : myTasksListURL;
|
||||
return myTasksListURL;
|
||||
}
|
||||
|
||||
public void setTasksListURL(final String tasksListURL) {
|
||||
myTasksListURL = tasksListURL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTaskPattern() {
|
||||
return myTaskPattern == null ? "" : myTaskPattern;
|
||||
return myTaskPattern;
|
||||
}
|
||||
|
||||
public void setTaskPattern(final String taskPattern) {
|
||||
@@ -178,9 +175,8 @@ public class GenericWebRepository extends BaseRepositoryImpl {
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLoginURL() {
|
||||
return myLoginURL == null ? "" : myLoginURL;
|
||||
return myLoginURL;
|
||||
}
|
||||
|
||||
public void setLoginURL(final String loginURL) {
|
||||
|
||||
@@ -254,6 +254,7 @@ public class LighthouseRepository extends BaseRepositoryImpl {
|
||||
method.addRequestHeader("X-LighthouseToken", myAPIKey);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(String id) throws Exception {
|
||||
final String[] split = id.split("\\-");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.intellij.tasks.mantis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: evgeny.zakrevsky
|
||||
* Date: 9/24/12
|
||||
@@ -7,6 +9,8 @@ package com.intellij.tasks.mantis;
|
||||
public class MantisProject {
|
||||
public final static MantisProject ALL_PROJECTS = new MantisProject(0, "All Projects");
|
||||
|
||||
private List<MantisFilter> myFilters;
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
@@ -35,6 +39,14 @@ public class MantisProject {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<MantisFilter> getFilters() {
|
||||
return myFilters;
|
||||
}
|
||||
|
||||
public void setFilters(final List<MantisFilter> filters) {
|
||||
myFilters = filters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return obj != null && obj instanceof MantisProject && ((MantisProject)obj).getId() == getId();
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.intellij.tasks.mantis.model.*;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import org.apache.axis.utils.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -21,8 +20,6 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
@@ -31,7 +28,7 @@ import java.util.Set;
|
||||
public class MantisRepository extends BaseRepositoryImpl {
|
||||
private final static String SOAP_API_LOCATION = "/api/soap/mantisconnect.php";
|
||||
|
||||
private Map<MantisProject, List<MantisFilter>> myProject2FiltersCachedData;
|
||||
private List<MantisProject> myProjects;
|
||||
|
||||
private MantisProject myProject;
|
||||
private MantisFilter myFilter;
|
||||
@@ -93,6 +90,7 @@ public class MantisRepository extends BaseRepositoryImpl {
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(String id) throws Exception {
|
||||
IssueData data = createSoap().mc_issue_get(getUsername(), getPassword(), BigInteger.valueOf(Integer.valueOf(id)));
|
||||
@@ -145,23 +143,23 @@ public class MantisRepository extends BaseRepositoryImpl {
|
||||
return task;
|
||||
}
|
||||
|
||||
public Set<MantisProject> getProjects() throws Exception {
|
||||
if (myProject2FiltersCachedData == null) {
|
||||
public List<MantisProject> getProjects() throws Exception {
|
||||
if (myProjects == null) {
|
||||
refreshProjectAndFiltersData();
|
||||
}
|
||||
return myProject2FiltersCachedData.keySet();
|
||||
return myProjects;
|
||||
}
|
||||
|
||||
public List<MantisFilter> getFilters(MantisProject project) throws Exception {
|
||||
if (myProject2FiltersCachedData == null) {
|
||||
if (myProjects == null) {
|
||||
refreshProjectAndFiltersData();
|
||||
}
|
||||
return myProject2FiltersCachedData.get(project);
|
||||
return project.getFilters();
|
||||
}
|
||||
|
||||
public void refreshProjectAndFiltersData() throws Exception {
|
||||
final MantisConnectPortType soap = createSoap();
|
||||
myProject2FiltersCachedData = new HashMap<MantisProject, List<MantisFilter>>();
|
||||
myProjects = new ArrayList<MantisProject>();
|
||||
ProjectData[] projectDatas = soap.mc_projects_get_user_accessible(getUsername(), getPassword());
|
||||
List<MantisProject> projects = ContainerUtil.map(projectDatas, new Function<ProjectData, MantisProject>() {
|
||||
@Override
|
||||
@@ -169,7 +167,7 @@ public class MantisRepository extends BaseRepositoryImpl {
|
||||
return new MantisProject(data.getId().intValue(), data.getName());
|
||||
}
|
||||
});
|
||||
projects.add(MantisProject.ALL_PROJECTS);
|
||||
projects.add(0, MantisProject.ALL_PROJECTS);
|
||||
String version = soap.mc_version();
|
||||
for (MantisProject project : projects) {
|
||||
FilterData[] filterDatas = soap.mc_filter_get(getUsername(), getPassword(), BigInteger.valueOf(project.getId()));
|
||||
@@ -183,7 +181,8 @@ public class MantisRepository extends BaseRepositoryImpl {
|
||||
return new MantisFilter(data.getId().intValue(), data.getName());
|
||||
}
|
||||
}));
|
||||
myProject2FiltersCachedData.put(project, filters);
|
||||
project.setFilters(filters);
|
||||
myProjects.add(project);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.intellij.tasks.mantis;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.tasks.config.BaseRepositoryEditor;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.Consumer;
|
||||
@@ -34,7 +35,7 @@ public class MantisRepositoryEditor extends BaseRepositoryEditor<MantisRepositor
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (!myRepository.getUrl().equals(myURLText.getText()) ||
|
||||
if (!myRepository.getUrl().equals(StringUtil.trimEnd(myURLText.getText(), "/")) ||
|
||||
!myRepository.getUsername().equals(myUserNameText.getText()) ||
|
||||
!myRepository.getPassword().equals(myPasswordText.getText())) {
|
||||
resetComboBoxes();
|
||||
|
||||
@@ -258,6 +258,7 @@ public class PivotalTrackerRepository extends BaseRepositoryImpl {
|
||||
return method;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(final String id) throws Exception {
|
||||
final String realId = getRealId(id);
|
||||
@@ -316,6 +317,7 @@ public class PivotalTrackerRepository extends BaseRepositoryImpl {
|
||||
return name + (!StringUtil.isEmpty(getProjectId()) ? "/" + getProjectId() : "");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTaskComment(final Task task) {
|
||||
if (isShouldFormatCommitMessage()) {
|
||||
|
||||
@@ -240,6 +240,7 @@ public class RedmineRepository extends BaseRepositoryImpl {
|
||||
return method;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(String id) throws Exception {
|
||||
final String realId = getRealId(id);
|
||||
|
||||
@@ -100,6 +100,7 @@ public class TracRepository extends BaseRepositoryImpl {
|
||||
return new XmlRpcClient(getUrl());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(String id) throws Exception {
|
||||
return getTask(Integer.parseInt(id), getRpcClient(), new Transport());
|
||||
@@ -142,6 +143,7 @@ public class TracRepository extends BaseRepositoryImpl {
|
||||
return o instanceof Date ? (Date)o : new Date((Integer)o * 1000l);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CancellableConnection createCancellableConnection() {
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ public class YouTrackRepository extends BaseRepositoryImpl {
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CancellableConnection createCancellableConnection() {
|
||||
PostMethod method = new PostMethod(getUrl() + "/rest/user/login");
|
||||
@@ -133,6 +134,7 @@ public class YouTrackRepository extends BaseRepositoryImpl {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Task findTask(String id) throws Exception {
|
||||
HttpMethod method = doREST("/rest/issue/byid/" + id, false);
|
||||
InputStream stream = method.getResponseBodyAsStream();
|
||||
|
||||
@@ -35,6 +35,7 @@ class TestRepository extends BaseRepository {
|
||||
return ContainerUtil.newArrayList(myTasks);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(final String id) throws Exception {
|
||||
return ContainerUtil.find(myTasks, new Condition<Task>() {
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.intellij.tasks.integration;
|
||||
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.TaskManagerTestCase;
|
||||
import com.intellij.tasks.mantis.MantisFilter;
|
||||
import com.intellij.tasks.mantis.MantisProject;
|
||||
import com.intellij.tasks.mantis.MantisRepository;
|
||||
import com.intellij.tasks.mantis.MantisRepositoryType;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: evgeny.zakrevsky
|
||||
* Date: 10/12/12
|
||||
*/
|
||||
public class MantisIntegrationTest extends TaskManagerTestCase {
|
||||
public void testMantis12() throws Exception {
|
||||
MantisRepository mantisRepository = new MantisRepository(new MantisRepositoryType());
|
||||
mantisRepository.setUrl("http://trackers-tests.labs.intellij.net:8142/");
|
||||
mantisRepository.setUsername("guest");
|
||||
mantisRepository.setPassword("guest");
|
||||
myManager.testConnection(mantisRepository);
|
||||
|
||||
assertTrue(mantisRepository.getProjects().size() >= 2);
|
||||
final MantisProject mantisProject = mantisRepository.getProjects().get(1);
|
||||
assertEquals(mantisProject.getName(), "Mantis 1.2 project 1");
|
||||
mantisRepository.setProject(mantisProject);
|
||||
|
||||
assertTrue(mantisProject.getFilters().size() >= 2);
|
||||
final MantisFilter mantisFilter = mantisProject.getFilters().get(1);
|
||||
assertEquals(mantisFilter.getName(), "Mantis 1.2 Filter 1");
|
||||
mantisRepository.setFilter(mantisFilter);
|
||||
|
||||
final List<Task> issues = mantisRepository.getIssues("", 1, 0);
|
||||
assertTrue(issues.size() >= 1);
|
||||
final Task task = issues.get(0);
|
||||
assertEquals(task.getId(), "1");
|
||||
assertEquals(task.getProject(), "Mantis 1.2 project 1");
|
||||
assertEquals(task.getNumber(), "1");
|
||||
assertEquals(task.getSummary(), "M12P1I1");
|
||||
|
||||
final Task task1 = mantisRepository.findTask("1");
|
||||
assertNotNull(task1);
|
||||
assertEquals(task1.getId(), "1");
|
||||
assertEquals(task1.getProject(), "Mantis 1.2 project 1");
|
||||
assertEquals(task1.getNumber(), "1");
|
||||
assertEquals(task1.getSummary(), "M12P1I1");
|
||||
assertEquals(task1.getDescription(), ".");
|
||||
|
||||
HttpClient client = new HttpClient();
|
||||
final GetMethod method = new GetMethod(task1.getIssueUrl());
|
||||
client.executeMethod(method);
|
||||
assertEquals(method.getStatusCode(), 200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user