View Javadoc
1 package net.sourceforge.selfesteem.test; 2 3 import junit.framework.TestCase; 4 import net.sourceforge.selfesteem.*; 5 6 import java.io.IOException; 7 import java.io.StringReader; 8 9 import org.jdom.Document; 10 import org.jdom.JDOMException; 11 import org.jdom.input.SAXBuilder; 12 import org.xml.sax.InputSource; 13 14 public class ParseStoriesTest extends TestCase { 15 private StoryParser _parser = new StoryParser(); 16 17 public ParseStoriesTest(String s) { 18 super(s); 19 } 20 21 public void testParsingStories() throws IOException { 22 RootNode node = parse("Iteration 1\n" + 23 "- Record In Place \n" + 24 " \n" + 25 "# this is a crock\n" + 26 "-Create Bob\n" + 27 "Iteration 2\n" + 28 "-Read Cool Stuff"); 29 30 checkNode(node.get(0), IterationNode.class, "Iteration 1"); 31 checkNode(node.get(0).get(0), StoryNode.class, "Record In Place"); 32 checkNode(node.get(0).get(1), StoryNode.class, "Create Bob"); 33 checkNode(node.get(1), IterationNode.class, "Iteration 2"); 34 checkNode(node.get(1).get(0), StoryNode.class, "Read Cool Stuff"); 35 } 36 37 private RootNode parse(String text) throws IOException { 38 _parser.parseStoryFile(new StringReader(text)); 39 return _parser.getRoot(); 40 } 41 42 public void testNoDuplicates() throws IOException { 43 try { 44 parse("abc\n" + 45 "-123\n" + 46 "-123"); 47 fail(); 48 49 } catch (SelfEsteemException e) { 50 assertEquals("there can only be one story named (123)", e.getMessage()); 51 } 52 } 53 54 public void testAddingTests() throws IOException { 55 RootNode node = parse("Iteration 1\n" + 56 "-Record In Place\n" + 57 "Iteration 2\n" + 58 "-Read Cool Stuff"); 59 60 _parser.addTest("Record In Place/lovely", true, 0.0); 61 _parser.addTest("Read Cool Stuff/crap", true, 0.0); 62 63 checkNode(node.get(0).get(0).get(0), TestNode.class, "lovely"); 64 checkNode(node.get(1).get(0).get(0), TestNode.class, "crap"); 65 } 66 67 public void testAddingTestsFromFile() throws IOException, JDOMException { 68 RootNode node = parse("Iteration 1\n" + 69 "-Record In Place"); 70 71 String testResults = 72 "<testsuite>" + 73 " <testcase name='Record In Place/test a' time='11.141'/>" + 74 " <testcase name='Record In Place/test b' time='11.141'>" + 75 " <error message='error message' type='java.lang.Exception'>stack trace</error>" + 76 " </testcase>" + 77 " <testcase name='Record In Place/test c' time='11.141'>" + 78 " <error message='error message' type='java.lang.Exception'>stack trace</error>" + 79 " </testcase>" + 80 "</testsuite>"; 81 82 _parser.parseTestResults(getDocument(testResults)); 83 84 StoryNode story = (StoryNode) node.get(0).get(0); 85 assertEquals("test a", story.get(0).getName()); 86 assertEquals("test b", story.get(1).getName()); 87 assertEquals("test c", story.get(2).getName()); 88 } 89 90 static Document getDocument(String xml) throws JDOMException { 91 return new SAXBuilder().build(new InputSource(new StringReader(xml))); 92 } 93 94 public void testAddingAnUnknownTest() { 95 try { 96 _parser.addTest("Record In Place/lovely", true, 0.0); 97 fail(); 98 } catch (SelfEsteemException e) { 99 assertEquals("Unknown story (Record In Place) please define it", e.getMessage()); 100 } 101 } 102 103 public void testAddingATestWithoutAStory() { 104 try { 105 _parser.addTest("lovely", true, 0.0); 106 fail(); 107 } catch (SelfEsteemException e) { 108 assertEquals("You must specify story for test (lovely) in the form of (<story>/lovely)", e.getMessage()); 109 } 110 } 111 112 private void checkNode(Node node, Class clazz, String name) { 113 assertEquals(clazz, node.getClass()); 114 assertEquals(name, node.getName()); 115 } 116 117 }

This page was automatically generated by Maven