You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "John Wagenleitner (JIRA)" <ji...@apache.org> on 2016/04/21 20:19:25 UTC

[jira] [Commented] (GROOVY-6696) @attribute on groovy.util.Node does not work when meta class is modified

    [ https://issues.apache.org/jira/browse/GROOVY-6696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15252391#comment-15252391 ] 

John Wagenleitner commented on GROOVY-6696:
-------------------------------------------

Running the following in GroovyConsole succeeds, I tested with 2.2.2, 2.4.6 and master:

{code}
import org.junit.*
import static org.junit.Assert.*

class Groovy6696Bug  {
    @Test
    public void notWorking() throws Exception {
        //given
        Node.metaClass.findParent = { closure ->
            def parent = delegate.parent()
            if(parent == null){
                return null
            }
            if(closure(parent)){
                return parent
            }
            return parent.findParent(closure)
        }

        def root = new XmlParser().parseText('''<node id="12">value</node>''')

        //when
        String id = root.@id;

        //then
        assertEquals("12", id);
    }
}
{code}

Results are:

{code}
JUnit 4 Runner, Tests: 1, Failures: 0, Time: 31
{code}

> @attribute on groovy.util.Node does not work when meta class is modified
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-6696
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6696
>             Project: Groovy
>          Issue Type: Bug
>          Components: XML Processing
>    Affects Versions: 2.2.2
>            Reporter: Baptiste Mesta
>            Priority: Minor
>
> if a closure is added to the meta class it seems that the node.@attribute is not working anymore
> however it is still working when we use quotes, i.e. node.'@attribute'
> here is some tests that reproduce the probleme, they have to be run alone
> {code:java}
>     @Test
>     public void working() throws Exception {
>         //given
>         def root = new XmlParser().parseText('''<node id="12">value</node>''')
>         //when
>         String id = root.@id;
>         //then
>         assertEquals("12", id);
>     }
>     @Test
>     public void notWorking() throws Exception {
>         //given
>         Node.metaClass.findParent = { closure ->
>             def parent = delegate.parent()
>             if(parent == null){
>                 return null
>             }
>             if(closure(parent)){
>                 return parent
>             }
>             return parent.findParent(closure)
>         }
>         def root = new XmlParser().parseText('''<node id="12">value</node>''')
>         //when
>         String id = root.@id;
>         //then
>         assertEquals("12", id);
>     }
>     @Test
>     public void workingOnlyWithQuotes() throws Exception {
>         //given
>         Node.metaClass.findParent = { closure ->
>             def parent = delegate.parent()
>             if(parent == null){
>                 return null
>             }
>             if(closure(parent)){
>                 return parent
>             }
>             return parent.findParent(closure)
>         }
>         def root = new XmlParser().parseText('''<node id="12">value</node>''')
>         //when
>         String id = root.'@id';
>         //then
>         assertEquals("12", id);
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)