PageRenderTime 23ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/com/t11e/discovery/datatool/JsonColumnsTest.java

http://github.com/t11e/discovery_datatool
Java | 117 lines | 113 code | 4 blank | 0 comment | 0 complexity | 0bc2a60c707dfd58d0392b216451b12e MD5 | raw file
  1package com.t11e.discovery.datatool;
  2
  3import java.util.Arrays;
  4import java.util.Collections;
  5
  6import org.dom4j.Document;
  7import org.junit.Test;
  8
  9public class JsonColumnsTest
 10  extends EndToEndTestBase
 11{
 12  @Test
 13  public void testDefault()
 14  {
 15    final Document doc = assertChangeset("none", "", "snapshot",
 16      Arrays.asList("1", "2", "3"),
 17      Collections.<String> emptyList(),
 18      false);
 19
 20    assertXpath("joe", doc,
 21      "/changeset/set-item[@id='1']/properties/struct/entry[@name='name']/string/text()");
 22    assertXpath("{'name':'joseph','age':21}".replace('\'', '"'), doc,
 23      "/changeset/set-item[@id='1']/properties/struct/entry[@name='JSON']/string/text()");
 24  }
 25
 26  @Test
 27  public void legacy()
 28  {
 29    testScopedJson("legacy");
 30  }
 31
 32  @Test
 33  public void scoped()
 34  {
 35    testScopedJson("scoped");
 36  }
 37
 38  private void testScopedJson(final String publisher)
 39  {
 40    final Document doc = assertChangeset(publisher, "", "snapshot",
 41      Arrays.asList("1", "2", "3"),
 42      Collections.<String> emptyList(),
 43      false);
 44
 45    assertXpath("joe", doc,
 46      "/changeset/set-item[@id='1']/properties/struct/entry[@name='name']/string/text()");
 47    assertXpath("joseph", doc,
 48      "/changeset/set-item[@id='1']/properties/struct/entry[@name='JSON']/struct/entry[@name='name']/string/text()");
 49    assertXpath("21", doc,
 50      "/changeset/set-item[@id='1']/properties/struct/entry[@name='JSON']/struct/entry[@name='age']/int/text()");
 51  }
 52
 53  @Test
 54  public void unscoped()
 55  {
 56    final Document doc = assertChangeset("unscoped", "", "snapshot",
 57      Arrays.asList("1", "2", "3"),
 58      Collections.<String> emptyList(),
 59      false);
 60
 61    assertXpath("joseph", doc,
 62      "/changeset/set-item[@id='1']/properties/struct/entry[@name='name']/string/text()");
 63    assertXpath("21", doc,
 64      "/changeset/set-item[@id='1']/properties/struct/entry[@name='age']/int/text()");
 65  }
 66
 67  @Test
 68  public void unscopedOrder()
 69  {
 70    final Document doc = assertChangeset("unscoped-order", "", "snapshot",
 71      Arrays.asList("1", "2", "3"),
 72      Collections.<String> emptyList(),
 73      false);
 74
 75    assertXpath("joe", doc,
 76      "/changeset/set-item[@id='1']/properties/struct/entry[@name='name']/string/text()");
 77    assertXpath("21", doc,
 78      "/changeset/set-item[@id='1']/properties/struct/entry[@name='age']/int/text()");
 79  }
 80
 81  @Test
 82  public void mixed()
 83  {
 84    final Document doc = assertChangeset("mixed", "", "snapshot",
 85      Arrays.asList("1", "2", "3"),
 86      Collections.<String> emptyList(),
 87      false);
 88
 89    assertXpath("joseph", doc,
 90      "/changeset/set-item[@id='1']/properties/struct/entry[@name='name']/string/text()");
 91    assertXpath("21", doc,
 92      "/changeset/set-item[@id='1']/properties/struct/entry[@name='age']/int/text()");
 93    assertXpath("joseph", doc,
 94      "/changeset/set-item[@id='1']/properties/struct/entry[@name='JSON']/struct/entry[@name='name']/string/text()");
 95    assertXpath("21", doc,
 96      "/changeset/set-item[@id='1']/properties/struct/entry[@name='JSON']/struct/entry[@name='age']/int/text()");
 97  }
 98
 99  @Test
100  public void mixedUpper()
101  {
102    final Document doc = assertChangeset("mixed-upper", "", "snapshot",
103      Arrays.asList("1", "2", "3"),
104      Collections.<String> emptyList(),
105      false);
106
107    assertXpath("joseph", doc,
108      "/changeset/set-item[@id='1']/properties/struct/entry[@name='NAME']/string/text()");
109    assertXpath("21", doc,
110      "/changeset/set-item[@id='1']/properties/struct/entry[@name='AGE']/int/text()");
111    assertXpath("joseph", doc,
112      "/changeset/set-item[@id='1']/properties/struct/entry[@name='JSON']/struct/entry[@name='name']/string/text()");
113    assertXpath("21", doc,
114      "/changeset/set-item[@id='1']/properties/struct/entry[@name='JSON']/struct/entry[@name='age']/int/text()");
115  }
116
117}