JAL-3829 allow multiple URL mocks and include P01308 in 3d-beacons mocks
[jalview.git] / src / jalview / fts / core / FTSRestClient.java
index b262f64..b1cfc53 100644 (file)
@@ -26,6 +26,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Objects;
 
 import jalview.fts.api.FTSDataColumnI;
@@ -58,9 +59,7 @@ public abstract class FTSRestClient implements FTSRestClientI
 
   private int defaultResponsePageSize = 100;
 
-  protected String mockQuery = null;
-
-  protected String mockResponse = null;
+  protected HashMap<String,String> mockQueries = null;
 
   protected FTSRestClient()
   {
@@ -433,10 +432,14 @@ public abstract class FTSRestClient implements FTSRestClientI
             "Couldn't find data column with name : " + nameOrCode);
   }
 
-  public static void createMockFTSRestClient(FTSRestClient instance,String workingQuery,
-          String jsonResponse)
+  /**
+   * 
+   * @param instance
+   * @param mocks {{working query, working response}, ...}
+   */
+  public static void createMockFTSRestClient(FTSRestClient instance,String[][] mocks)
   {
-    instance.setMock(workingQuery,jsonResponse);
+    instance.setMock(mocks);
   }
 
   @Override
@@ -494,8 +497,7 @@ public abstract class FTSRestClient implements FTSRestClientI
 
   public static void unMock(FTSRestClient instance)
   {
-    instance.mockQuery =null;
-    instance.mockResponse =null;
+    instance.mockQueries=null;
   }
 
   protected String getResourceFile(String fileName)
@@ -522,15 +524,22 @@ public abstract class FTSRestClient implements FTSRestClientI
     return defaultResponsePageSize;
   }
 
-  protected void setMock(String workingQuery, String jsonResponse)
+  protected void setMock(String[][] mocks)
   {
-    mockQuery=workingQuery;
-    mockResponse = jsonResponse;
+    if (mocks==null) {
+      mockQueries=null;
+      return;
+    }
+    mockQueries=new HashMap<String,String>();
+    for (String[] mock:mocks)
+    {
+      mockQueries.put(mock[0],mock[1]);
+    }
   }
 
   protected boolean isMocked()
   {
-    return mockQuery != null && mockResponse!=null;
+    return mockQueries!=null;
   }
 
   @Override