Home | History | Annotate | Download | only in composer
      1 /**
      2  * Copyright (c) 2008, 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 package org.yaml.snakeyaml.composer;
     17 
     18 import java.io.StringReader;
     19 
     20 import junit.framework.TestCase;
     21 
     22 import org.yaml.snakeyaml.Yaml;
     23 import org.yaml.snakeyaml.nodes.MappingNode;
     24 import org.yaml.snakeyaml.nodes.Node;
     25 import org.yaml.snakeyaml.nodes.NodeId;
     26 
     27 public class ComposerImplTest extends TestCase {
     28 
     29     public void testGetNode() {
     30         String data = "american:\n  - Boston Red Sox";
     31         Yaml yaml = new Yaml();
     32         Node node = yaml.compose(new StringReader(data));
     33         assertNotNull(node);
     34         assertTrue(node instanceof MappingNode);
     35         String data2 = "---\namerican:\n- Boston Red Sox";
     36         Node node2 = yaml.compose(new StringReader(data2));
     37         assertNotNull(node2);
     38         assertFalse(node.equals(node2));
     39     }
     40 
     41     public void testComposeBean() {
     42         String data = "!!org.yaml.snakeyaml.composer.ComposerImplTest$BeanToCompose {name: Bill, age: 18}";
     43         Yaml yaml = new Yaml();
     44         Node node = yaml.compose(new StringReader(data));
     45         assertNotNull(node);
     46         assertTrue(node instanceof MappingNode);
     47         assertEquals(
     48                 "tag:yaml.org,2002:org.yaml.snakeyaml.composer.ComposerImplTest$BeanToCompose",
     49                 node.getTag().getValue());
     50         assertEquals(NodeId.mapping, node.getNodeId());
     51         assertEquals(Object.class, node.getType());
     52     }
     53 
     54     public static class BeanToCompose {
     55         private String name;
     56         private int age;
     57 
     58         public String getName() {
     59             return name;
     60         }
     61 
     62         public void setName(String name) {
     63             this.name = name;
     64         }
     65 
     66         public int getAge() {
     67             return age;
     68         }
     69 
     70         public void setAge(int age) {
     71             this.age = age;
     72         }
     73     }
     74 }
     75