Commits

Sam Adams  committed 4be78c0

Migrate IntegrationTests to use WebappModule

  • Participants
  • Parent commits 1b37ed3

Comments (0)

Files changed (2)

File crystallography-test-harness/src/test/java/net/chempound/crystal/CrystalIntegrationTest.java

 package net.chempound.crystal;
 
-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.config.ChempoundConfiguration;
-import net.chempound.config.DefaultPropertySource;
-import net.chempound.config.StubChempoundConfiguration;
 import net.chempound.content.DepositRequest;
 import net.chempound.crystal.importer.CrystalStructureImporter;
 import net.chempound.crystal.importer.utils.CifIO;
 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 nu.xom.ParsingException;
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Document;
  */
 public class CrystalIntegrationTest {
 
-    private Component component;
-
+    private ImageGenerator imageGenerator;
+    private InChIGenerator inchiGenerator;
+    private ChempoundWebappLauncher webappLauncher;
     private File workspace;
 
-    private ImageGenerator imageGenerator;
-    private InChIGenerator inchiGenerator;
+    @Before
+    public void setUp() throws Exception {
+        workspace = new File("target", UUID.randomUUID().toString());
+        FileUtils.forceMkdir(workspace);
 
-    @Before
-    public void init() throws Exception {
+        webappLauncher = new ChempoundWebappLauncher(new StubConfigurationWebAppModule(URI.create("http://localhost:8714/"), workspace, new CrystallographyModule()));
+        webappLauncher.start();
 
         imageGenerator = mock(ImageGenerator.class);
         inchiGenerator = mock(InChIGenerator.class);
             @Override
             public Object answer(final InvocationOnMock invocation) throws Throwable {
                 final CMLMolecule molecule = (CMLMolecule) invocation.getArguments()[0];
+
                 final CMLIdentifier inchi = new CMLIdentifier();
                 inchi.setConvention("iupac:inchi");
                 inchi.setCMLValue("InChI=1/TEST");
                 molecule.appendChild(inchi);
+
                 final CMLIdentifier inchiKey = new CMLIdentifier();
                 inchiKey.setConvention("iupac:inchiKey");
                 inchiKey.setCMLValue("TEST-TEST");
                 molecule.appendChild(inchiKey);
+
                 return null;
             }
         }).when(inchiGenerator).attachIdentifiers(any(CMLMolecule.class));
-
-        workspace = createWorkspace();
-
-        Injector injector = Guice.createInjector(
-                new ChempoundConfigurationModule(initConfiguration(), new DefaultPropertySource()),
-                new DefaultChempoundModule(),
-                new DefaultChempoundWebModule(),
-                new CrystallographyModule()
-            );
-
-        component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, 8714)
-                .getContext().getParameters().add("maxThreads", "256");
-        component.getDefaultHost()
-                .attachDefault(injector.getInstance(Application.class));
-        component.start();
     }
 
     @After
-    public void close() throws Exception {
-        component.stop();
-        FileUtils.deleteQuietly(workspace);
+    public void tearDownChempound() throws Exception {
+        try {
+            webappLauncher.stop();
+        } finally {
+            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 {
-        final URI uri = URI.create("http://localhost:8714/");
-        return new StubChempoundConfiguration(uri, workspace);
-    }
-
-
     private void closeQuietly(Response response) {
         if (response.getEntity() != null) {
             try {

File crystallography-test-harness/src/test/java/net/chempound/crystal/CrystalSearchIntegrationTest.java

 package net.chempound.crystal;
 
-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.config.ChempoundConfiguration;
-import net.chempound.config.DefaultPropertySource;
-import net.chempound.config.StubChempoundConfiguration;
 import net.chempound.content.DepositRequest;
 import net.chempound.crystal.importer.CrystalStructureImporter;
-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;
 
     private static ImageGenerator imageGenerator;
     private static InChIGenerator inchiGenerator;
-
-    private static Component component;
+    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);
+
+        webappLauncher = new ChempoundWebappLauncher(new StubConfigurationWebAppModule(URI.create("http://localhost:8715/"), workspace, new CrystallographyModule()));
+        webappLauncher.start();
 
         imageGenerator = mock(ImageGenerator.class);
         inchiGenerator = mock(InChIGenerator.class);
 
-        workspace = createWorkspace();
+        loadData();
+    }
 
-        Injector injector = Guice.createInjector(
-                new ChempoundConfigurationModule(initConfiguration(), new DefaultPropertySource()),
-                new DefaultChempoundModule(),
-                new DefaultChempoundWebModule(),
-                new CrystallographyModule()
-            );
-
-        component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, 8715)
-                .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 {
         }
     }
 
-    @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:8715/");
-        return new StubChempoundConfiguration(uri, workspace);
-    }
-
-
     private static void closeQuietly(Response response) {
         if (response.getEntity() != null) {
             try {