package org.folio.rest.tools.utils;

import static org.junit.Assert.assertEquals;

import org.apache.commons.io.IOUtils;
import org.folio.rest.tools.client.Response;
import org.folio.rest.tools.parser.JsonPathParser;
import org.junit.Test;

import io.vertx.core.json.JsonObject;

/**
 * @author shale
 *
 */
public class ResponseTest {

  @Test
  public void check() {
    JsonObject j1 = null;
    JsonObject j2 = null;

    try {
      j1 = new JsonObject(
        IOUtils.toString(JsonPathParser.class.getClassLoader().
          getResourceAsStream("pathTest.json"), "UTF-8"));

      j2 = new JsonObject(
        IOUtils.toString(JsonPathParser.class.getClassLoader().
          getResourceAsStream("pathTest.json"), "UTF-8"));

      Response test1 = new Response();
      test1.setBody(j1);
      Response test2 = new Response();
      test2.setBody(j2);
      JsonPathParser jpp = new JsonPathParser( test1.joinOn("c.a1", test2, "a", "c.arr[1]").getBody() );
      assertEquals(jpp.getValueAt("c.a1.ignore"), "true");

    } catch (Exception e) {
      e.printStackTrace();
    }
  }

}

@@ -74,16 +74,148 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertNull;%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Aimport
@@ -987,16 +987,17 @@
 dy(j2);%0A
+%0A
       Js
@@ -1149,24 +1149,470 @@
 , %22true%22);%0A%0A
+      //check non existent path%0A      assertNull(jpp.getValueAt(%22c.a1.ignores!SA%22));%0A%0A      //non existent insertField%0A      assertNull(new JsonPathParser(test1.joinOn(%22c.a1%22, test2, %22a%22, %22c.arr%5B5%5D%22).getBody())%0A        .getValueAt(%22a.c.a1%22));%0A%0A      //non existant insertField and join field -%0A      assertNotNull(test1.joinOn(%22c.a9%22, test2, %22a%22, %22c.arr%5B5%5D%22));%0A      //System.out.println(test1.joinOn(%22c.a9%22, test2, %22a%22, %22c.arr%5B5%5D%22).getBody());%0A%0A
     %7D catch 
@@ -1650,24 +1650,49 @@
 ackTrace();%0A
+      assertTrue(false);%0A
     %7D%0A  %7D%0A%0A%7D

add more tests