Anonymous avatar Anonymous committed 285e227

Migrate IntegrationTests to use WebappModule

Comments (0)

Files changed (2)

compchem-test-harness/src/test/java/net/chempound/compchem/CompChemIntegrationTest.java

 package net.chempound.compchem;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
 import com.hp.hpl.jena.rdf.model.Statement;
 import com.hp.hpl.jena.xmloutput.RDFXMLWriterI;
 import com.hp.hpl.jena.xmloutput.impl.Abbreviated;
-import net.chempound.ChempoundConfigurationModule;
-import net.chempound.DefaultChempoundModule;
 import net.chempound.chemistry.ImageGenerator;
 import net.chempound.chemistry.InChIGenerator;
 import net.chempound.compchem.gaussian.GaussianLogImporter;
 import net.chempound.compchem.nwchem.NWChemLogImporter;
-import net.chempound.config.ChempoundConfiguration;
-import net.chempound.config.DefaultPropertySource;
-import net.chempound.config.StubChempoundConfiguration;
 import net.chempound.content.DepositRequest;
 import net.chempound.rdf.DCTerms;
 import net.chempound.storage.DepositResource;
-import net.chempound.webapp.DefaultChempoundWebModule;
+import net.chempound.webapp.ChempoundWebappLauncher;
+import net.chempound.webapp.StubConfigurationWebAppModule;
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Document;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
-import org.restlet.*;
+import org.restlet.Client;
+import org.restlet.Request;
+import org.restlet.Response;
 import org.restlet.data.Method;
 import org.restlet.data.Protocol;
 import org.restlet.data.Status;
  */
 public class CompChemIntegrationTest {
 
-    private static final int PORT = 8713;
-    private static final String PATH = "path-to-repo";
-    private static final String REPO_URI = "http://localhost:"+PORT+"/"+PATH+"/";
+    private static final String REPO_URI = "http://localhost:8713/path-to-repo/";
+    private static final URI BASE_URI = URI.create(REPO_URI);
 
-
-    private Component component;
     private ImageGenerator imageGenerator;
     private InChIGenerator inchiGenerator;
-
+    private ChempoundWebappLauncher webappLauncher;
     private File workspace;
 
     @Before
-    public void init() throws Exception {
+    public void setUp() throws Exception {
+        workspace = new File("target", UUID.randomUUID().toString());
+        FileUtils.forceMkdir(workspace);
+
+        webappLauncher = new ChempoundWebappLauncher(new StubConfigurationWebAppModule(BASE_URI, workspace, new CompChemModule()));
+        webappLauncher.start();
 
         imageGenerator = stubImageGenerator();
         inchiGenerator = mock(InChIGenerator.class);
                 return null;
             }
         }).when(inchiGenerator).attachIdentifiers(any(CMLMolecule.class));
-
-        workspace = createWorkspace();
-
-        Injector injector = Guice.createInjector(
-                new ChempoundConfigurationModule(initConfiguration(), new DefaultPropertySource()),
-                new DefaultChempoundModule(),
-                new DefaultChempoundWebModule(),
-                new CompChemModule()
-            );
-
-        component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, PORT)
-                .getContext().getParameters().add("maxThreads", "256");
-        component.getDefaultHost()
-                .attach("/"+PATH, injector.getInstance(Application.class));
-        component.start();
     }
 
     @After
-    public void close() throws Exception {
-        component.stop();
-        FileUtils.deleteQuietly(workspace);
-    }
-
-    protected File createWorkspace() throws IOException {
-        File workspace;
-        do {
-            workspace = new File("target/tmp/-"+ UUID.randomUUID());
-        } while (workspace.exists());
-        FileUtils.forceMkdir(workspace);
-        return workspace;
-    }
-
-    protected ChempoundConfiguration initConfiguration() throws IOException {
-        return new StubChempoundConfiguration(URI.create(REPO_URI), workspace);
+    public void tearDownChempound() throws Exception {
+        try {
+            webappLauncher.stop();
+        } finally {
+            FileUtils.deleteQuietly(workspace);
+        }
     }
 
     private void closeQuietly(Response response) {

compchem-test-harness/src/test/java/net/chempound/compchem/CompChemSearchIntegrationTest.java

 package net.chempound.compchem;
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import net.chempound.ChempoundConfigurationModule;
-import net.chempound.DefaultChempoundModule;
 import net.chempound.chemistry.ImageGenerator;
 import net.chempound.chemistry.InChIGenerator;
 import net.chempound.compchem.nwchem.NWChemLogImporter;
-import net.chempound.config.ChempoundConfiguration;
-import net.chempound.config.DefaultPropertySource;
-import net.chempound.config.StubChempoundConfiguration;
 import net.chempound.content.DepositRequest;
-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.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.restlet.*;
+import org.restlet.Client;
+import org.restlet.Request;
+import org.restlet.Response;
 import org.restlet.data.Form;
 import org.restlet.data.Method;
 import org.restlet.data.Protocol;
 import java.net.URI;
 import java.util.UUID;
 
+import static net.chempound.chemistry.testutil.ImageGeneratorStubber.stubImageGenerator;
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.mock;
 
  */
 public class CompChemSearchIntegrationTest {
 
-    private static Component component;
     private static ImageGenerator imageGenerator;
     private static InChIGenerator inchiGenerator;
-
+    private static ChempoundWebappLauncher webappLauncher;
     private static File workspace;
 
     @BeforeClass
-    public static void init() throws Exception {
+    public static void setUp() throws Exception {
+        workspace = new File("target", UUID.randomUUID().toString());
+        FileUtils.forceMkdir(workspace);
 
-        imageGenerator = mock(ImageGenerator.class);
+        webappLauncher = new ChempoundWebappLauncher(new StubConfigurationWebAppModule(URI.create("http://localhost:8716/"), workspace, new CompChemModule()));
+        webappLauncher.start();
+
+        imageGenerator = stubImageGenerator();
         inchiGenerator = mock(InChIGenerator.class);
 
-        workspace = createWorkspace();
-
-        Injector injector = Guice.createInjector(
-                new ChempoundConfigurationModule(initConfiguration(), new DefaultPropertySource()),
-                new DefaultChempoundModule(),
-                new DefaultChempoundWebModule(),
-                new CompChemModule()
-            );
-
-        component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, 8716)
-                .getContext().getParameters().add("maxThreads", "256");
-        component.getDefaultHost()
-                .attachDefault(injector.getInstance(Application.class));
-        component.start();
-
         loadData();
     }
 
+    @AfterClass
+    public static void tearDownChempound() throws Exception {
+        try {
+            webappLauncher.stop();
+        } finally {
+            FileUtils.deleteQuietly(workspace);
+            webappLauncher = null;
+            workspace = null;
+        }
+    }
+
     private static void loadData() throws Exception {
-
         loadData("h2o_631gs");
         loadData("benzene_321g_mp2");
         loadData("h2o_sto3g_dft_b3lyp_opt");
-
     }
 
     private static void loadData(String id) throws Exception {
         }
     }
 
-    @AfterClass
-    public static void close() throws Exception {
-        component.stop();
-        FileUtils.deleteQuietly(workspace);
-    }
-
-    protected static File createWorkspace() throws IOException {
-        File workspace;
-        do {
-            workspace = new File("target/tmp/-"+ UUID.randomUUID());
-        } while (workspace.exists());
-        FileUtils.forceMkdir(workspace);
-        return workspace;
-    }
-
-    protected static ChempoundConfiguration initConfiguration() throws IOException {
-        final URI uri = URI.create("http://localhost:8716/");
-        return new StubChempoundConfiguration(uri, workspace);
-    }
-
     private static void closeQuietly(Response response) {
         if (response.getEntity() != null) {
             try {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.