package de.ddb.pdc.metadata;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ApiUrlsTest {

  private static final String API_URL_PREFIX =
      "https://api.deutsche-digitale-bibliothek.de";

  @Test
  public void searchUrl() {
    assertEquals(API_URL_PREFIX +
        "/search?query=foo&offset=0&rows=123&sort=relevance&oauth_consumer_key=key",
        ApiUrls.searchUrl("foo", 0, 123, "relevance", "key"));
  }

  @Test
  public void complexSearchUrl() {
    String query = "+testing-the!syntax?right&&now\\";
    assertEquals(API_URL_PREFIX +
        "/search?query=\\+testing\\-the\\!syntax\\?right\\&&now\\\\" +
        "&offset=0&rows=10&sort=relevance&oauth_consumer_key=key",
        ApiUrls.searchUrl(query, 0, 10, "relevance", "key"));

  }

  @Test
  public void itemAipUrl() {
    assertEquals(API_URL_PREFIX +
        "/items/abcde/aip?oauth_consumer_key=key",
        ApiUrls.itemAipUrl("abcde", "key"));
  }

  @Test
  public void entityUrl() {
    assertEquals(API_URL_PREFIX +
        "/entities?query=id:\"abcde\"&oauth_consumer_key=key",
        ApiUrls.entityUrl("abcde", "key"));
  }
}
@@ -471,24 +471,27 @@
 oid 
-complexSearchUrl
+searchUrlWithSpaces
 () %7B
@@ -515,40 +515,15 @@
  = %22
-+testing-the!syntax?right&&now%5C%5C
+foo bar
 %22;%0A 
@@ -582,52 +582,18 @@
 ery=
-%5C%5C+testing%5C%5C-the%5C%5C!syntax%5C%5C?right%5C%5C&&now%5C%5C%5C%5C
+foo OR bar
 %22 +%0A

Fix ApiUrlsTest