new test
authorjloinig
Wed, 13 Jul 2005 11:25:24 +0200
changeset 26372e60f6376569
parent 2636 6264b2e48281
child 2638 580e8d1b7533
new test
src/java-tests/isac/functest/minibrowser/ProxyMock.java
src/java-tests/isac/functest/minibrowser/TestMiniBrowser.java
src/java-tests/isac/functest/minibrowser/test2.html
     1.1 --- a/src/java-tests/isac/functest/minibrowser/ProxyMock.java	Wed Jul 13 11:25:08 2005 +0200
     1.2 +++ b/src/java-tests/isac/functest/minibrowser/ProxyMock.java	Wed Jul 13 11:25:24 2005 +0200
     1.3 @@ -1,28 +1,43 @@
     1.4  /*
     1.5   * Created on 12.07.2005
     1.6   *
     1.7 - * TODO To change the template for this generated file go to
     1.8 - * Window - Preferences - Java - Code Style - Code Templates
     1.9   */
    1.10  package isac.functest.minibrowser;
    1.11  
    1.12 +import java.io.IOException;
    1.13 +
    1.14 +import isac.gui.minibrowser.MiniBrowserImpl;
    1.15 +
    1.16  import javax.swing.event.HyperlinkEvent;
    1.17  import javax.swing.event.HyperlinkListener;
    1.18  
    1.19  /**
    1.20 - * @author johannes
    1.21 + * @author JL
    1.22   *
    1.23 - * TODO To change the template for this generated type comment go to
    1.24 - * Window - Preferences - Java - Code Style - Code Templates
    1.25 + * A mock class to test the MiniBrowser.
    1.26 + * Catches a HyperlinkEvent and sets a internal variable to true. 
    1.27 + * 
    1.28   */
    1.29  public class ProxyMock implements HyperlinkListener {
    1.30  
    1.31 -	/* (non-Javadoc)
    1.32 -	 * @see javax.swing.event.HyperlinkListener#hyperlinkUpdate(javax.swing.event.HyperlinkEvent)
    1.33 +	public boolean hyperlink_event_fired_ = false;
    1.34 +	
    1.35 +	/**
    1.36 +	 * Sets hyperlink_event_fired to true if a hyperlinkEvent is fired
    1.37 +	 * and updates the page in the MiniBrowser
    1.38 +	 * 
    1.39 +	 * @param hyperlink_event
    1.40 +	 * @throws IOException
    1.41  	 */
    1.42 -	public void hyperlinkUpdate(HyperlinkEvent arg0) {
    1.43 -		// TODO Auto-generated method stub
    1.44 -
    1.45 +	public void hyperlinkUpdate(HyperlinkEvent hyperlink_event){
    1.46 +		hyperlink_event_fired_ = true;
    1.47 +		MiniBrowserImpl mini_browser =  (MiniBrowserImpl) hyperlink_event.getSource();
    1.48 +		try {
    1.49 +			mini_browser.setPage(hyperlink_event.getURL());
    1.50 +		} catch (IOException e) {
    1.51 +			mini_browser.setText("ERROR FILE NOT FOUND: " +
    1.52 +					mini_browser.getPage().getFile());
    1.53 +		}
    1.54  	}
    1.55  
    1.56  }
     2.1 --- a/src/java-tests/isac/functest/minibrowser/TestMiniBrowser.java	Wed Jul 13 11:25:08 2005 +0200
     2.2 +++ b/src/java-tests/isac/functest/minibrowser/TestMiniBrowser.java	Wed Jul 13 11:25:24 2005 +0200
     2.3 @@ -5,11 +5,11 @@
     2.4   */
     2.5  package isac.functest.minibrowser;
     2.6  
     2.7 -import java.io.BufferedReader;
     2.8 -import java.io.FileReader;
     2.9  import java.io.IOException;
    2.10 +import java.net.URL;
    2.11  
    2.12  import javax.swing.JFrame;
    2.13 +import javax.swing.event.HyperlinkEvent;
    2.14  
    2.15  import isac.gui.minibrowser.MiniBrowserImpl;
    2.16  import junit.framework.TestCase;
    2.17 @@ -17,32 +17,28 @@
    2.18  /**
    2.19   * MiniBrowser
    2.20   * 
    2.21 - * This testcases should test the MiniBrowser independend from the implementation.
    2.22 - * So only functional use cases are tested.
    2.23 + * This testcases should test the MiniBrowser independend from the
    2.24 + * implementation. So only functional use cases are tested.
    2.25   * 
    2.26   * @author JL
    2.27   * @version $Revision$
    2.28   * @see isac.gui.minibrowser.IMiniBrowser
    2.29   * @see isac.gui.minibrowser.MiniBrowserImpl
    2.30 - * 
    2.31 + *  
    2.32   */
    2.33  public class TestMiniBrowser extends TestCase {
    2.34  
    2.35  	/*
    2.36  	 * testNewMiniBrowserWithLocalPage
    2.37  	 * 
    2.38 -	 * Tests the generation of a MiniBrowser and the representation of
    2.39 -	 * a local (isac internal) page (problem, excample, ...)
    2.40 +	 * Tests the generation of a MiniBrowser and the representation of a local
    2.41 +	 * (isac internal) page (problem, excample, ...)
    2.42  	 * 
    2.43  	 * @author JL
    2.44 -	 * @todo implement
    2.45 -	 * 
    2.46 -	 * TOOODO JL: implement testNewMiniBrowserWithLocalPage
    2.47  	 */
    2.48  	public void testNewMiniBrowserWithLocalPage() throws IOException {
    2.49  		System.out
    2.50  				.println("---BEGIN isac.functest.minibrowser.testNewMiniBrowserWithLocalPage");
    2.51 -
    2.52  		ProxyMock proxy_mock = new ProxyMock();
    2.53  		MiniBrowserImpl mini_browser = new MiniBrowserImpl(proxy_mock);
    2.54  		// FIXME JL: do not do setPage later on this test
    2.55 @@ -54,57 +50,62 @@
    2.56  		mini_browser_frame.setSize(600, 600);
    2.57  		mini_browser_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    2.58  		mini_browser_frame.setVisible(true);
    2.59 -
    2.60  		mini_browser_frame.getContentPane().add(mini_browser);
    2.61  
    2.62 -		BufferedReader in = new BufferedReader(new FileReader(
    2.63 -				"bin/java/isac/functest/minibrowser/test.html"));
    2.64 -		in.close();
    2.65 -
    2.66  		String result = mini_browser.getText();
    2.67  		String result_first_line = result.substring(0, result.indexOf("\n"));
    2.68  		String expected_first_line = "<html math=\"http://www.w3.org/1998/Math/MathML\" xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"#DEFAULT\">";
    2.69 +		assertEquals(expected_first_line, result_first_line);
    2.70  
    2.71 -		assertEquals(expected_first_line, result_first_line);
    2.72 +		assertEquals("bin/java/isac/functest/minibrowser/test.html",
    2.73 +				mini_browser.getPage().getFile());
    2.74 +		
    2.75 +		mini_browser_frame.setVisible(false);
    2.76 +
    2.77  		System.out
    2.78  				.println("---END isac.functest.minibrowser.testNewMiniBrowserWithLocalPage");
    2.79  	}
    2.80  
    2.81  	/*
    2.82 -	 * testLocalLink
    2.83 +	 * testKlickOnLink
    2.84  	 * 
    2.85 -	 * Tests the representation of a local (isac internal) page if klicked
    2.86 -	 * on a link in the minibrowser
    2.87 +	 * Tests if the right event is fired
    2.88  	 * 
    2.89 -	 * @author JL
    2.90 -	 * @todo implement
    2.91 -	 * 
    2.92 -	 * TOOODO JL: implement testLocalLink
    2.93  	 */
    2.94 -	public void testLocalLink() {
    2.95 -		System.out.println("---BEGIN isac.functest.minibrowser.testLocalLink");
    2.96 -		System.out.println("TODO");
    2.97 -		assertEquals("TODO", "TODO");
    2.98 -		System.out.println("---END isac.functest.minibrowser.testLocalLink");
    2.99 -	}
   2.100 +	public void testKlickOnLink() throws IOException {
   2.101 +		System.out
   2.102 +				.println("---BEGIN isac.functest.minibrowser.testKlickOnLink");
   2.103  
   2.104 -	/*
   2.105 -	 * testExternalLink
   2.106 -	 * 
   2.107 -	 * Tests if a external browser (standard web browser) is opened
   2.108 -	 * if a external link is klicked in the MiniBrowser
   2.109 -	 * 
   2.110 -	 * @author JL
   2.111 -	 * @todo implement
   2.112 -	 * 
   2.113 -	 * TOOODO JL: testExternalLink
   2.114 -	 */
   2.115 -	public void testExternalLink() {
   2.116 -		System.out
   2.117 -				.println("---BEGIN isac.functest.minibrowser.testExternalLink");
   2.118 -		System.out.println("TODO");
   2.119 -		assertEquals("TODO", "TODO");
   2.120 -		System.out.println("---END isac.functest.minibrowser.testExternalLink");
   2.121 +		ProxyMock proxy_mock = new ProxyMock();
   2.122 +		MiniBrowserImpl mini_browser = new MiniBrowserImpl(proxy_mock);
   2.123 +		mini_browser
   2.124 +				.setPage("file:bin/java/isac/functest/minibrowser/test.html");
   2.125 +
   2.126 +		URL url = new URL("file:bin/java/isac/functest/minibrowser/test2.html");
   2.127 +		HyperlinkEvent hyperlink_event = new HyperlinkEvent(mini_browser,
   2.128 +				HyperlinkEvent.EventType.ACTIVATED, url);
   2.129 +		mini_browser.fireHyperlinkUpdate(hyperlink_event);
   2.130 +		
   2.131 +		JFrame mini_browser_frame = new JFrame("MiniBrowser Test2");
   2.132 +		mini_browser_frame.setSize(600, 600);
   2.133 +		mini_browser_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   2.134 +		mini_browser_frame.setVisible(true);
   2.135 +		mini_browser_frame.getContentPane().add(mini_browser);
   2.136 +		
   2.137 +		// FIXME JL: wait for thread
   2.138 +		for(int i = 0; i < 10000;)
   2.139 +			i++;
   2.140 +
   2.141 +		
   2.142 +		assertEquals("No Event fired.",
   2.143 +				proxy_mock.hyperlink_event_fired_, true);
   2.144 +
   2.145 +		String expected_string = "<html>\n  <head>\n    \n  </head>\n  <body>\n    Test Page 2\n  </body>\n</html>\n";
   2.146 +		assertEquals(expected_string, mini_browser.getText());
   2.147 +
   2.148 +		mini_browser_frame.setVisible(false);
   2.149 +
   2.150 +		System.out.println("---END isac.functest.minibrowser.testKlickOnLink");
   2.151  	}
   2.152  
   2.153  }
   2.154 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/java-tests/isac/functest/minibrowser/test2.html	Wed Jul 13 11:25:24 2005 +0200
     3.3 @@ -0,0 +1,1 @@
     3.4 +Test Page 2