commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "BRABANT Benjamin (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (DIGESTER-177) Adding SetLeaf Rule
Date Tue, 02 Jul 2013 19:51:19 GMT

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

BRABANT Benjamin edited comment on DIGESTER-177 at 7/2/13 7:50 PM:
-------------------------------------------------------------------

Hello,

I attached the annotation TestCase. I encountered problems that I bypassed but I think they
should be corrected despite everything.

First, I had to add the Override method herebelow otherwise the Group Class I annoted was
not configured and parsing result in failure. I don't understand why this problem occured
but facing other annotation TestCase I think that Group Class should be configured automatically
without adding this method.

{code:title=CollectionTestCase.java|borderStyle=solid}
@Override
protected Collection<RulesModule> getAuxModules() {
	Collection<RulesModule> modules = new Stack<RulesModule>();
	modules.add(new FromAnnotationsRuleModule() {

		@Override
		protected void configureRules() {
			bindRulesFrom(Group.class);
		}

	});
	return modules;
}
{code}

Then, I would like to use regex pattern for my test so I began modifying the AbstractAnnotatedPojoTestCase
Class as below :

{code:title=AbstractAnnotatedPojoTestCase.java|borderStyle=solid}
public final void verifyExpectedEqualsToParsed(Object expected) throws Exception {
    [...]

    Digester digester = newLoader(modules).newDigester();
    digester.setRules(new RegexRules(new RegexMatcher()));
    Object actual = digester.parse(input);

    [...]
}
{code}

Setting the Rules implementation as above result the parsing method returning a null object
whereas the code below works properly :
	
{code:title=AbstractAnnotatedPojoTestCase.java|borderStyle=solid}
public final void verifyExpectedEqualsToParsed(Object expected) throws Exception {
    [...]

    Digester digester = newLoader(modules).newDigester(new RegexRules(new RegexMatcher()));
    Object actual = digester.parse(input);

    [...]
}
{code}

Thus, in the same way the getAuxModules() method can be overrided, I created the method below
that can be overrided and I modified the verifyExpectedEqualsToParsed method in consequence
in case developper wants to run his tests with another Rules implementation.

{code:title=AbstractAnnotatedPojoTestCase.java|borderStyle=solid}
public final void verifyExpectedEqualsToParsed(Object expected) throws Exception {
    [...]

    Digester digester = newLoader(modules).newDigester(this.getRules());
    Object actual = digester.parse(input);

    [...]
}

[...]

protected Rules getRules() {
    return new RulesBase();
}
{code}
{code:title=AbstractAnnotatedPojoTestCase.java|borderStyle=solid}
@Override
protected Rules getRules() {
   return new RegexRules(new SimpleRegexMatcher());
}
{code}
Please let me know if I have to open another issue for these potential bugs.

Thanks in advance
                
      was (Author: maastiff):
    Hello,

I attached the annotation TestCase. I encountered problems that I bypassed but I think they
should be corrected despite everything.

First, I had to add the Override method herebelow otherwise the Group Class I annoted was
not configured and parsing result in failure. I don't understand why this problem occured
but facing other annotation TestCase I think that Group Class should be configured automatically
without adding this method.

{code:title=CollectionTestCase.java|borderStyle=solid}
@Override
protected Collection<RulesModule> getAuxModules() {
	Collection<RulesModule> modules = new Stack<RulesModule>();
	modules.add(new FromAnnotationsRuleModule() {

		@Override
		protected void configureRules() {
			bindRulesFrom(Group.class);
		}

	});
	return modules;
}
{code}

Then, I would like to use regex pattern for my test so I began modifying the AbstractAnnotatedPojoTestCase
Class as below :

{code:title=AbstractAnnotatedPojoTestCase.java|borderStyle=solid}
public final void verifyExpectedEqualsToParsed(Object expected) throws Exception {
    [...]

    Digester digester = newLoader(modules).newDigester();
    digester.setRules(new RegexRules(new RegexMatcher()));
    Object actual = digester.parse(input);

    [...]
}
{code}

Setting the Rules implementation as above result the parsing method returning a null object
whereas the code below works properly :
	
{code:title=AbstractAnnotatedPojoTestCase.java|borderStyle=solid}
public final void verifyExpectedEqualsToParsed(Object expected) throws Exception {
    [...]

    Digester digester = newLoader(modules).newDigester(new RegexRules(new RegexMatcher()));
    Object actual = digester.parse(input);

    [...]
}
{code}

Thus, in the same way the getAuxModules() method can be overrided, I created the method below
that can be overrided and I modified the verifyExpectedEqualsToParsed method in consequence
in case developper wants to run his tests with another Rules implementation.

{code:title=AbstractAnnotatedPojoTestCase.java|borderStyle=solid}
public final void verifyExpectedEqualsToParsed(Object expected) throws Exception {
    [...]

    Digester digester = newLoader(modules).newDigester(this.getRules());
    Object actual = digester.parse(input);

    [...]
}

[...]

protected Rules getRules() {
    return new RulesBase();
}
{code}


Please let me know if I have to open another issue for these potential bugs.

Thanks in advance
                  
> Adding SetLeaf Rule
> -------------------
>
>                 Key: DIGESTER-177
>                 URL: https://issues.apache.org/jira/browse/DIGESTER-177
>             Project: Commons Digester
>          Issue Type: Improvement
>    Affects Versions: 3.2
>         Environment: Microsoft Windows 7 x32
>            Reporter: BRABANT Benjamin
>            Priority: Minor
>         Attachments: SetLeafFeatureAnnotationTestCase.patch, SetLeafFeature.patch
>
>
> Hello,
> I would like to suggest a new minor functionality that is missing to my mind in the digester
project. Indeed, it is possible by default to :
> * call a method on the (top) object passing the (top-1) object as an argument [SetTop
method]
> * call a method on the (top-1) object passing the (top) object as an argument [SetNext
method]
> * call a method on the (root) object passing the (top) object as an argument [SetRoot
method]
> To follow this sequence, I think it could be interesting that digester offers by default
the possibility of calling a method on the (top) object passing the (root) object as an argument
[the new SetLeaf method] !
> From this perspective, I attached you my patch that provides this functionality and a
TestCase to check it. I am also writing TestCases for annotation, binder and xmlrules for
which I will attach patches as soon as possible.
> Thanks in advance for your consideration.
> BRABANT Benjamin

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message