/*
 * Copyright (c) 2002-2014 Nu Echo Inc. All rights reserved.
 */

package com.fasterxml.jackson.dataformat.xml.failing;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import java.util.*;

import org.junit.*;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonTypeInfo.*;
import com.fasterxml.jackson.dataformat.xml.*;
import com.fasterxml.jackson.dataformat.xml.annotation.*;

/**
 * @author Nu Echo Inc.
 */
public class Issue97Test extends XmlTestBase
{
    @JsonTypeInfo(property = "type", use = Id.NAME)
    public static abstract class Foo {
        @JacksonXmlProperty(isAttribute = true)
        public String data;
    }

    @JsonTypeName("good")
    public static class FooGood extends Foo {
        public String bar;
    }

    @JsonTypeName("bad")
    public static class FooBad extends Foo {
        @JacksonXmlElementWrapper(useWrapping = false)
        public List<String> bar;
    }

    @Test
    public void testGood() throws Exception {
        XmlMapper mapper = new XmlMapper();
        mapper.registerSubtypes(FooGood.class);

        String xml = "<Foo type=\"good\" data=\"dummy\"><bar>FOOBAR</bar></Foo>";
        Foo fooRead = mapper.readValue(xml, Foo.class);
        assertThat(fooRead, instanceOf(FooGood.class));

        xml = "<Foo data=\"dummy\" type=\"good\" ><bar>FOOBAR</bar></Foo>";
        fooRead = mapper.readValue(xml, Foo.class);
        assertThat(fooRead, instanceOf(FooGood.class));
    }
    
    @Test
    public void testBad() throws Exception {
        XmlMapper mapper = new XmlMapper();
        mapper.registerSubtypes(FooBad.class);

        String xml = "<Foo type=\"bad\" data=\"dummy\"><bar><bar>FOOBAR</bar></bar></Foo>";
        Foo fooRead = mapper.readValue(xml, Foo.class);
        assertThat(fooRead, instanceOf(FooBad.class));

        xml = "<Foo data=\"dummy\" type=\"bad\"><bar><bar>FOOBAR</bar></bar></Foo>";
        fooRead = mapper.readValue(xml, Foo.class);
        assertThat(fooRead, instanceOf(FooBad.class));
    }
}

@@ -1,73 +1,4 @@
-/*%0A * Copyright (c) 2002-2014 Nu Echo Inc. All rights reserved.%0A */%0A%0A
 pack
@@ -392,20 +392,16 @@
 hor 
-Nu Echo Inc.
+pgelinas
 %0A */

fix #97