Commits

Anonymous committed acadbbc

Migrate IntegrationTests to use WebappModule

  • Participants
  • Parent commits d0324f9

Comments (0)

Files changed (1)

src/test/java/uk/ac/cam/ch/wwmm/quixote/client/QuixoteClientCLIIntegrationTest.java

 package uk.ac.cam.ch.wwmm.quixote.client;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Stage;
-import net.chempound.ChempoundConfigurationModule;
-import net.chempound.DefaultChempoundModule;
-import net.chempound.config.ChempoundConfiguration;
-import net.chempound.config.DefaultPropertySource;
-import net.chempound.config.StubChempoundConfiguration;
+import net.chempound.compchem.CompChemModule;
 import net.chempound.datastore.TripleStore;
 import net.chempound.rdf.ORE;
-import net.chempound.webapp.DefaultChempoundWebModule;
+import net.chempound.webapp.ChempoundWebappLauncher;
+import net.chempound.webapp.StubConfigurationWebAppModule;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.junit.*;
-import org.restlet.Application;
-import org.restlet.Component;
-import org.restlet.data.Protocol;
-import uk.ac.cam.ch.wwmm.quixote.QuixotePluginsModule;
 
 import java.io.File;
 import java.io.IOException;
  */
 public class QuixoteClientCLIIntegrationTest {
 
-    private static Component component;
-    private static TripleStore tripleStore;
-    private static File workspace;
+    private static final URI BASE_URI = URI.create("http://localhost:12080/");
 
     private QuixoteClientCLI client;
     private File tmpDir;
 
+    private static ChempoundWebappLauncher webappLauncher;
+    private static File workspace;
+    private static TripleStore tripleStore;
+
     @BeforeClass
-    public static void setUpChempound() throws Exception {
-        final URI baseUri = URI.create("http://localhost:12080/");
+    public static void setUpClass() throws Exception {
         workspace = new File("target", UUID.randomUUID().toString());
+        FileUtils.forceMkdir(workspace);
 
-        final ChempoundConfiguration configuration = new StubChempoundConfiguration(baseUri, workspace);
-        final Injector injector = Guice.createInjector(Stage.DEVELOPMENT,
-                new DefaultChempoundModule(),
-                new DefaultChempoundWebModule(),
-                new ChempoundConfigurationModule(configuration, new DefaultPropertySource()),
-                new QuixotePluginsModule()
-        );
+        webappLauncher = new ChempoundWebappLauncher(new StubConfigurationWebAppModule(BASE_URI, workspace, new CompChemModule()));
+        webappLauncher.start();
 
-        component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, 12080)
-                .getContext().getParameters().add("maxThreads", "256");
-        component.getDefaultHost().attach(injector.getInstance(Application.class));
-        component.start();
-
-        tripleStore = injector.getInstance(TripleStore.class);
+        tripleStore = webappLauncher.getInjector().getInstance(TripleStore.class);
     }
 
     @AfterClass
-    public static void tearDownChempound() throws Exception {
-        if (component != null) {
-            try {
-                component.stop();
-            } finally {
-                component = null;
-            }
+    public static void tearDownClass() throws Exception {
+        try {
+            webappLauncher.stop();
+        } finally {
+            FileUtils.deleteQuietly(workspace);
+            webappLauncher = null;
+            workspace = null;
+            tripleStore = null;
         }
-        FileUtils.deleteQuietly(workspace);
-        workspace = null;
     }
 
     @Before
         client = spy(new QuixoteClientCLI());
         doNothing().when(client).exit(anyInt());
 
-        tmpDir = new File("target/" + UUID.randomUUID());
+        tmpDir = new File(workspace, "tmp/" + UUID.randomUUID());
+        FileUtils.forceMkdir(tmpDir);
     }
 
     @After
 
     @Test
     public void testDepositCif() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
         copyFile("bh2341sup1.cif");
 
         client.runMain("-R", "http://localhost:12080/content/", "--cwd", tmpDir.getAbsolutePath(),
 
     @Test
     public void testDepositGaussian() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
         copyFile("C2H5.log");
 
         client.runMain("-R", "http://localhost:12080/content/", "--cwd", tmpDir.getAbsolutePath(),
 
     @Test
     public void testDepositNwChem() throws Exception {
-        FileUtils.forceMkdir(tmpDir);
         copyFile("cv5056.log");
 
         client.runMain("-R", "http://localhost:12080/content/", "--cwd", tmpDir.getAbsolutePath(),