package org.gbif.checklistbank.ws.client;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.WebResource;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class NameUsageMatchWsClientTest {

  /**
   * Test http://dev.gbif.org/issues/browse/POR-2688
   * We expect a client handler exception cause we did not setup the entire jersey stack properly.
   * We only want to make sure there is no UriBuilderException thrown
   */
  @Test(expected = ClientHandlerException.class)
  public void testCurlyBrackets() {
    WebResource api = Client.create().resource("http://api.gbif.org/v1/species/match");
    WebResource  q = api.queryParam("name", "Nereis southerni %7B%7Bnowrap Abdel-Moez & Humphries, 1955");
    assertEquals(
      "http://api.gbif.org/v1/species/match?name=Nereis+southerni+%7B%7Bnowrap+Abdel-Moez+%26+Humphries,+1955",
      q.toString());

    NameUsageMatchWsClient client = new NameUsageMatchWsClient(api);

    client.match("Nereis southerni {{nowrap Abdel-Moez & Humphries, 1955", null, null, false, false);
  }

}

@@ -47,41 +47,46 @@
 ort 
-com.sun.jersey.api.client.Client;
+javax.ws.rs.core.UriBuilderException;%0A
 %0Aimp
@@ -121,32 +121,16 @@
 t.Client
-HandlerException
 ;%0Aimport
@@ -373,16 +373,37 @@
 handler 
+or uniform interface 
 exceptio
@@ -548,49 +548,8 @@
 Test
-(expected = ClientHandlerException.class)
 %0A  p
@@ -581,16 +581,28 @@
 ets() %7B%0A
+    try %7B%0A  
     WebR
@@ -681,24 +681,26 @@
 atch%22);%0A    
+ 
+ 
 WebResource 
@@ -794,16 +794,18 @@
 %22);%0A    
+  
 assertEq
@@ -816,16 +816,18 @@
 (%0A      
+ 
+ 
 %22http://
@@ -930,16 +930,18 @@
 ,%0A      
+  
 q.toStri
@@ -952,16 +952,18 @@
 );%0A%0A    
+ 
+ 
 NameUsag
@@ -1016,24 +1016,26 @@
 ient(api);%0A%0A
+  
     client.m
@@ -1124,15 +1124,167 @@
 false);%0A
+    %7D catch (RuntimeException e) %7B%0A      if (e instanceof UriBuilderException) %7B%0A        throw e;%0A      %7D%0A      System.out.println(e.toString());%0A    %7D%0A
   %7D%0A%0A%7D%0A

Allow NameUsageMatchWsClientTest to work with broken nub-ws