Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 74aacebec5eff4edbbefd14dea9846331b39e357 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Martin Fluegge - initial API and implementation
 */
package org.eclipse.emf.cdo.dawn.tests;

import org.eclipse.net4j.util.om.OMPlatform;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Date;

/**
 * @author Martin Fluegge
 */
public class DawnTestPlatform
{
  public static DawnTestPlatform instance = new DawnTestPlatform();

  private String tempTestFolder = "";

  private String resourcesFolderName = "testdata";

  public DawnTestPlatform()
  {
    tempTestFolder = OMPlatform.INSTANCE.getProperty("java.io.tmpdir") + "/dawntests/test_" + new Date().getTime();
  }

  public String getTestFolder()
  {
    return tempTestFolder;
  }

  public File getTestResource(String path) throws URISyntaxException
  {
    File file = new File(getTestResourceURI(path));
    return file;
  }

  public java.net.URI getTestResourceURI(String path) throws URISyntaxException
  {
    String testFolder = getBundlePathForClass(AbstractDawnTest.class);

    String separator = path.startsWith("/") ? "" : "/";

    java.net.URI uri = new java.net.URI(testFolder + "/" + resourcesFolderName + separator + path);
    return uri;
  }

  public String getBundlePathForClass(Class<?> clazz) throws URISyntaxException
  {
    URL resourceURI = clazz.getResource("");
    return resourceURI.toString().substring(0, resourceURI.toString().lastIndexOf("/bin"));
  }
}

Back to the top