add test for arg configure and fix issue in xml configuration for it

This commit is contained in:
Jesse McConnell 2012-08-10 12:24:58 -05:00
parent 4d74adc1e5
commit 107a14e138
3 changed files with 139 additions and 2 deletions

View File

@ -370,7 +370,7 @@ public class XmlConfiguration
throw new IllegalStateException("No suitable constructor on " + oClass, x);
}
}
configure(obj, _config, index);
return obj;
}
@ -437,6 +437,8 @@ public class XmlConfiguration
case "Property":
propertyObj(node);
break;
case "Arg": // Arg should have been processed for Configure already so ignore it here
break;
default:
throw new IllegalStateException("Unknown tag: " + tag + " in " + _url);
}
@ -757,7 +759,10 @@ public class XmlConfiguration
/*
* Create a new value object.
*
* @param obj @param node @return @exception Exception
* @param obj
* @param node
*
* @return @exception Exception
*/
private Object newObj(Object obj, XmlParser.Node node) throws Exception
{

View File

@ -0,0 +1,50 @@
package org.eclipse.jetty.xml;
import org.eclipse.jetty.util.annotation.Name;
public class AnnotatedTestConfiguration
{
private String first;
private String second;
private String third;
public AnnotatedTestConfiguration(@Name("first") String first, @Name("second") String second, @Name("third") String third)
{
this.first = first;
this.second = second;
this.third = third;
}
public String getFirst()
{
return first;
}
public void setFirst(String first)
{
this.first = first;
}
public String getSecond()
{
return second;
}
public void setSecond(String second)
{
this.second = second;
}
public String getThird()
{
return third;
}
public void setThird(String third)
{
this.third = third;
}
}

View File

@ -342,4 +342,86 @@ public class XmlConfigurationTest
xmlConfiguration.configure(tc);
Assert.assertEquals("tc.map is has two entries as specified in the XML", 2, tc.map.size());
}
@Test
public void testConstructorNamedInjection() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg>arg1</Arg> " +
" <Arg>arg2</Arg> " +
" <Arg>arg3</Arg> " +
"</Configure>");
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
Assert.assertEquals("first parameter not wired correctly","arg1", atc.getFirst());
Assert.assertEquals("second parameter not wired correctly","arg2", atc.getSecond());
Assert.assertEquals("third parameter not wired correctly","arg3", atc.getThird());
}
@Test
public void testConstructorNamedInjectionOrdered() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"second\">arg2</Arg> " +
" <Arg name=\"third\">arg3</Arg> " +
"</Configure>");
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
Assert.assertEquals("first parameter not wired correctly","arg1", atc.getFirst());
Assert.assertEquals("second parameter not wired correctly","arg2", atc.getSecond());
Assert.assertEquals("third parameter not wired correctly","arg3", atc.getThird());
}
public void testConstructorNamedInjectionUnOrdered() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"third\">arg3</Arg> " +
" <Arg name=\"second\">arg2</Arg> " +
"</Configure>");
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
Assert.assertEquals("first parameter not wired correctly","arg1", atc.getFirst());
Assert.assertEquals("second parameter not wired correctly","arg2", atc.getSecond());
Assert.assertEquals("third parameter not wired correctly","arg3", atc.getThird());
}
public void testConstructorNamedInjectionOrderedMixed() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " +
" <Arg>arg2</Arg> " +
" <Arg name=\"third\">arg3</Arg> " +
"</Configure>");
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
Assert.assertEquals("first parameter not wired correctly","arg1", atc.getFirst());
Assert.assertEquals("second parameter not wired correctly","arg2", atc.getSecond());
Assert.assertEquals("third parameter not wired correctly","arg3", atc.getThird());
}
public void testConstructorNamedInjectionUnorderedMixed() throws Exception
{
XmlConfiguration xmlConfiguration = new XmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"third\">arg3</Arg> " +
" <Arg>arg2</Arg> " +
" <Arg name=\"first\">arg1</Arg> " +
"</Configure>");
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
Assert.assertEquals("first parameter not wired correctly","arg1", atc.getFirst());
Assert.assertEquals("second parameter not wired correctly","arg2", atc.getSecond());
Assert.assertEquals("third parameter not wired correctly","arg3", atc.getThird());
}
}