/**
 * Copyright (c) 2008-2012, http://www.snakeyaml.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.yaml.snakeyaml.issues.issue56;

import java.util.Map;

import junit.framework.TestCase;

import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Util;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Construct;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.Tag;

public class PerlTest extends TestCase {

    @SuppressWarnings("unchecked")
    public void testMaps() {
        Yaml yaml = new Yaml(new CustomConstructor());
        String input = Util.getLocalResource("issues/issue56-1.yaml");
        int counter = 0;
        for (Object obj : yaml.loadAll(input)) {
            // System.out.println(obj);
            Map<String, Object> map = (Map<String, Object>) obj;
            Integer oid = (Integer) map.get("oid");
            assertTrue(oid > 10000);
            counter++;
        }
        assertEquals(4, counter);
        assertEquals(0, CodeBean.counter);
    }

    private class CustomConstructor extends SafeConstructor {
        public CustomConstructor() {
            // define tags which begin with !org.yaml.
            String prefix = "!de.oddb.org,2007/ODDB";
            this.yamlMultiConstructors.put(prefix, new ConstructYamlMap());
        }
    }

    @SuppressWarnings("unchecked")
    public void testJavaBeanWithTypeDescription() {
        Constructor c = new CustomBeanConstructor();
        TypeDescription descr = new TypeDescription(CodeBean.class, new Tag(
                "!de.oddb.org,2007/ODDB::Util::Code"));
        c.addTypeDescription(descr);
        Yaml yaml = new Yaml(c);
        String input = Util.getLocalResource("issues/issue56-1.yaml");
        int counter = 0;
        for (Object obj : yaml.loadAll(input)) {
            // System.out.println(obj);
            Map<String, Object> map = (Map<String, Object>) obj;
            Integer oid = (Integer) map.get("oid");
            assertTrue(oid > 10000);
            counter++;
        }
        assertEquals(4, counter);
        assertEquals(55, CodeBean.counter);
    }

    @SuppressWarnings("unchecked")
    public void testJavaBean() {
        Constructor c = new CustomBeanConstructor();
        Yaml yaml = new Yaml(c);
        String input = Util.getLocalResource("issues/issue56-1.yaml");
        int counter = 0;
        for (Object obj : yaml.loadAll(input)) {
            // System.out.println(obj);
            Map<String, Object> map = (Map<String, Object>) obj;
            Integer oid = (Integer) map.get("oid");
            assertTrue(oid > 10000);
            counter++;
        }
        assertEquals(4, counter);
        assertEquals(55, CodeBean.counter);
    }

    private class CustomBeanConstructor extends Constructor {
        public CustomBeanConstructor() {
            // define tags which begin with !org.yaml.
            String prefix = "!de.oddb.org,2007/ODDB";
            this.yamlMultiConstructors.put(prefix, new ConstructYamlMap());
        }

        protected Construct getConstructor(Node node) {
            if (node.getTag().equals(new Tag("!de.oddb.org,2007/ODDB::Util::Code"))) {
                node.setUseClassConstructor(true);
                node.setType(CodeBean.class);
            }
            return super.getConstructor(node);
        }
    }

    @Override
    protected void setUp() {
        CodeBean.counter = 0;
    }
}

@@ -656,16 +656,76 @@
 sue56;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.LinkedHashMap;%0A
 import j
@@ -738,16 +738,16 @@
 il.Map;%0A
-
 %0Aimport 
@@ -1167,32 +1167,34 @@
 uppressWarnings(
+%7B 
 %22unchecked%22)%0A   
@@ -1180,32 +1180,46 @@
 gs(%7B %22unchecked%22
+, %22rawtypes%22 %7D
 )%0A    public voi
@@ -1530,32 +1530,32 @@
 , Object%3E) obj;%0A
-
             Inte
@@ -1582,32 +1582,823 @@
 map.get(%22oid%22);%0A
+            if (oid == 123058) %7B%0A                ArrayList a = (ArrayList) map.get(%22sequences%22);%0A                LinkedHashMap b = (LinkedHashMap) a.get(0);%0A                LinkedHashMap c = (LinkedHashMap) b.get(%22atc%22);%0A                LinkedHashMap d = (LinkedHashMap) c.get(%22name%22);%0A                LinkedHashMap e = (LinkedHashMap) d.get(%22canonical%22);%0A                String acidNameDe = e.entrySet().toArray()%5B1%5D.toString();%0A                assertEquals(%22Unicode escaped sequence must be decoded.%22,%0A                        %22:de=Acetylsalicyls%C3%83%C2%A4ure%22, acidNameDe);%0A                /*%0A                 * TODO issue 151:%0A                 * assertEquals(%22Unicode escaped sequence must be decoded.%22,%0A                 * %22:de=Acetylsalicyls%C3%A4ure%22, acidNameDe);%0A                 */%0A            %7D%0A
             asse

Add a test for issue 151