@Test
  public void testMapping() throws Exception {
    Session s = openSession();
    FullTextSession session = Search.getFullTextSession(s);
    Transaction tx = s.beginTransaction();

    QueryDescriptor query =
        ElasticsearchQueries.fromJson("{ 'query': { 'match' : { 'lastName' : 'Hergesheimer' } } }");
    List<?> result =
        session
            .createFullTextQuery(query, GolfPlayer.class)
            .setProjection(ProjectionConstants.SOURCE)
            .list();

    String source = (String) ((Object[]) result.iterator().next())[0];

    JsonHelper.assertJsonEqualsIgnoringUnknownFields(
        "{"
            + "\"active\": true,"
            + "\"dateOfBirth\": \"1958-04-07T00:00:00Z\","
            + "\"driveWidth\": 285,"
            + "\"firstName\": \"Klaus\","
            + "\"handicap\": 3.4,"
            + "\"lastName\": \"Hergesheimer\","
            + "\"fullName\": \"Klaus Hergesheimer\","
            + "\"age\": 34,"
            + "\"puttingStrength\": \"2.5\""
            + "}",
        source);

    tx.commit();
    s.close();
  }
  @Test
  public void testElementCollectionOfBasicTypeMapping() throws Exception {
    Session s = openSession();
    FullTextSession session = Search.getFullTextSession(s);
    Transaction tx = s.beginTransaction();

    QueryDescriptor query =
        ElasticsearchQueries.fromJson("{ 'query': { 'match' : { 'lastName' : 'Hergesheimer' } } }");
    List<?> result =
        session
            .createFullTextQuery(query, GolfPlayer.class)
            .setProjection(ProjectionConstants.SOURCE)
            .list();

    String source = (String) ((Object[]) result.iterator().next())[0];

    JsonHelper.assertJsonEqualsIgnoringUnknownFields(
        "{"
            + "\"lastName\": \"Hergesheimer\","
            + "\"strengths\": ["
            + "\"willingness\", \"precision\", \"stamina\""
            + "]"
            + "}",
        source);

    tx.commit();
    s.close();
  }
  @Test
  public void testEmbeddedListOfEntityMapping() throws Exception {
    Session s = openSession();
    FullTextSession session = Search.getFullTextSession(s);
    Transaction tx = s.beginTransaction();

    QueryDescriptor query =
        ElasticsearchQueries.fromJson("{ 'query': { 'match' : { 'lastName' : 'Brand' } } }");
    List<?> result =
        session
            .createFullTextQuery(query, GolfPlayer.class)
            .setProjection(ProjectionConstants.SOURCE)
            .list();

    String source = (String) ((Object[]) result.iterator().next())[0];

    JsonHelper.assertJsonEqualsIgnoringUnknownFields(
        "{"
            + "'lastName' : 'Brand',"
            + "'playedCourses': ["
            + "{"
            + "'name' : 'Purbeck',"
            + "'rating' : 127.3, "
            + "'holes': ["
            + "{ 'par' : 4, 'length' : 433 },"
            + "{ 'par' : 3, 'length' : 163 }"
            + "]"
            + "},"
            + "{"
            + "'name' : 'Mount Maja',"
            + "'rating' : 111.9, "
            + "'holes': ["
            + "{ 'par' : 5, 'length' : 512 },"
            + "{ 'par' : 3, 'length' : 113 }"
            + "]"
            + "}"
            + "]"
            + "}",
        source);

    tx.commit();
    s.close();
  }
  @Test
  public void testNullTokenMapping() {
    Session s = openSession();
    FullTextSession session = Search.getFullTextSession(s);
    Transaction tx = s.beginTransaction();

    QueryDescriptor query = ElasticsearchQueries.fromQueryString("lastName:Kidd");
    List<?> result =
        session
            .createFullTextQuery(query, GolfPlayer.class)
            .setProjection(ProjectionConstants.SOURCE)
            .list();

    String source = (String) ((Object[]) result.iterator().next())[0];

    JsonHelper.assertJsonEquals(
        "{"
            + "\"active\": null,"
            + "\"dateOfBirth\": null,"
            + "\"driveWidth\": null,"
            + "\"firstName\": null,"
            + "\"handicap\": 0.0,"
            + // not nullable
            "\"puttingStrength\": \"0.0\","
            + // not nullable
            "\"lastName\": \"Kidd\","
            + "\"fullName\": \"Kidd\""
            +
            // ranking.value is null but indexNullAs() has not been given, so it's
            // not present in the index at all
            // "\"ranking\": {" +
            //     "\"value\": ..." +
            // "}" +
            "}",
        source);

    tx.commit();
    s.close();
  }
  @Test
  public void testEmbeddedMapping() throws Exception {
    Session s = openSession();
    FullTextSession session = Search.getFullTextSession(s);
    Transaction tx = s.beginTransaction();

    QueryDescriptor query =
        ElasticsearchQueries.fromJson("{ 'query': { 'match' : { 'lastName' : 'Galore' } } }");
    List<?> result =
        session
            .createFullTextQuery(query, GolfPlayer.class)
            .setProjection(ProjectionConstants.SOURCE)
            .list();

    String source = (String) ((Object[]) result.iterator().next())[0];

    JsonHelper.assertJsonEqualsIgnoringUnknownFields(
        "{" + "\"lastName\": \"Galore\"," + "\"ranking\": {" + "\"value\": \"311\"" + "}" + "}",
        source);

    tx.commit();
    s.close();
  }