jvanzyl 02/03/22 12:41:30
Added: src/test/org/apache/stratum/xo/mismatch Mismatch.java
TestMismatchMapper.java mismatch.xml
Log:
Test case that makes sure the mapper doesn't crap out when there are
elements that don't map to properties in the specified bean. Gracefully
continue with attempting to map the rest of the XML file.
Revision Changes Path
1.1
jakarta-turbine-stratum/src/test/org/apache/stratum/xo/mismatch/Mismatch.java
Index: Mismatch.java
===================================================================
package org.apache.stratum.xo.mismatch;
import java.util.List;
import java.util.ArrayList;
public class Mismatch
{
private String firstName;
private String lastName;
private ArrayList hobbies = new ArrayList();
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getFirstName()
{
return firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getLastName()
{
return lastName;
}
// Need to reduce this.
public void addHobby(String hobby)
{
hobbies.add(hobby);
}
public String getHobby(int index)
{
return (String) hobbies.get(index);
}
public List getHobbies()
{
return hobbies;
}
}
1.1
jakarta-turbine-stratum/src/test/org/apache/stratum/xo/mismatch/TestMismatchMapper.java
Index: TestMismatchMapper.java
===================================================================
package org.apache.stratum.xo.mismatch;
import java.io.File;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.stratum.xo.Mapper;
public class TestMismatchMapper
extends TestCase
{
private static String TEST_DOCUMENT =
"src/test/org/apache/stratum/xo/mismatch/mismatch.xml";
private static String TEST_CLASS =
"org.apache.stratum.xo.mismatch.Mismatch";
public TestMismatchMapper(String testName)
{
super(testName);
}
public static Test suite()
{
return new TestSuite(TestMismatchMapper.class);
}
public void setUp()
{
}
public void tearDown()
{
}
public void testPersonMapping()
{
try
{
Mapper m = new Mapper();
m.setDebug(true);
Mismatch mismatch = (Mismatch) m.map(new File(TEST_DOCUMENT),
TEST_CLASS);
assertEquals("Jason",mismatch.getFirstName());
assertEquals("van Zyl",mismatch.getLastName());
assertEquals("somnambulism",mismatch.getHobby(0));
assertEquals("squash",mismatch.getHobby(1));
}
catch (Exception e)
{
e.printStackTrace();
fail(e.getMessage());
}
}
}
1.1
jakarta-turbine-stratum/src/test/org/apache/stratum/xo/mismatch/mismatch.xml
Index: mismatch.xml
===================================================================
<person>
<firstName>Jason</firstName>
<lastName>van Zyl</lastName>
<hobbies>
<hobby>somnambulism</hobby>
<hobby>squash</hobby>
</hobbies>
<noMatchingProperty>boo hoo</noMatchingProperty>
<foos>
<foo>bar1</foo>
<foo>bar2</foo>
</foos>
<releases>
<release>
<version>3.0-b1</version>
<tag>FULCRUM_3_0_B1</tag>
</release>
</releases>
</person>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>