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.partialconstruct;
17 
18 import junit.framework.TestCase;
19 
20 import org.yaml.snakeyaml.composer.Composer;
21 import org.yaml.snakeyaml.constructor.Constructor;
22 import org.yaml.snakeyaml.parser.ParserImpl;
23 import org.yaml.snakeyaml.reader.StreamReader;
24 import org.yaml.snakeyaml.resolver.Resolver;
25 
26 public class FragmentComposerTest extends TestCase {
27 
testFragment()28     public void testFragment() {
29         String document = "foo:  blargle\n"
30                 + "developer:  { name: \"Bjarne Stroustrup\", language: \"C++\"}\n"
31                 + "gee:  [ \"whiz\", \"bang\"]\n";//
32 
33         StreamReader reader = new StreamReader(document);
34         Composer composer = new FragmentComposer(new ParserImpl(reader), new Resolver(),
35                 "developer");
36         Constructor constructor = new Constructor();
37         constructor.setComposer(composer);
38         DeveloperBean developer = (DeveloperBean) constructor.getSingleData(DeveloperBean.class);
39         assertEquals("Bjarne Stroustrup", developer.name);
40         assertEquals("C++", developer.language);
41     }
42 }
43