@Test
 public void testGetTaskUrl() throws Exception {
   assertThat(
       connector.getTaskUrl(actualFixture.repository().getRepositoryUrl(), "123"),
       equalTo(actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/123"));
   assertThat(
       connector.getTaskUrl(actualFixture.repository().getRepositoryUrl(), "Test"),
       equalTo(actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/Test"));
 }
 @Test
 public void testGetRepositoryUrlFromTaskUrl() throws Exception {
   assertNull(
       connector.getRepositoryUrlFromTaskUrl(
           actualFixture.repository().getRepositoryUrl() + "/rest/bug/1"));
   assertThat(
       connector.getRepositoryUrlFromTaskUrl(
           actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/1"),
       equalTo(actualFixture.repository().getRepositoryUrl()));
 }
 @Test
 public void testUpdateTaskFromTaskData() throws Exception {
   TaskData taskData =
       new TaskData(
           new TaskAttributeMapper(actualFixture.repository()),
           connector.getConnectorKind(),
           actualFixture.repository().getRepositoryUrl(),
           "123");
   ITask task =
       new TaskTask(
           connector.getConnectorKind(), actualFixture.repository().getRepositoryUrl(), "");
   connector.updateTaskFromTaskData(actualFixture.repository(), task, taskData);
   assertThat(
       task.getUrl(),
       equalTo(actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/123"));
 }
  @Test
  public void testRepositoryCacheNotChanged() throws Exception {
    TaskRepository repository =
        new TaskRepository(
            actualFixture.repository().getConnectorKind(),
            actualFixture.repository().getRepositoryUrl());
    UserCredentials credentials = CommonTestUtil.getCredentials(PrivilegeLevel.USER);
    repository.setCredentials(
        org.eclipse.mylyn.commons.net.AuthenticationType.REPOSITORY,
        new AuthenticationCredentials(credentials.getUserName(), credentials.getPassword()),
        true);

    // load a configuration into the cache
    BugzillaRestConfiguration configuration = connector.getRepositoryConfiguration(repository);
    assertNotNull(configuration);

    // test that with an wrong user the configuration is removed from the cache
    String orgUserName = repository.getProperty("org.eclipse.mylyn.tasklist.repositories.username");
    repository.setProperty("org.eclipse.mylyn.tasklist.repositories.username", "xxx");
    BugzillaRestConfiguration configurationForCompare =
        connector.getRepositoryConfiguration(repository);
    assertNull(configurationForCompare);

    // load a configuration into the cache
    repository.setProperty("org.eclipse.mylyn.tasklist.repositories.username", orgUserName);
    configurationForCompare = connector.getRepositoryConfiguration(repository);
    assertThat(configuration, not(equalTo(configurationForCompare)));
    // the following three properties do not remove the entry from the cache
    repository.setProperty(RepositoryLocation.PROPERTY_LABEL, "nolabel");
    BugzillaRestConfiguration newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertEquals(configurationForCompare, newConfiguration);
    repository.setProperty(TaskRepository.OFFLINE, "false");
    newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertEquals(configurationForCompare, newConfiguration);
    repository.setProperty(TaskRepository.OFFLINE, "false");
    newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertEquals(configurationForCompare, newConfiguration);
    repository.setProperty(IRepositoryConstants.PROPERTY_ENCODING, "UTF-16");
    newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertEquals(configurationForCompare, newConfiguration);
    repository.setProperty(TaskRepository.PROXY_HOSTNAME, "nohost");
    newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertEquals(configurationForCompare, newConfiguration);
    repository.setProperty(TaskRepository.PROXY_PORT, "noport");
    newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertEquals(configurationForCompare, newConfiguration);
    repository.setProperty("org.eclipse.mylyn.tasklist.repositories.savePassword", "true");
    newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertEquals(configurationForCompare, newConfiguration);
  }
  @Test
  public void testReloadCache() throws Exception {
    connector = new BugzillaRestConnectorLocal(new Duration(5, TimeUnit.SECONDS));
    assertNotNull(connector);
    configuration = connector.getRepositoryConfiguration(actualFixture.repository());
    assertNotNull(configuration);

    // now wait until we know that the configuration is no longer valid
    // Parameter of Constructor from BugzillaRestConnector
    // (Default see BugzillaRestConnector.CONFIGURATION_CACHE_REFRESH_AFTER_WRITE_DURATION)
    BugzillaRestConfiguration configuration_new = waitAndGetConfiguration(6000L);
    assertEquals(configuration, configuration_new);

    waitForCacheRemoval();
    BugzillaRestConfiguration configuration_new1 =
        connector.getRepositoryConfiguration(actualFixture.repository());
    assertThat(configuration, not(configuration_new1));
  }
 @Test
 public void testLoadCache() throws Exception {
   BugzillaRestConfiguration configuration =
       connector.getRepositoryConfiguration(actualFixture.repository());
   assertNotNull(configuration);
   BugzillaRestConfiguration configuration_new = waitAndGetConfiguration(6000L);
   assertEquals(configuration, configuration_new);
   BugzillaRestConfiguration configuration_new1 = waitAndGetConfiguration(3000L);
   assertEquals(configuration, configuration_new1);
 }
  @Test
  public void testRepositoryCacheChanged() throws Exception {
    TaskRepository repository =
        new TaskRepository(
            actualFixture.repository().getConnectorKind(),
            actualFixture.repository().getRepositoryUrl());
    UserCredentials credentials = CommonTestUtil.getCredentials(PrivilegeLevel.USER);
    repository.setCredentials(
        org.eclipse.mylyn.commons.net.AuthenticationType.REPOSITORY,
        new AuthenticationCredentials(credentials.getUserName(), credentials.getPassword()),
        true);

    // load a configuration into the cache
    BugzillaRestConfiguration configuration = connector.getRepositoryConfiguration(repository);
    assertNotNull(configuration);

    // test that with an wrong user the configuration is removed from the cache
    String orgUserName = repository.getProperty("org.eclipse.mylyn.tasklist.repositories.username");
    repository.setProperty("org.eclipse.mylyn.tasklist.repositories.username", "xxx");
    BugzillaRestConfiguration configurationForCompare =
        connector.getRepositoryConfiguration(repository);
    assertNull(configurationForCompare);
    repository.setProperty("org.eclipse.mylyn.tasklist.repositories.username", orgUserName);
    configurationForCompare = connector.getRepositoryConfiguration(repository);
    assertNotNull(configurationForCompare);

    repository.setProperty(IRepositoryConstants.PROPERTY_TIMEZONE, "Europe/Brussels");
    BugzillaRestConfiguration newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertThat(configurationForCompare, not(equalTo(newConfiguration)));
    configurationForCompare = newConfiguration;

    repository.setProperty("version", "xxx");
    newConfiguration = connector.getRepositoryConfiguration(repository);
    assertNotNull(newConfiguration);
    assertThat(configurationForCompare, not(equalTo(newConfiguration)));
  }
 private BugzillaRestConfiguration waitAndGetConfiguration(long millis)
     throws InterruptedException, CoreException {
   Thread.sleep(millis);
   return connector.getRepositoryConfiguration(actualFixture.repository());
 }