IDEA-24115: Test connection of the JIRA integration blocks Idea for 10 minutes: YouTrack too

This commit is contained in:
Dmitry Avdeev
2011-03-09 17:24:40 +03:00
parent 643cb17b67
commit 44eecd0860
2 changed files with 15 additions and 9 deletions
@@ -97,11 +97,11 @@ public abstract class BaseRepositoryImpl extends BaseRepository {
protected void configureHttpMethod(HttpMethod method) {}
public abstract class HttpTestConnection extends CancellableConnection {
public abstract class HttpTestConnection<T extends HttpMethod> extends CancellableConnection {
private HttpMethod myMethod;
private T myMethod;
public HttpTestConnection(HttpMethod method) {
public HttpTestConnection(T method) {
myMethod = method;
}
@@ -115,6 +115,6 @@ public abstract class BaseRepositoryImpl extends BaseRepository {
myMethod.abort();
}
protected abstract void doTest(HttpMethod method) throws Exception;
protected abstract void doTest(T method) throws Exception;
}
}
@@ -71,14 +71,20 @@ public class YouTrackRepository extends BaseRepositoryImpl {
return taskList.toArray(new Task[taskList.size()]);
}
public void testConnection() throws Exception {
getIssues(null, 10, 0);
@Override
public CancellableConnection createCancellableConnection() {
PostMethod method = new PostMethod(getUrl() + "/rest/user/login");
return new HttpTestConnection<PostMethod>(method) {
@Override
protected void doTest(PostMethod method) throws Exception {
login(method);
}
};
}
private HttpClient login() throws Exception {
private HttpClient login(PostMethod method) throws Exception {
HttpClient client = getHttpClient();
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword()));
PostMethod method = new PostMethod(getUrl() + "/rest/user/login");
configureHttpMethod(method);
method.addParameter("login", getUsername());
method.addParameter("password", getPassword());
@@ -111,7 +117,7 @@ public class YouTrackRepository extends BaseRepositoryImpl {
private HttpMethod doREST(String request, boolean post) throws Exception {
HttpClient client = login();
HttpClient client = login(new PostMethod(getUrl() + "/rest/user/login"));
String uri = getUrl() + request;
HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri);
configureHttpMethod(method);