org.eclipse.mylyn.tests.util_3.7.1.v20120425-0100

16:46:58.982 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.tests.util_3.7.1.v20120425-0100.jar
package org.eclipse.mylyn.tests.util;

public enum TestUtil$PrivilegeLevel
{
  ANONYMOUS,  GUEST,  USER,  ADMIN,  READ_ONLY;
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.TestUtil.PrivilegeLevel
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.tests.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.eclipse.mylyn.tasks.core.TaskRepository;

public class UrlBuilder
{
  private final StringBuilder buf = new StringBuilder(512);
  
  public static UrlBuilder build(TaskRepository repository)
  {
    UrlBuilder builder = new UrlBuilder();
    String url = repository.getRepositoryUrl();
    if (url.endsWith("/")) {
      url = url.substring(0, url.length() - 1);
    }
    return builder.append(url);
  }
  
  public UrlBuilder append(String urlSegment)
  {
    buf.append(urlSegment);
    return this;
  }
  
  public UrlBuilder parameter(String name, Object value)
  {
    return parameter(name, value == null ? null : value.toString());
  }
  
  public UrlBuilder parameter(String name, String value)
  {
    int indexOfQ = buf.indexOf("?");
    if (indexOfQ == -1) {
      buf.append("?");
    } else {
      buf.append("&");
    }
    buf.append(name);
    buf.append('=');
    if (value != null) {
      buf.append(encode(value));
    }
    return this;
  }
  
  private String encode(String value)
  {
    try
    {
      return URLEncoder.encode(value, "UTF-8");
    }
    catch (UnsupportedEncodingException e)
    {
      throw new IllegalStateException(e);
    }
  }
  
  public String toString()
  {
    return buf.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.UrlBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.tests.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import junit.framework.AssertionFailedError;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;

@Deprecated
public class TestUtil
{
  public static final String KEY_CREDENTIALS_FILE = "mylyn.credentials";
  
  public static enum PrivilegeLevel
  {
    ANONYMOUS,  GUEST,  USER,  ADMIN,  READ_ONLY;
  }
  
  public static class Credentials
  {
    public final String username;
    public final String password;
    
    public Credentials(String username, String password)
    {
      this.username = username;
      this.password = password;
    }
    
    public String toString()
    {
      return getClass().getSimpleName() + " [username=" + username + ",password=" + password + "]";
    }
    
    public String getShortUserName()
    {
      if (username.contains("@")) {
        return username.substring(0, username.indexOf("@"));
      }
      return username;
    }
  }
  
  public static Credentials readCredentials()
  {
    return readCredentials(PrivilegeLevel.USER, null);
  }
  
  public static Credentials readCredentials(PrivilegeLevel level)
  {
    return readCredentials(level, null);
  }
  
  public static Credentials readCredentials(PrivilegeLevel level, String realm)
  {
    Properties properties = new Properties();
    try
    {
      String filename = System.getProperty("mylyn.credentials");
      File file;
      if (filename == null)
      {
        File file;
        try
        {
          File file = getFile(TestUtil.class, "credentials.properties");
          if (file.exists()) {
            break label81;
          }
          throw new AssertionFailedError();
        }
        catch (AssertionFailedError localAssertionFailedError1)
        {
          file = new File(new File(System.getProperty("user.home"), ".mylyn"), "credentials.properties");
        }
      }
      else
      {
        file = new File(filename);
      }
      label81:
      properties.load(new FileInputStream(file));
    }
    catch (Exception e)
    {
      AssertionFailedError error = new AssertionFailedError(
        "must define credentials in $HOME/.mylyn/credentials.properties");
      error.initCause(e);
      throw error;
    }
    String defaultPassword = properties.getProperty("pass");
    
    realm = realm != null ? realm + "." : "";
    switch (level)
    {
    case ADMIN: 
      return createCredentials(properties, realm + "anon.", "", "");
    case ANONYMOUS: 
      return createCredentials(properties, realm + "guest.", "guest@mylyn.eclipse.org", defaultPassword);
    case GUEST: 
      return createCredentials(properties, realm, "tests@mylyn.eclipse.org", defaultPassword);
    case USER: 
      return createCredentials(properties, realm, "read-only@mylyn.eclipse.org", defaultPassword);
    case READ_ONLY: 
      return createCredentials(properties, realm + "admin.", "admin@mylyn.eclipse.org", null);
    }
    throw new AssertionFailedError("invalid privilege level");
  }
  
  private static Credentials createCredentials(Properties properties, String prefix, String defaultUsername, String defaultPassword)
  {
    String username = properties.getProperty(prefix + "user");
    String password = properties.getProperty(prefix + "pass");
    if (username == null) {
      username = defaultUsername;
    }
    if (password == null) {
      password = defaultPassword;
    }
    if ((username == null) || (password == null)) {
      throw new AssertionFailedError(
        "username or password not found in <plug-in dir>/credentials.properties, make sure file is valid");
    }
    return new Credentials(username, password);
  }
  
  public static File getFile(Object source, String filename)
    throws IOException
  {
    return CommonTestUtil.getFile(source, filename);
  }
  
  @Deprecated
  public static boolean runHeartbeatTestsOnly()
  {
    return !Boolean.parseBoolean(System.getProperty("org.eclipse.mylyn.tests.all"));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.TestUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.tests.util;

import java.net.Proxy;
import java.util.Arrays;
import java.util.HashSet;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.mylyn.commons.net.AbstractWebLocation;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.IProxyProvider;
import org.eclipse.mylyn.commons.net.WebLocation;
import org.eclipse.mylyn.commons.net.WebUtil;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel;
import org.eclipse.mylyn.internal.tasks.core.TaskActivationHistory;
import org.eclipse.mylyn.internal.tasks.core.TaskActivityManager;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.internal.tasks.core.externalization.ExternalizationManager;
import org.eclipse.mylyn.internal.tasks.core.externalization.TaskListExternalizationParticipant;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.ITaskActivityManager;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUi;

public abstract class TestFixture
{
  protected AbstractRepositoryConnector connector;
  private final String connectorKind;
  private String repositoryName;
  protected final String repositoryUrl;
  private String simpleInfo;
  private String description;
  private TestSuite suite;
  
  private final class Activation
    extends TestCase
  {
    private final boolean activate;
    
    private Activation(String name, boolean activate)
    {
      super();
      this.activate = activate;
    }
    
    protected void runTest()
      throws Throwable
    {
      if (activate) {
        activate();
      } else {
        getDefault().activate();
      }
    }
  }
  
  public static void resetTaskList()
    throws Exception
  {
    TasksUi.getTaskActivityManager().deactivateActiveTask();
    TasksUiPlugin.getTaskListExternalizationParticipant().resetTaskList();
    TasksUiPlugin.getTaskActivityManager().getTaskActivationHistory().clear();
    TaskListView view = TaskListView.getFromActivePerspective();
    if (view != null) {
      view.refresh();
    }
  }
  
  public static void resetTaskListAndRepositories()
    throws Exception
  {
    TasksUiPlugin.getRepositoryManager().clearRepositories();
    TasksUiPlugin.getDefault().getLocalTaskRepository();
    resetTaskList();
  }
  
  public static void saveAndReadTasklist()
    throws Exception
  {
    TasksUiPlugin.getTaskList().notifyElementsChanged(null);
    saveNow();
    resetTaskList();
    TasksUiPlugin.getDefault().initializeDataSources();
  }
  
  public static void saveNow()
    throws Exception
  {
    TasksUiPlugin.getExternalizationManager().saveNow();
  }
  
  public TestFixture(String connectorKind, String repositoryUrl)
  {
    this.connectorKind = connectorKind;
    this.repositoryUrl = repositoryUrl;
  }
  
  protected abstract TestFixture activate();
  
  public void add(Class<? extends TestCase> clazz)
  {
    Assert.isNotNull(suite, "Invoke createSuite() first");
    suite.addTestSuite(clazz);
  }
  
  protected void configureRepository(TaskRepository repository) {}
  
  public AbstractRepositoryConnector connector()
  {
    return connector;
  }
  
  public TestSuite createSuite(TestSuite parentSuite)
  {
    suite = new TestSuite("Testing on " + getInfo());
    parentSuite.addTest(suite);
    suite.addTest(new Activation("repository: " + getRepositoryUrl() + " [@" + getSimpleInfo() + "]", true, null));
    return suite;
  }
  
  public void done()
  {
    Assert.isNotNull(suite, "Invoke createSuite() first");
    suite.addTest(new Activation("done", false, null));
    suite = null;
  }
  
  public String getConnectorKind()
  {
    return connectorKind;
  }
  
  protected abstract TestFixture getDefault();
  
  public String getInfo()
  {
    return repositoryName + " " + simpleInfo;
  }
  
  public String getRepositoryUrl()
  {
    return repositoryUrl;
  }
  
  public String getSimpleInfo()
  {
    return simpleInfo;
  }
  
  public AbstractWebLocation location()
    throws Exception
  {
    return location(CommonTestUtil.PrivilegeLevel.USER);
  }
  
  public AbstractWebLocation location(CommonTestUtil.PrivilegeLevel level)
    throws Exception
  {
    return location(level, WebUtil.getProxyForUrl(repositoryUrl));
  }
  
  public AbstractWebLocation location(CommonTestUtil.PrivilegeLevel level, Proxy proxy)
    throws Exception
  {
    UserCredentials credentials = CommonTestUtil.getCredentials(level);
    return location(credentials.getUserName(), credentials.getPassword(), proxy);
  }
  
  public AbstractWebLocation location(String username, String password)
    throws Exception
  {
    return location(username, password, WebUtil.getProxyForUrl(repositoryUrl));
  }
  
  public AbstractWebLocation location(String username, String password, final Proxy proxy)
    throws Exception
  {
    new WebLocation(repositoryUrl, username, password, new IProxyProvider()
    {
      public Proxy getProxyForHost(String host, String proxyType)
      {
        return proxy;
      }
    });
  }
  
  public TaskRepository repository()
  {
    TaskRepository repository = new TaskRepository(connectorKind, repositoryUrl);
    UserCredentials credentials = CommonTestUtil.getCredentials(CommonTestUtil.PrivilegeLevel.USER);
    repository.setCredentials(AuthenticationType.REPOSITORY, 
      new AuthenticationCredentials(credentials.getUserName(), credentials.getPassword()), false);
    return repository;
  }
  
  protected void resetRepositories() {}
  
  protected void setInfo(String repositoryName, String version, String description)
  {
    Assert.isNotNull(repositoryName);
    Assert.isNotNull(version);
    this.repositoryName = repositoryName;
    simpleInfo = version;
    this.description = description;
    if ((description != null) && (description.length() > 0)) {
      simpleInfo = (simpleInfo + "/" + description);
    }
  }
  
  public TaskRepository singleRepository()
  {
    TaskRepositoryManager manager = TasksUiPlugin.getRepositoryManager();
    if (manager != null) {
      manager.clearRepositories();
    }
    resetRepositories();
    
    TaskRepository repository = new TaskRepository(connectorKind, repositoryUrl);
    UserCredentials credentials = CommonTestUtil.getCredentials(CommonTestUtil.PrivilegeLevel.USER);
    repository.setCredentials(AuthenticationType.REPOSITORY, 
      new AuthenticationCredentials(credentials.getUserName(), credentials.getPassword()), true);
    configureRepository(repository);
    if (manager != null) {
      manager.addRepository(repository);
    }
    return repository;
  }
  
  public void setUpFramework() {}
  
  public static void initializeTasksSettings()
  {
    try
    {
      TasksUiPlugin plugin = TasksUiPlugin.getDefault();
      if (plugin == null) {
        return;
      }
      IPreferenceStore store = plugin.getPreferenceStore();
      store.setValue("org.eclipse.mylyn.tasks.ui.notifications.enabled", false);
      store.setValue("org.eclipse.mylyn.tasks.ui.repositories.synch.schedule", false);
    }
    catch (NoClassDefFoundError localNoClassDefFoundError) {}
  }
  
  public boolean isExcluded()
  {
    String excludeFixture = System.getProperty("mylyn.test.exclude", "");
    String[] excludeFixtureArray = excludeFixture.split(",");
    return new HashSet(Arrays.asList(excludeFixtureArray)).contains(getRepositoryUrl());
  }
  
  public String getDescription()
  {
    return description;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.TestFixture
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.tests.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;

public class InMemoryTaskDataCollector
  extends TaskDataCollector
{
  public Map<String, IStatus> failureByTaskId;
  public List<TaskData> results;
  
  public InMemoryTaskDataCollector()
  {
    reset();
  }
  
  public void accept(TaskData taskData)
  {
    results.add(taskData);
  }
  
  public void failed(String taskId, IStatus status)
  {
    failureByTaskId.put(taskId, status);
  }
  
  public Map<String, IStatus> getFailureByTaskId()
  {
    return failureByTaskId;
  }
  
  public List<TaskData> getResults()
  {
    return results;
  }
  
  public void reset()
  {
    results = new ArrayList();
    failureByTaskId = new HashMap();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.InMemoryTaskDataCollector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.tests.util;

public class TestUtil$Credentials
{
  public final String username;
  public final String password;
  
  public TestUtil$Credentials(String username, String password)
  {
    this.username = username;
    this.password = password;
  }
  
  public String toString()
  {
    return getClass().getSimpleName() + " [username=" + username + ",password=" + password + "]";
  }
  
  public String getShortUserName()
  {
    if (username.contains("@")) {
      return username.substring(0, username.indexOf("@"));
    }
    return username;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.TestUtil.Credentials
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.tests.util;

import junit.framework.TestCase;

final class TestFixture$Activation
  extends TestCase
{
  private final boolean activate;
  
  private TestFixture$Activation(TestFixture paramTestFixture, String name, boolean activate)
  {
    super(name);
    this.activate = activate;
  }
  
  protected void runTest()
    throws Throwable
  {
    if (activate) {
      this$0.activate();
    } else {
      this$0.getDefault().activate();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.TestFixture.Activation
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.tests.util;

import java.net.Proxy;
import org.eclipse.mylyn.commons.net.IProxyProvider;

class TestFixture$1
  implements IProxyProvider
{
  TestFixture$1(TestFixture paramTestFixture, Proxy paramProxy) {}
  
  public Proxy getProxyForHost(String host, String proxyType)
  {
    return val$proxy;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.tests.util.TestFixture.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd