View Javadoc

    1   /**
    2    * Copyright (c) 2008-2011, http://www.snakeyaml.org
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *     http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package org.yaml.snakeyaml;
    18
    19  import java.util.Date;
    20  import java.util.List;
    21  import java.util.Map;
    22
    23  import junit.framework.TestCase;
    24
    25  /**
    26   * Test Chapter 2.5 from the YAML specification
    27   *
    28   * @author py4fun
    29   * @see http://yaml.org/spec/1.1/
    30   */
    31  public class Chapter2_5Test extends TestCase {
    32
    33      @SuppressWarnings("unchecked")
    34      public void testExample_2_28() {
    35          YamlStream resource = new YamlStream("example2_28.yaml");
    36          List<Object> list = (List<Object>) resource.getNativeData();
    37          assertEquals(3, list.size());
    38          Map<String, Object> data0 = (Map<String, Object>) list.get(0);
    39          Date date = (Date) data0.get("Time");
    40          assertEquals("Date: " + date, 1006545702000L, date.getTime());
    41          assertEquals("ed", data0.get("User"));
    42          assertEquals("This is an error message for the log file", data0.get("Warning"));
    43          //
    44          Map<String, Object> data1 = (Map<String, Object>) list.get(1);
    45          Date date1 = (Date) data1.get("Time");
    46          assertTrue("Date: " + date1, date1.after(date));
    47          assertEquals("ed", data1.get("User"));
    48          assertEquals("A slightly different error message.", data1.get("Warning"));
    49          //
    50          Map<String, Object> data3 = (Map<String, Object>) list.get(2);
    51          Date date3 = (Date) data3.get("Date");
    52          assertTrue("Date: " + date3, date3.after(date1));
    53          assertEquals("ed", data3.get("User"));
    54          assertEquals("Unknown variable \"bar\"", data3.get("Fatal"));
    55          List<Map<String, String>> list3 = (List<Map<String, String>>) data3.get("Stack");
    56          Map<String, String> map1 = list3.get(0);
    57          assertEquals("TopClass.py", map1.get("file"));
    58          assertEquals(new Integer(23), map1.get("line"));
    59          assertEquals("x = MoreObject(\"345\\n\")\n", map1.get("code"));
    60          Map<String, String> map2 = list3.get(1);
    61          assertEquals("MoreClass.py", map2.get("file"));
    62          assertEquals(new Integer(58), map2.get("line"));
    63          assertEquals("foo = bar", map2.get("code"));
    64      }
    65  }