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

import static org.junit.Assert.assertTrue;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

import edu.tamu.tcat.hathitrust.Record;
import edu.tamu.tcat.hathitrust.Record.IdType;
import edu.tamu.tcat.hathitrust.client.HathiTrustClientException;
import edu.tamu.tcat.hathitrust.client.v1.basic.BasicRecord;
import edu.tamu.tcat.hathitrust.client.v1.basic.BibAPIClientImpl;
import edu.tamu.tcat.osgi.config.ConfigurationProperties;
import edu.tamu.tcat.osgi.config.file.SimpleFileConfigurationProperties;
import edu.tamu.tcat.oss.json.jackson.JacksonJsonMapper;

public class TestBibAPIClient
{

   public TestBibAPIClient()
   {
      // TODO Auto-generated constructor stub
   }

   private SimpleFileConfigurationProperties getConfigProperties()
   {
      SimpleFileConfigurationProperties config = new SimpleFileConfigurationProperties();
      Map<String, Object> params = new HashMap<>();
      Path propsPath = Paths.get("config.properties");
      propsPath = propsPath.toAbsolutePath();
      params.put(SimpleFileConfigurationProperties.PROP_FILE, propsPath.toString());
      config.activate(params);
      return config;
   }

   @Test
   public void testClientConnection()
   {
      String oclcNum = "379388464";
      IdType oclc = IdType.OCLC;
      BasicRecord record = new BasicRecord();
      BasicRecord.BasicRecordIdentifier recordIdent = record.new BasicRecordIdentifier(oclc, oclcNum);
//      SimpleFileConfigurationProperties config = getConfigProperties();

      BibAPIClientImpl client = new BibAPIClientImpl();
      client.setConfig(new ConfigurationPropertiesImpl());
      JacksonJsonMapper mapper = new JacksonJsonMapper();
      mapper.activate();
      client.setJsonMapper(mapper);
      try
      {
         Record lookup = client.lookup(recordIdent);
      }
      catch (HathiTrustClientException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      // client.setJsonMapper(mapper);
      assertTrue("", client.canConnect());
   }

   private class ConfigurationPropertiesImpl implements ConfigurationProperties
   {

      @Override
      public <T> T getPropertyValue(String name, Class<T> type) throws IllegalStateException
      {
         if (!name.equalsIgnoreCase(BibAPIClientImpl.HATHI_TRUST))
            throw new IllegalStateException("No value configured for property '" + name + "'");

         if (type != String.class)
            throw new IllegalStateException("Expected String type");

         return (T)"http://catalog.hathitrust.org/api/";
      }

      @Override
      public <T> T getPropertyValue(String name, Class<T> type, T defaultValue) throws IllegalStateException
      {
         if (!name.equalsIgnoreCase(BibAPIClientImpl.HATHI_TRUST))
            throw new IllegalStateException("No value configured for property '" + name + "'");

         if (type != String.class)
            throw new IllegalStateException("Expected String type");

         return (T)"http://catalog.hathitrust.org/api/";
      }

   }
}

@@ -75,20 +75,32 @@
 ert.
-assertTrue;%0A
+*;%0A%0Aimport java.net.URI;
 %0Aimp
@@ -151,16 +151,45 @@
 .Paths;%0A
+import java.util.Collection;%0A
 import j
@@ -206,16 +206,39 @@
 ashMap;%0A
+import java.util.List;%0A
 import j
@@ -363,16 +363,73 @@
 IdType;%0A
+import edu.tamu.tcat.hathitrust.Record.RecordIdentifier;%0A
 import e
@@ -1985,22 +1985,34 @@
         
+Collection%3C
 Record
+%3E
  lookup 
@@ -2041,16 +2041,543 @@
 Ident);%0A
+         for (Record recordResult : lookup)%0A         %7B%0A            boolean identNumberListed = false;%0A            List%3CRecordIdentifier%3E identifiers = recordResult.getIdentifiers(oclc);%0A            for(RecordIdentifier resultRecordIdent : identifiers)%0A            %7B%0A               if(oclcNum.equals(resultRecordIdent.getId()))%0A               %7B%0A                  identNumberListed = true;%0A                  break;%0A               %7D%0A            %7D%0A            assertTrue(%22OCLC number do not match.%22, identNumberListed);%0A         %7D%0A
       %7D%0A
@@ -2743,24 +2743,24 @@
 er(mapper);%0A
-
       assert
@@ -2765,16 +2765,47 @@
 rtTrue(%22
+Unable to connect to HathiTrust
 %22, clien

Change code to match updated API.