001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.http.server;
007:
008: import java.io.File;
009:
010: import info.aduna.net.http.server.embedded.EmbeddedServer;
011:
012: import org.openrdf.http.protocol.Protocol;
013: import org.openrdf.repository.Repository;
014: import org.openrdf.repository.RepositoryConnection;
015: import org.openrdf.repository.RepositoryException;
016: import org.openrdf.repository.config.RepositoryConfig;
017: import org.openrdf.repository.config.RepositoryConfigException;
018: import org.openrdf.repository.config.RepositoryConfigUtil;
019: import org.openrdf.repository.http.HTTPRepository;
020: import org.openrdf.repository.manager.SystemRepository;
021: import org.openrdf.repository.sail.config.SailRepositoryConfig;
022: import org.openrdf.sail.inferencer.fc.config.ForwardChainingRDFSInferencerConfig;
023: import org.openrdf.sail.memory.config.MemoryStoreConfig;
024:
025: /**
026: * @author Herko ter Horst
027: */
028: public class TestServer extends EmbeddedServer {
029:
030: public static final String TEST_REPO_ID = "Test";
031:
032: public static final String TEST_INFERENCE_REPO_ID = "Test-RDFS";
033:
034: public static final String OPENRDF_CONTEXT = "/openrdf";
035:
036: public static String SERVER_URL = "http://" + DEFAULT_HOST + ":"
037: + DEFAULT_PORT + OPENRDF_CONTEXT;
038:
039: public static String REPOSITORY_URL = Protocol
040: .getRepositoryLocation(TestServer.SERVER_URL, TEST_REPO_ID);
041:
042: public static String INFERENCE_REPOSITORY_URL = Protocol
043: .getRepositoryLocation(TestServer.SERVER_URL,
044: TEST_INFERENCE_REPO_ID);
045:
046: public static final String OPENRDF_SERVER_WAR = "./target/openrdf-sesame";
047:
048: public TestServer() {
049: // warPath configured in pom.xml maven-war-plugin configuration
050: super (DEFAULT_HOST, DEFAULT_PORT, OPENRDF_CONTEXT,
051: OPENRDF_SERVER_WAR);
052: }
053:
054: @Override
055: public void start() throws Exception {
056: File dataDir = new File(System.getProperty("user.dir")
057: + "/target/datadir");
058: dataDir.mkdirs();
059: System.setProperty("info.aduna.platform.appdata.basedir",
060: dataDir.getAbsolutePath());
061: System.setProperty("DEBUG", "true");
062:
063: super .start();
064:
065: createTestRepositories();
066: }
067:
068: @Override
069: public void stop() throws Exception {
070: Repository systemRepo = new HTTPRepository(Protocol
071: .getRepositoryLocation(SERVER_URL, SystemRepository.ID));
072: RepositoryConnection con = systemRepo.getConnection();
073: try {
074: con.clear();
075: } finally {
076: con.close();
077: }
078:
079: super .stop();
080: }
081:
082: /**
083: * @throws RepositoryException
084: */
085: private void createTestRepositories() throws RepositoryException,
086: RepositoryConfigException {
087: Repository systemRep = new HTTPRepository(Protocol
088: .getRepositoryLocation(SERVER_URL, SystemRepository.ID));
089:
090: // create a (non-inferencing) memory store
091: MemoryStoreConfig memStoreConfig = new MemoryStoreConfig();
092: SailRepositoryConfig sailRepConfig = new SailRepositoryConfig(
093: memStoreConfig);
094: RepositoryConfig repConfig = new RepositoryConfig(TEST_REPO_ID,
095: sailRepConfig);
096:
097: RepositoryConfigUtil.updateRepositoryConfigs(systemRep,
098: repConfig);
099:
100: // create an inferencing memory store
101: ForwardChainingRDFSInferencerConfig inferMemStoreConfig = new ForwardChainingRDFSInferencerConfig(
102: new MemoryStoreConfig());
103: sailRepConfig = new SailRepositoryConfig(inferMemStoreConfig);
104: repConfig = new RepositoryConfig(TEST_INFERENCE_REPO_ID,
105: sailRepConfig);
106:
107: RepositoryConfigUtil.updateRepositoryConfigs(systemRep,
108: repConfig);
109: }
110: }
|