Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 112 additions & 20 deletions apiconnector/src/test/java/testbase/BaseTestFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,130 @@

import com.thoughtworks.xstream.XStream;


// important that name does not start with test
public class BaseTestFramework {

protected static final String url_test = "https://test.openml.org/";
// TODO(Jos): make it easy to switch to local testing on the docker compose
// protected static final String url_test = "http://localhost:8080/"; // openml-service (docker compose)

protected static final String url_live = "https://www.openml.org/";
protected static final OpenmlConnector client_admin_test = new OpenmlConnector(url_test,"d488d8afd93b32331cf6ea9d7003d4c3");
// protected static final OpenmlConnector client_admin_test = new OpenmlConnector(url_test,"AD000000000000000000000000000000"); // openml-service (docker compose)

protected static final OpenmlConnector client_write_test = new OpenmlConnector(url_test, "8baa83ecddfe44b561fd3d92442e3319");
// protected static final OpenmlConnector client_write_test = new OpenmlConnector(url_test, "AD000000000000000000000000000000"); // openml-service (docker compose)
protected static final OpenmlConnector client_read_test = new OpenmlConnector(url_test, "6a4e0925273c6c9e2709b8b5179755c2"); // user id 3345, vanrijn@freiburg
// protected static final OpenmlConnector client_read_test = new OpenmlConnector(url_test, "AD000000000000000000000000000000"); // openml-service (docker compose)
protected static final OpenmlConnector client_read_live = new OpenmlConnector(url_live, "c1994bdb7ecb3c6f3c8f3b35f4b47f1f");

private static final ServerConfig test_server = new StagingServerConfig();

protected static final String subdomain_test = test_server.subdomain();
protected static final String url_test = test_server.url();
private static final String url_live = "https://www.openml.org/";

protected static final OpenmlConnector client_admin_test = new OpenmlConnector(url_test, test_server.apiKeyAdmin());
protected static final OpenmlConnector client_write_test = new OpenmlConnector(url_test, test_server.apiKeyWrite());
protected static final OpenmlConnector client_read_test = new OpenmlConnector(url_test, test_server.apiKeyRead());
protected static final OpenmlConnector client_read_live = new OpenmlConnector(url_live, "c1994bdb7ecb3c6f3c8f3b35f4b47f1f");

protected static final XStream xstream = XstreamXmlMapping.getInstance();

protected static final boolean VERBOSE = false;

@Before
public void setup() {
public void setup() {
Settings.CACHE_ALLOWED = false;
// for the functions that do use cache
Settings.CACHE_DIRECTORY = System.getProperty("user.home") + "/.openml_test/cache";
Settings.CACHE_DIRECTORY = System.getProperty("user.home") + "/.openml_" + subdomain_test + "/cache";

if (VERBOSE) {
client_admin_test.setVerboseLevel(1);
client_write_test.setVerboseLevel(1);
client_read_test.setVerboseLevel(1);
client_read_live.setVerboseLevel(1);
}
}
}
}


interface ServerConfig {
String subdomain();
String url();
String apiKeyWrite();
String apiKeyRead();
String apiKeyAdmin();
}
class TestServerConfig implements ServerConfig{

@Override
public String subdomain() {
return "test";
}

@Override
public String url() {
return "https://test.openml.org/";
}

@Override
public String apiKeyWrite() {
return "8baa83ecddfe44b561fd3d92442e3319";
}

@Override
public String apiKeyRead() {
return "6a4e0925273c6c9e2709b8b5179755c2"; // user id 3345, vanrijn@freiburg
}

@Override
public String apiKeyAdmin() {
return "d488d8afd93b32331cf6ea9d7003d4c3";
}
}

class StagingServerConfig implements ServerConfig{

@Override
public String subdomain() {
return "staging";
}

@Override
public String url() {
return "https://staging.openml.org/";
}

@Override
public String apiKeyWrite() {
return "normaluser";
}

@Override
public String apiKeyRead() {
return "readonly";
}

@Override
public String apiKeyAdmin() {
return "abc";
}
}

class DockerComposeServerConfig implements ServerConfig{

@Override
public String subdomain() {
return null;
}

@Override
public String url() {
return "http://localhost:8080/";
}

@Override
public String apiKeyWrite() {
return "AD000000000000000000000000000000";
}

@Override
public String apiKeyRead() {
return "AD000000000000000000000000000000";
}

@Override
public String apiKeyAdmin() {
return "AD000000000000000000000000000000";
}
}



8 changes: 4 additions & 4 deletions apiconnector/src/test/java/utils/TestCacheFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestCacheFunctions extends BaseTestFramework {

private static void utilDatasetCache(OpenmlConnector openml, int did) throws Exception {
Settings.CACHE_ALLOWED = true;
Settings.CACHE_DIRECTORY = System.getProperty("user.home") + "/.openml_test/cache";
Settings.CACHE_DIRECTORY = System.getProperty("user.home") + "/.openml_" + subdomain_test + "/cache";

String[] suffix = {
"datasets/" + did + "/description.xml",
Expand Down Expand Up @@ -56,7 +56,7 @@ private static void utilDatasetCache(OpenmlConnector openml, int did) throws Exc

private static void utilTaskCache(OpenmlConnector openml, List<Pair<String, String>> expected, int taskId) throws Exception {
Settings.CACHE_ALLOWED = true;
Settings.CACHE_DIRECTORY = System.getProperty("user.home") + "/.openml_test/cache";
Settings.CACHE_DIRECTORY = System.getProperty("user.home") + "/.openml_" + subdomain_test + "/cache";
// first remove potential cache files, to ensure that this procedure placed them
for (Pair<String, String> pair : expected) {
File toRemove = HttpCacheController.getCacheLocation(new URL(pair.getRight()), pair.getLeft());
Expand Down Expand Up @@ -99,8 +99,8 @@ public void testTaskLive() throws Exception {
@Test
public void testTaskTest() throws Exception {
List<Pair<String, String>> expected = Arrays.asList(
Pair.of("tasks/115/task.xml", "https://test.openml.org/api/v1/task/115"),
Pair.of("tasks/115/datasplits.arff", "https://test.openml.org/api_splits/get/115/Task_115_splits.arff")
Pair.of("tasks/115/task.xml", url_test + "api/v1/task/115"),
Pair.of("tasks/115/datasplits.arff", url_test + "/api_splits/get/115/Task_115_splits.arff")
);
utilTaskCache(client_read_test, expected, 115);
}
Expand Down