using OpenEdge.Core.Assert.
using OpenEdge.Core.AssertionFailedError.

routine-level on error undo, throw.

/**
 * Test OE Dataset.
 */
class oo.TestDataset:

  @Test.
  METHOD PUBLIC VOID testDatasetFromXML():
    DEFINE VARIABLE dsData AS HANDLE NO-UNDO.
    DEFINE VARIABLE xml AS LONGCHAR NO-UNDO.

   CREATE DATASET dsData.
   xml = "<?xml version=~"1.0~"?>"
                 + "<ProDataSet>"
                 +   "<Customer>"
                 +     "<customerName>John Smith</customerName>"
                 +     "<customerNum>10</customerNum>"
                 +   "</Customer>"
                 +   "<Customer>"
                 +     "<customerName>Freddie Mercury</customerName>"
                 +     "<customerNum>11</customerNum>"
                 +   "</Customer>"
                 +   "<Order>"
                 +     "<orderNum>1</orderNum>"
                 +     "<customerNum>10</customerNum>"
                 +     "<address>Address 1</address>"
                 +   "</Order>"
                 + "</ProDataSet>".
    Assert:IsTrue(dsData:READ-XML("longchar", xml, ?, ?, ?)).
    Assert:Equals(2, dsData:NUM-TOP-BUFFERS).
  END METHOD.
   
  @Test.
  METHOD PUBLIC VOID testDatasetFromJSON():
    DEFINE VARIABLE dsData AS HANDLE NO-UNDO.
    DEFINE VARIABLE jsonSource AS LONGCHAR NO-UNDO.

   CREATE DATASET dsData.
   jsonSource = "~{ ~"data~": [~{ ~"value1~": ~"asdf~", ~"value2~": ~"asdf~"},"
              + "~{ ~"value1~": ~"bvcx~", ~"value2~": ~"bvcx~"},"
              + "~{ ~"value1~": ~"qwerty~", ~"value2~": ~"bvcx~"}]}".
    Assert:IsTrue(dsData:READ-JSON("longchar", jsonSource, ?)).
    Assert:Equals(1, dsData:NUM-TOP-BUFFERS).
  END METHOD.

  @Test.   
  METHOD PUBLIC VOID testDatasetFromJSON2():
    DEFINE VARIABLE dsData AS HANDLE NO-UNDO.
    DEFINE VARIABLE jsonSource AS LONGCHAR NO-UNDO.

    CREATE DATASET dsData.
    jsonSource = "~{ ~"data1~": [~{ ~"value1~": ~"asdf~", ~"value2~": ~"asdf~"},"
                            + "~{ ~"value1~": ~"bvcx~", ~"value2~": ~"bvcx~"},"
                            + "~{ ~"value1~": ~"qwerty~", ~"value2~": ~"bvcx~"}],"
               + " ~"data2~": [~{ ~"value1~": ~"asdf~", ~"value2~": ~"asdf~"},"
                            + "~{ ~"value1~": ~"bvcx~", ~"value2~": ~"bvcx~"},"
                            + "~{ ~"value1~": ~"qwerty~", ~"value2~": ~"bvcx~"}]}".
    Assert:IsTrue(dsData:READ-JSON("longchar", jsonSource, ?)).
    Assert:Equals(2, dsData:NUM-TOP-BUFFERS).
  END METHOD.
   
end class.
