@SuppressWarnings("ConstantConditions")
 private void changeStateAndCheck(String url, String key) throws Exception {
   myRepository.setUrl(url);
   Task task = myRepository.findTask(key);
   try {
     myRepository.setTaskState(task, TaskState.IN_PROGRESS);
     task = myRepository.findTask(key);
     assertEquals(task.getState(), TaskState.IN_PROGRESS);
     myRepository.setTaskState(task, TaskState.RESOLVED);
     task = myRepository.findTask(key);
     assertEquals(task.getState(), TaskState.RESOLVED);
     myRepository.setTaskState(task, TaskState.REOPENED);
     assertEquals(myRepository.findTask(key).getState(), TaskState.REOPENED);
   } catch (Exception e) {
     // always attempt to restore original state of the issue
     try {
       // transition to Resolved state usually is possible from any other
       myRepository.setTaskState(task, TaskState.RESOLVED);
     } catch (Exception ignored) {
     }
     try {
       myRepository.setTaskState(task, TaskState.REOPENED);
     } catch (Exception ignored) {
     }
     throw e;
   }
 }
 public void testLogin() throws Exception {
   myRepository.setUsername("german");
   myRepository.setUsername("wrong password");
   //noinspection ConstantConditions
   Exception exception = myRepository.createCancellableConnection().call();
   assertNotNull(exception);
   assertEquals(JiraRepository.LOGIN_FAILED_CHECK_YOUR_PERMISSIONS, exception.getMessage());
 }
 public void testGerman() throws Exception {
   myRepository.setUsername("german");
   myRepository.setPassword("german");
   Task[] issues = myRepository.getIssues(null, 50, 0);
   assertEquals(3, issues.length);
   assertEquals(TaskState.OPEN, issues[0].getState());
   assertFalse(issues[0].isClosed());
 }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   TaskSettings.getInstance().CONNECTION_TIMEOUT = 10000;
   myRepository = new JiraRepository(new JiraRepositoryType());
   myRepository.setUrl(JIRA_5_TEST_SERVER_URL);
   myRepository.setUsername("buildtest");
   myRepository.setPassword("buildtest");
 }
 /** Holds only for JIRA > 5.x.x */
 public void testExtractedErrorMessage() throws Exception {
   myRepository.setSearchQuery("foo < bar");
   try {
     myRepository.getIssues("", 50, 0);
     fail();
   } catch (Exception e) {
     assertEquals(
         "Request failed. Reason: \"Field 'foo' does not exist or you do not have permission to view it.\"",
         e.getMessage());
   }
 }
 public void testJqlQuery() throws Exception {
   myRepository.setSearchQuery(
       "assignee = currentUser() AND (summary ~ 'foo' or resolution = Fixed)");
   assertEquals(2, myRepository.getIssues("", 50, 0).length);
 }
 public void testVersionDiscovery() throws Exception {
   myRepository.setUrl(JIRA_5_TEST_SERVER_URL);
   assertEquals("2.0", myRepository.discoverRestApiVersion().getVersionName());
   myRepository.setUrl(JIRA_4_TEST_SERVER_URL);
   assertEquals("2.0.alpha1", myRepository.discoverRestApiVersion().getVersionName());
 }