package com.versionone.hudson;


import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.Descriptor;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.tasks.BatchFile;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;
import org.apache.commons.io.FileUtils;
import org.jvnet.hudson.test.HudsonTestCase;
import org.xml.sax.SAXException;
import org.junit.Ignore;

import java.io.IOException;



public class AppTest extends HudsonTestCase {


	public void test1() throws Exception {
		FreeStyleProject project = createFreeStyleProject();
		//project.getBuildersList().add(new BatchFile("echo hello"));
//		List<Action> actions = project.getActions();
		DescribableList<Publisher, Descriptor<Publisher>> publishers = project.getPublishersList();
		VersionOneNotifier versionOneNotifier = new VersionOneNotifier();
        versionOneNotifier.getDescriptor().setData("http://fake_address/VersionOne/", "admin", "admin", "[A-Z]{1,2}-[0-9]+", "Number");
//		VersionOneNotifier.DESCRIPTOR.configure()
		publishers.add(versionOneNotifier);

		FreeStyleBuild build = project.scheduleBuild2(0).get();
		System.out.println(build.getDisplayName() + " completed");

		// TODO: change this to use HtmlUnit
		String s = FileUtils.readFileToString(build.getLogFile());
		assertTrue(s.contains("VersionOne:"));
	}



    /*
	public void test2() throws IOException, SAXException {
		final HtmlPage page = new WebClient().goTo("configure");
		assertElementPresentByName(page, "com-versionone-hudson-VersionOneNotifier");
		int j = 3;
		int i = ((2009 - 2004) + j) > 1 ? 0 : 1;
	}
	*/

	/**
	 * Verifies that the specified page contains an element with the specified ID.
	 *
	 * @param page the page to check
	 * @param name the expected Name of an element in the page
	 */

	public static void assertElementPresentByName(final HtmlPage page, final String name) {
		try {
			page.getHtmlElementsByName(name);
		} catch (final ElementNotFoundException e) {
			throw new AssertionError("The page does not contain an element with name '" + name + "'.");
		}
	}

}

@@ -27,18 +27,16 @@
 son;%0D%0A%0D%0A
-%0D%0A
 import c
@@ -257,40 +257,8 @@
 t;%0D%0A
-import hudson.tasks.BatchFile;%0D%0A
 impo
@@ -446,34 +446,8 @@
 on;%0D
-%0Aimport org.junit.Ignore;%0D
 %0A%0D%0Ai
@@ -476,20 +476,16 @@
 ion;%0D%0A%0D%0A
-%0D%0A%0D%0A
 public c
@@ -525,19 +525,20 @@
 se %7B%0D%0A%0D%0A
-%0D%0A%09
+    
 public v
@@ -569,18 +569,24 @@
 tion %7B%0D%0A
-%09%09
+        
 FreeStyl
@@ -635,125 +635,16 @@
 );%0D%0A
-%09%09//project.getBuildersList().add(new BatchFile(%22echo hello%22));%0D%0A//%09%09List%3CAction%3E actions = project.getActions();%0D%0A%09%09
+        
 Desc
@@ -732,18 +732,24 @@
 ist();%0D%0A
-%09%09
+        
 VersionO
@@ -948,57 +948,16 @@
 );%0D%0A
-//%09%09VersionOneNotifier.DESCRIPTOR.configure()%0D%0A%09%09
+        
 publ
@@ -991,18 +991,24 @@
 er);%0D%0A%0D%0A
-%09%09
+        
 FreeStyl
@@ -1056,18 +1056,24 @@
 get();%0D%0A
-%09%09
+        
 System.o
@@ -1130,50 +1130,16 @@
 %0D%0A%0D%0A
-%09%09// TODO: change this to use HtmlUnit%0D%0A%09%09
+        
 Stri
@@ -1190,26 +1190,32 @@
 ogFile());%0D%0A
-%09%09
+        
 assertTrue(s
@@ -1246,27 +1246,21 @@
 );%0D%0A
-%09
+    
 %7D%0D%0A%0D%0A
-%0D%0A%0D%0A    /*%0D%0A%09
+    
 publ
@@ -1311,18 +1311,24 @@
 tion %7B%0D%0A
-%09%09
+        
 final Ht
@@ -1377,18 +1377,24 @@
 ure%22);%0D%0A
-%09%09
+        
 assertEl
@@ -1468,84 +1468,30 @@
 );%0D%0A
-%09%09int j = 3;%0D%0A%09%09int i = ((2009 - 2004) + j) %3E 1 ? 0 : 1;%0D%0A%09%7D%0D%0A%09*/%0D%0A%0D%0A%09
+    %7D%0D%0A%0D%0A    
 /**%0D%0A
-%09
+    
  * V
@@ -1570,14 +1570,20 @@
 D.%0D%0A
-%09 *%0D%0A%09
+     *%0D%0A    
  * @
@@ -1612,17 +1612,20 @@
  check%0D%0A
-%09
+    
  * @para
@@ -1680,17 +1680,21 @@
 ge%0D%0A
-%09
+    
  */%0D%0A
-%0D%0A%09
+    
 publ
@@ -1782,20 +1782,35 @@
  %7B%0D%0A
-%09%09try %7B%0D%0A%09%09%09
+        try %7B%0D%0A            
 page
@@ -1840,18 +1840,24 @@
 name);%0D%0A
-%09%09
+        
 %7D catch 
@@ -1898,11 +1898,20 @@
  %7B%0D%0A
-%09%09%09
+            
 thro
@@ -2003,18 +2003,23 @@
 );%0D%0A
-%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A
+        %7D%0D%0A    %7D%0D%0A%7D

test added