added tests and changed the java package names
[hudson-sidebar-announcer-plugin:hudson-sidebar-announcer-plugin.git] / sidebar-announcer / src / test / java / hudson / plugins / TestAnnounceWidget.java
1 package     hudson.plugins;
2 import com.gargoylesoftware.htmlunit.html.HtmlButton;
3 import com.gargoylesoftware.htmlunit.html.HtmlElement;
4 import com.gargoylesoftware.htmlunit.html.HtmlForm;
5 import com.gargoylesoftware.htmlunit.html.HtmlPage;
6 import org.junit.Test;
7 import java.io.File;
8 import java.io.IOException;
9
10 import org.jvnet.hudson.test.HudsonTestCase;
11 import org.xml.sax.SAXException;
12
13
14 /**
15  * Created by IntelliJ IDEA.
16  * User: JuhaH
17  * Date: 3.11.2010
18  * Time: 20:53:32
19  *
20  */
21 public class TestAnnounceWidget extends HudsonTestCase{
22
23     @Test
24     public void testAnnounceWidget()
25     {
26         String teststring = "lorem ipsum";
27         String testfile = "src/test/resources/testfile.txt";
28         File f = new File(testfile);
29
30         HtmlPage configPage;
31         try {
32
33             WebClient c = new WebClient();
34             
35             configPage = c.goTo("/configure");
36
37             HtmlForm form = configPage.getFormByName("config");
38             form.getInputByName("fileLoc").type(f.getAbsolutePath());
39
40             form.submit((HtmlButton)last(form.getHtmlElementsByTagName("button")));
41             configPage = c.goTo("/");
42             HtmlElement element = configPage.getHtmlElementById("announcerdiv");
43             assertTrue(element.getTextContent().contains(teststring)); 
44
45         } catch (IOException e) {
46             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
47             assertEquals(1,2);
48         } catch (SAXException e) {
49             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
50              assertEquals(1,2);
51         }
52
53     }
54 }