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.issues.issue9;
    18
    19  import java.util.Iterator;
    20
    21  import junit.framework.TestCase;
    22
    23  import org.yaml.snakeyaml.Yaml;
    24
    25  public class NopropTest extends TestCase {
    26
    27      public void testOK01() {
    28          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean1\n  intVal : 11\n  strVal : HALLO_1 ";
    29          Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    30          assertTrue(docs.hasNext());
    31          BeanHolder beanHolder = (BeanHolder) docs.next();
    32          assertEquals("HALLO_1", beanHolder.getBean().getStrVal());
    33          assertEquals(11, beanHolder.getBean().getIntVal());
    34      }
    35
    36      public void testOK02() {
    37          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean2\n  intVal : 22\n  strVal : HALLO_2 ";
    38          Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    39          assertTrue(docs.hasNext());
    40          BeanHolder beanHolder = (BeanHolder) docs.next();
    41          assertEquals("HALLO_2", beanHolder.getBean().getStrVal());
    42          assertEquals(22, beanHolder.getBean().getIntVal());
    43      }
    44
    45      public void testOK03() {
    46          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean1\n  intVal : 1";
    47          Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    48          assertTrue(docs.hasNext());
    49          BeanHolder beanHolder = (BeanHolder) docs.next();
    50          assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    51          assertEquals(1, beanHolder.getBean().getIntVal());
    52      }
    53
    54      public void testOK04() {
    55          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean2\n  intVal : 22";
    56          Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    57          assertTrue(docs.hasNext());
    58          BeanHolder beanHolder = (BeanHolder) docs.next();
    59          assertEquals("BEAN_2", beanHolder.getBean().getStrVal());
    60          assertEquals(22, beanHolder.getBean().getIntVal());
    61      }
    62
    63      public void testOK05() {
    64          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean1\n  strVal : HALLO_1 ";
    65          Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    66          assertTrue(docs.hasNext());
    67          BeanHolder beanHolder = (BeanHolder) docs.next();
    68          assertEquals("HALLO_1", beanHolder.getBean().getStrVal());
    69          assertEquals(1, beanHolder.getBean().getIntVal());
    70      }
    71
    72      public void testOK06() {
    73          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean2\n  strVal : HALLO_2 ";
    74          Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    75          assertTrue(docs.hasNext());
    76          BeanHolder beanHolder = (BeanHolder) docs.next();
    77          assertEquals("HALLO_2", beanHolder.getBean().getStrVal());
    78          assertEquals(2, beanHolder.getBean().getIntVal());
    79      }
    80
    81      public void testEmptyBean() {
    82          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean1";
    83          Iterator<Object> docs = new Yaml(new BeanConstructor()).loadAll(yaml).iterator();
    84          assertTrue(docs.hasNext());
    85          BeanHolder beanHolder = (BeanHolder) docs.next();
    86          assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    87          assertEquals(1, beanHolder.getBean().getIntVal());
    88      }
    89
    90      public void testEmptyBean2() {
    91          String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean1 {}";
    92          Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    93          assertTrue(docs.hasNext());
    94          BeanHolder beanHolder = (BeanHolder) docs.next();
    95          assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    96          assertEquals(1, beanHolder.getBean().getIntVal());
    97      }
    98
    99      public void testEmptyDoc() {
    100         String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder";
    101         Iterator<Object> docs = new Yaml(new BeanConstructor()).loadAll(yaml).iterator();
    102         assertTrue(docs.hasNext());
    103         BeanHolder beanHolder = (BeanHolder) docs.next();
    104         assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    105         assertEquals(3, beanHolder.getBean().getIntVal());
    106     }
    107
    108     public void testEmptyDoc2() {
    109         String yaml = "---";
    110         Iterator<Object> docs = new Yaml(new BeanConstructor()).loadAll(yaml).iterator();
    111         assertTrue(docs.hasNext());
    112         BeanHolder beanHolder = (BeanHolder) docs.next();
    113         assertNotNull(beanHolder);
    114         assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    115         assertEquals(3, beanHolder.getBean().getIntVal());
    116         // only space is also null
    117         yaml = "--- ";
    118         docs = new Yaml(new BeanConstructor()).loadAll(yaml).iterator();
    119         assertTrue(docs.hasNext());
    120         beanHolder = (BeanHolder) docs.next();
    121         assertNotNull(beanHolder);
    122         assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    123         assertEquals(3, beanHolder.getBean().getIntVal());
    124         // only space is also null
    125         yaml = "--- '23'";
    126         docs = new Yaml(new BeanConstructor()).loadAll(yaml).iterator();
    127         assertTrue(docs.hasNext());
    128         beanHolder = (BeanHolder) docs.next();
    129         assertNotNull(beanHolder);
    130         assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    131         assertEquals(23, beanHolder.getBean().getIntVal());
    132     }
    133
    134     public void testEmptyDoc3() {
    135         String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder";
    136         Iterator<Object> docs = new Yaml(new BeanConstructor3()).loadAll(yaml).iterator();
    137         assertTrue(docs.hasNext());
    138         BeanHolder beanHolder = (BeanHolder) docs.next();
    139         assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    140         assertEquals(1, beanHolder.getBean().getIntVal());
    141     }
    142
    143     public void testNonBean() {
    144         String yaml = "--- !!org.yaml.snakeyaml.issues.issue9.BeanHolder\nbean : !!org.yaml.snakeyaml.issues.issue9.Bean1 123";
    145         Iterator<Object> docs = new Yaml().loadAll(yaml).iterator();
    146         assertTrue(docs.hasNext());
    147         BeanHolder beanHolder = (BeanHolder) docs.next();
    148         assertEquals("BEAN_1", beanHolder.getBean().getStrVal());
    149         assertEquals(123, beanHolder.getBean().getIntVal());
    150     }
    151 }