Commits

Sam Adams committed ba85137

Fix relative/absolute URIs in compchem + crystallography templates

  • Participants
  • Parent commits 2857429

Comments (0)

Files changed (3)

compchem-handler/src/main/resources/net/chempound/compchem/includes/headers.html

     <!-- import jmol -->
-    <script src="/plugins/jmol/jmol/Jmol.js" type="text/javascript"></script>
+    <script src="${URI_BASE}/plugins/jmol/jmol/Jmol.js" type="text/javascript"></script>
 
     <!-- import jquery -->
-    <script src="/plugins/jquery/jquery-1.4.2.js" type="text/javascript"></script>
+    <script src="${URI_BASE}/plugins/jquery/jquery-1.4.2.js" type="text/javascript"></script>
 
     <!-- import jmol-jquery -->
-    <script src="/plugins/jmol/jquery.jmol.js" type="text/javascript"></script>
+    <script src="${URI_BASE}/plugins/jmol/jquery.jmol.js" type="text/javascript"></script>
     <!-- import style sheet -->
-    <link href="/plugins/jmol/jquery.jmol.css" type="text/css" rel="stylesheet" />"
+    <link href="${URI_BASE}/plugins/jmol/jquery.jmol.css" type="text/css" rel="stylesheet" />"

compchem-handler/src/main/resources/net/chempound/compchem/templates/comp.ftl

 <script type="text/javascript">
     $(document).ready(function() {
         var useSignedApplet = true;
-        jmolInitialize("/plugins/jmol/jmol/", useSignedApplet);
+        jmolInitialize("${URI_BASE}/plugins/jmol/jmol/", useSignedApplet);
 
         $("#jmol").jmol({
             'img': "${calculation.imageFile}",

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

 package net.chempound.compchem;
 
-import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.Module;
 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.DefaultChempoundModule;
 import net.chempound.chemistry.ImageGenerator;
 import net.chempound.chemistry.InChIGenerator;
-import net.chempound.chemistry.testutil.ImageGeneratorStubber;
-import net.chempound.config.BaseUri;
 import net.chempound.config.ChempoundConfiguration;
 import net.chempound.config.DefaultChempoundConfiguration;
 import net.chempound.content.DepositRequest;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * @author sea36
  */
 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 Component component;
     private ImageGenerator imageGenerator;
     private InChIGenerator inchiGenerator;
             );
 
         component = injector.getInstance(Component.class);
-        component.getServers().add(Protocol.HTTP, 8713)
+        component.getServers().add(Protocol.HTTP, PORT)
                 .getContext().getParameters().add("maxThreads", "256");
         component.getDefaultHost()
-                .attachDefault(injector.getInstance(Application.class));
+                .attach("/"+PATH, injector.getInstance(Application.class));
         component.start();
     }
 
     @After
     public void close() throws Exception {
         component.stop();
-//        FileUtils.deleteQuietly(workspace);
+        FileUtils.deleteQuietly(workspace);
     }
 
     protected File createWorkspace() throws IOException {
     }
 
     protected ChempoundConfiguration initConfiguration() throws IOException {
-        URI uri = URI.create("http://localhost:8713/");
-        return DefaultChempoundConfiguration.load(uri, workspace);
+        return DefaultChempoundConfiguration.load(URI.create(REPO_URI), workspace);
     }
 
     private void closeQuietly(Response response) {
 
         // Test collection
         Client client = new Client(Protocol.HTTP);
-        Request request1 = new Request(Method.GET, "http://localhost:8713/content/index.html");
+        Request request1 = new Request(Method.GET, REPO_URI+"content/index.html");
         Response response1 = client.handle(request1);
         try {
             assertEquals(Status.SUCCESS_OK, response1.getStatus());
         Response response2 = client.handle(request2);
         try {
             assertEquals(Status.SUCCESS_OK, response2.getStatus());
+
+            String text = response2.getEntityAsText();
+            assertTrue(text.contains("jmolInitialize(\""+REPO_URI+"plugins/jmol/jmol/\""));
+            assertTrue(text.contains(""+REPO_URI+"plugins/jmol/jquery.jmol.js\""));
+
         } finally {
             closeQuietly(response1);
         }
-
     }
 
     private DepositReceipt performDeposit(InputStream in, String id) throws Exception {
         Deposit deposit = createDeposit(id, request);
 
         SWORDClient sword = new SWORDClient();
-        return sword.deposit("http://localhost:8713/sword/collection/", deposit);
+        return sword.deposit(REPO_URI+"sword/collection/", deposit);
     }