package edu.tamu.tcat.hathitrust.basic.tests;

import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Test;

import edu.tamu.tcat.hathitrust.features.ExtractedFeatures;
import edu.tamu.tcat.hathitrust.features.ExtractedFeaturesProvider;

public class ExtractedFeaturesTests
{
   @Test
   public void testFactoryCreate() throws Exception
   {
      ExtractedFeaturesProvider p = createProvider();
      try (ExtractedFeatures feat = p.getExtractedFeatures("hvd.ah3d1a"))
      {
         String vid = feat.getVolumeId();
         System.out.println("Loaded: " + vid);
      }
   }
   
   private static ExtractedFeaturesProvider createProvider()
   {
      return new MockExtractedFeaturesProvider(Paths.get("\\\\citd.tamu.edu\\citdfs\\archive\\HTRC_Dataset\\"));
   }
   
   static class MockExtractedFeaturesProvider implements ExtractedFeaturesProvider
   {
      private Path root;
      
      public MockExtractedFeaturesProvider(Path root)
      {
         this.root = root;
      }
      
      @Override
      public ExtractedFeatures getExtractedFeatures(String htrcVolumeId)
      {
         return null;
      }
   }
}

@@ -36,24 +36,52 @@
 sic.tests;%0A%0A
+import java.nio.file.Files;%0A
 import java.
@@ -122,16 +122,99 @@
 e.Paths;
+%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.regex.Pattern;
 %0A%0Aimport
@@ -1228,19 +1228,1156 @@
     
-return null
+String%5B%5D strs = htrcVolumeId.split(Pattern.quote(%22.%22));%0A         String src = strs%5B0%5D;%0A         String tail = strs%5B1%5D;%0A         %0A         List%3CString%3E pairs = new ArrayList%3C%3E();%0A         for (int i=0; i%3Ctail.length(); i+=2)%0A         %7B%0A            pairs.add(tail.substring(i, i+2));%0A         %7D%0A         %0A         Path p = root.resolve(%22basic%22).resolve(src).resolve(%22pairtree_root%22);%0A         for (String part : pairs)%0A            p = p.resolve(part);%0A         %0A         p = p.resolve(tail);%0A         Path file = p.resolve(htrcVolumeId+%22.basic.json.bz2%22);%0A         if (!Files.exists(file))%0A         %7B%0A            throw new IllegalStateException(%22not exist: %22 + file);%0A         %7D%0A         %0A         %0A         return new MockExtractedFeatures(htrcVolumeId);%0A      %7D%0A   %7D%0A   %0A   static class MockExtractedFeatures implements ExtractedFeatures%0A   %7B%0A      private final String vid;%0A      %0A      public MockExtractedFeatures(String vid)%0A      %7B%0A         this.vid = vid;%0A      %7D%0A      %0A      @Override%0A      public void close() throws Exception%0A      %7B%0A         // no-op%0A      %7D%0A%0A      @Override%0A      public String getVolumeId()%0A      %7B%0A         return vid
 ;%0A  

Add code to resolve directory path from volume id