IDEA-138740 During test connection additionally check that Redmine projects can be downloaded

This commit is contained in:
Mikhail Golubev
2015-04-03 16:00:26 +03:00
parent f68172c36d
commit 149557ac59
2 changed files with 36 additions and 14 deletions
@@ -133,8 +133,13 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
HttpResponse httpResponse = client.execute(myCurrentRequest);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
myCurrentRequest = new HttpGet(getIssuesUrl(0, 1, true));
// Check that projects can be downloaded via given URL and the latter is not project-specific
myCurrentRequest = new HttpGet(getProjectsUrl(0, 1));
statusLine = client.execute(myCurrentRequest).getStatusLine();
if (statusLine != null && statusLine.getStatusCode() == HttpStatus.SC_OK) {
myCurrentRequest = new HttpGet(getIssuesUrl(0, 1, true));
statusLine = client.execute(myCurrentRequest).getStatusLine();
}
}
if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) {
throw RequestFailedException.forStatusCode(statusLine.getStatusCode(), statusLine.getReasonPhrase());
@@ -192,14 +197,8 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
int offset = 0;
ProjectsWrapper wrapper;
do {
URIBuilder builder = new URIBuilder(getRestApiUrl("projects.json"));
builder.addParameter("offset", String.valueOf(offset));
builder.addParameter("limit", "50");
if (isUseApiKeyAuthentication()) {
builder.addParameter("key", myAPIKey);
}
HttpGet method = new HttpGet(builder.toString());
HttpGet method = new HttpGet(getProjectsUrl(offset, 50));
wrapper = client.execute(method, new GsonSingleObjectDeserializer<ProjectsWrapper>(GSON, ProjectsWrapper.class));
offset += wrapper.getProjects().size();
allProjects.addAll(wrapper.getProjects());
@@ -210,6 +209,17 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
return Collections.unmodifiableList(myProjects);
}
@NotNull
private URI getProjectsUrl(int offset, int limit) throws URISyntaxException {
URIBuilder builder = new URIBuilder(getRestApiUrl("projects.json"));
builder.addParameter("offset", String.valueOf(offset));
builder.addParameter("limit", String.valueOf(limit));
if (isUseApiKeyAuthentication()) {
builder.addParameter("key", myAPIKey);
}
return builder.build();
}
@Nullable
@Override
public Task findTask(@NotNull String id) throws Exception {
@@ -17,7 +17,7 @@ import java.util.List;
* @author Mikhail Golubev
*/
public class RedmineIntegrationTest extends TaskManagerTestCase {
private static final String REDMINE_2_0_TEST_SERVER_URL = "http://trackers-tests.labs.intellij.net:8072/";
private static final String REDMINE_2_0_TEST_SERVER_URL = "http://trackers-tests.labs.intellij.net:8072";
private RedmineRepository myRepository;
@@ -73,16 +73,28 @@ public class RedmineIntegrationTest extends TaskManagerTestCase {
assertEquals("prj-1 7 7 Summary contains 'baz'", TaskUtil.getChangeListComment(localTask));
}
/**
* Redmine doesn't send 401 or 403 errors, when issues are downloaded with wrong credentials, so current user information is
* fetched instead.
*/
// IDEA-122845
// Redmine doesn't send 401 or 403 errors, when issues are downloaded with wrong credentials (and anonymous access is allowed),
// so current user information is fetched instead.
public void testCredentialsCheck() throws Exception {
myRepository.setPassword("wrong-password");
try {
//noinspection ConstantConditions
final Exception exception = myRepository.createCancellableConnection().call();
assertNotNull("Test connection must fail when wrong credentials specified", exception);
assertNotNull("Test connection must fail when wrong credentials are specified", exception);
}
catch (Exception e) {
assertEquals(TaskBundle.message("failure.login"), e.getMessage());
}
}
// IDEA-138740
public void testProjectSpecificUrlCheck() throws Exception {
myRepository.setUrl(REDMINE_2_0_TEST_SERVER_URL + "/projects/prj-1");
try {
//noinspection ConstantConditions
final Exception exception = myRepository.createCancellableConnection().call();
assertNotNull("Test connection must fail when project-specific URL is specified", exception);
}
catch (Exception e) {
assertEquals(TaskBundle.message("failure.login"), e.getMessage());