Commits

Jorge Estrada  committed 8100495 Merge

Merged with main trunk

  • Participants
  • Parent commits 201b904, 68b3529

Comments (0)

Files changed (9)

             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>uk.ac.cam.ch.wwmm.quixote</groupId>
+            <artifactId>quixote-repository</artifactId>
+            <version>0.1-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <repositories>

File src/main/java/uk/ac/cam/ch/wwmm/quixote/client/cif/DepositCifCommand.java

 package uk.ac.cam.ch.wwmm.quixote.client.cif;
 
-import net.chempound.client.DepositBuilder;
-import net.chempound.client.SwordUtil;
-import net.chempound.client.cli.command.Command;
 import net.chempound.client.cli.command.DepositCommand;
 import net.chempound.client.cli.options.GlobalOptions;
+import net.chempound.client.sword.DepositReceipt;
 import net.chempound.crystal.importer.CrystalStructureImporter;
 import net.chempound.crystal.rdf.CrystalStructurePersonalities;
-import net.chempound.rdf.ChempoundPersonalities;
 import org.apache.commons.io.FilenameUtils;
-import org.swordapp.client.Deposit;
-import org.swordapp.client.DepositReceipt;
-import org.swordapp.client.SWORDClient;
 
 import java.io.File;
+import java.net.URI;
 
 /**
  * @author Sam Adams
         final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
         importer.setCifResource(FilenameUtils.getName(filename), cifFile);
 
-        final SWORDClient swordClient = new SWORDClient();
         final String url = globalOptions.repository;
         try {
-            final Deposit deposit = SwordUtil.createSwordDeposit(importer.build());
-            final DepositReceipt receipt = swordClient.deposit(url, deposit);
+            final DepositReceipt receipt = swordClient.deposit(URI.create(url), importer.build());
 
         } catch (Exception e) {
             e.printStackTrace();

File src/main/java/uk/ac/cam/ch/wwmm/quixote/client/gaussian/DepositGaussianCommand.java

 package uk.ac.cam.ch.wwmm.quixote.client.gaussian;
 
-import net.chempound.client.SwordUtil;
 import net.chempound.client.cli.command.DepositCommand;
 import net.chempound.client.cli.options.GlobalOptions;
+import net.chempound.client.sword.DepositReceipt;
 import net.chempound.compchem.GaussianLogImporter;
 import net.chempound.compchem.rdf.CompChemPersonalities;
-import net.chempound.crystal.importer.CrystalStructureImporter;
-import net.chempound.crystal.rdf.CrystalStructurePersonalities;
 import org.apache.commons.io.FilenameUtils;
-import org.swordapp.client.Deposit;
-import org.swordapp.client.DepositReceipt;
-import org.swordapp.client.SWORDClient;
 
 import java.io.File;
+import java.net.URI;
 
 /**
  * @author Sam Adams
         final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
         importer.setLogFile(cifFile, FilenameUtils.getName(filename));
 
-        final SWORDClient swordClient = new SWORDClient();
         final String url = globalOptions.repository;
         try {
-            final Deposit deposit = SwordUtil.createSwordDeposit(importer.generateDepositRequest());
-            final DepositReceipt receipt = swordClient.deposit(url, deposit);
+            final DepositReceipt receipt = swordClient.deposit(URI.create(url), importer.generateDepositRequest());
 
         } catch (Exception e) {
             e.printStackTrace();

File src/main/java/uk/ac/cam/ch/wwmm/quixote/client/nwchem/DepositNWChemCommand.java

 package uk.ac.cam.ch.wwmm.quixote.client.nwchem;
 
-import net.chempound.client.SwordUtil;
 import net.chempound.client.cli.command.DepositCommand;
 import net.chempound.client.cli.options.GlobalOptions;
-import net.chempound.compchem.GaussianLogImporter;
+import net.chempound.client.sword.DepositReceipt;
 import net.chempound.compchem.NWChemLogImporter;
 import net.chempound.compchem.rdf.CompChemPersonalities;
 import org.apache.commons.io.FilenameUtils;
-import org.swordapp.client.Deposit;
-import org.swordapp.client.DepositReceipt;
-import org.swordapp.client.SWORDClient;
 
 import java.io.File;
+import java.net.URI;
 
 /**
  * @author Sam Adams
         final File cifFile = globalOptions.workingDirectory == null ? new File(filename) : new File(globalOptions.workingDirectory, filename);
         importer.setLogFile(cifFile, FilenameUtils.getName(filename));
 
-        final SWORDClient swordClient = new SWORDClient();
         final String url = globalOptions.repository;
         try {
-            final Deposit deposit = SwordUtil.createSwordDeposit(importer.generateDepositRequest());
-            final DepositReceipt receipt = swordClient.deposit(url, deposit);
+            final DepositReceipt receipt = swordClient.deposit(URI.create(url), importer.generateDepositRequest());
 
         } catch (Exception e) {
             e.printStackTrace();

File src/main/resources/log4j.properties

+log4j.rootLogger = WARN, A
+
+log4j.appender.A = org.apache.log4j.ConsoleAppender
+log4j.appender.A.layout = org.apache.log4j.PatternLayout
+log4j.appender.A.layout.ConversionPattern = %-4r [%t] %-5p %c %x - %m%n
+log4j.appender.A.target = System.err

File 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.DefaultChempoundConfiguration;
+import net.chempound.datastore.TripleStore;
+import net.chempound.rdf.ORE;
+import net.chempound.webapp.DefaultChempoundWebModule;
+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;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.UUID;
+
+import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.spy;
+
 /**
  * @author Sam Adams
  */
 public class QuixoteClientCLIIntegrationTest {
+
+    private static Component component;
+    private static TripleStore tripleStore;
+    private static File workspace;
+
+    private QuixoteClientCLI client;
+    private File tmpDir;
+
+    @BeforeClass
+    public static void setUpChempound() throws Exception {
+        final URI baseUri = URI.create("http://localhost:12080/");
+        workspace = new File("target", UUID.randomUUID().toString());
+
+        final ChempoundConfiguration configuration = new DefaultChempoundConfiguration(baseUri, workspace);
+        final Injector injector = Guice.createInjector(Stage.DEVELOPMENT,
+                new DefaultChempoundModule(),
+                new DefaultChempoundWebModule(),
+                new ChempoundConfigurationModule(configuration),
+                new QuixotePluginsModule()
+        );
+
+        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);
+    }
+
+    @AfterClass
+    public static void tearDownChempound() throws Exception {
+        if (component != null) {
+            try {
+                component.stop();
+            } finally {
+                component = null;
+            }
+        }
+        FileUtils.deleteQuietly(workspace);
+        workspace = null;
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        client = spy(new QuixoteClientCLI());
+        doNothing().when(client).exit(anyInt());
+
+        tmpDir = new File("target/" + UUID.randomUUID());
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        FileUtils.deleteQuietly(tmpDir);
+    }
+
+    @Test
+    public void testDepositCif() throws Exception {
+        FileUtils.forceMkdir(tmpDir);
+        copyFile("bh2341sup1.cif");
+
+        client.runMain("-R", "http://localhost:12080/content/", "--cwd", tmpDir.getAbsolutePath(),
+                "deposit-cif", "-s", "bh2341sup1", "bh2341sup1.cif");
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/"), ORE.aggregates, createResource("http://localhost:12080/content/bh2341sup1/")));
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/bh2341sup1/"), ORE.aggregates, createResource("http://localhost:12080/content/bh2341sup1/bh2341sup1.cif")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/bh2341sup1/"), ORE.aggregates, createResource("http://localhost:12080/content/bh2341sup1/bh2341sup1.cml")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/bh2341sup1/"), ORE.aggregates, createResource("http://localhost:12080/content/bh2341sup1/bh2341sup1.rdf")));
+    }
+
+    @Test
+    public void testDepositGaussian() throws Exception {
+        FileUtils.forceMkdir(tmpDir);
+        copyFile("C2H5.log");
+
+        client.runMain("-R", "http://localhost:12080/content/", "--cwd", tmpDir.getAbsolutePath(),
+                "deposit-gaussian", "-s", "C2H5", "C2H5.log");
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/"), ORE.aggregates, createResource("http://localhost:12080/content/C2H5/")));
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/C2H5/"), ORE.aggregates, createResource("http://localhost:12080/content/C2H5/C2H5.log")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/C2H5/"), ORE.aggregates, createResource("http://localhost:12080/content/C2H5/C2H5.cml")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/C2H5/"), ORE.aggregates, createResource("http://localhost:12080/content/C2H5/C2H5.rdf")));
+    }
+
+    @Test
+    public void testDepositNwChem() throws Exception {
+        FileUtils.forceMkdir(tmpDir);
+        copyFile("cv5056.log");
+
+        client.runMain("-R", "http://localhost:12080/content/", "--cwd", tmpDir.getAbsolutePath(),
+                "deposit-nwchem", "-s", "cv5056", "cv5056.log");
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/"), ORE.aggregates, createResource("http://localhost:12080/content/cv5056/")));
+
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/cv5056/"), ORE.aggregates, createResource("http://localhost:12080/content/cv5056/cv5056.log")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/cv5056/"), ORE.aggregates, createResource("http://localhost:12080/content/cv5056/cv5056.cml")));
+        assertTrue(tripleStore.containsTriple(createResource("http://localhost:12080/content/cv5056/"), ORE.aggregates, createResource("http://localhost:12080/content/cv5056/cv5056.rdf")));
+    }
+
+    private void copyFile(final String filename) throws IOException {
+        final InputStream inputStream = getClass().getResourceAsStream(filename);
+        try {
+            FileUtils.copyInputStreamToFile(inputStream, new File(tmpDir, filename));
+        } finally {
+            IOUtils.closeQuietly(inputStream);
+        }
+    }
+
 }