1 26 27 package org.objectweb.jonas.examples.clients.earsample; 28 29 import junit.framework.TestSuite; 30 31 import org.objectweb.jonas.examples.util.JExampleTestCase; 32 33 import com.meterware.httpunit.AuthorizationRequiredException; 34 import com.meterware.httpunit.WebResponse; 35 36 41 public class F_EarSample extends JExampleTestCase { 42 43 46 private static final String URL_EARSAMPLE = "/earsample/secured/Op"; 47 48 52 public static void main(String [] args) { 53 54 String testtorun = null; 55 for (int argn = 0; argn < args.length; argn++) { 57 String sArg = args[argn]; 58 if (sArg.equals("-n")) { 59 testtorun = args[++argn]; 60 } 61 } 62 63 if (testtorun == null) { 64 junit.textui.TestRunner.run(suite()); 65 } else { 66 junit.textui.TestRunner.run(new F_EarSample(testtorun)); 67 } 68 } 69 70 74 public static TestSuite suite() { 75 return new TestSuite(F_EarSample.class); 76 } 77 78 83 protected void setUp() throws Exception { 84 super.setUp(); 85 useEar("earsample"); 86 } 87 88 92 public F_EarSample(String s) { 93 super(s, URL_EARSAMPLE); 94 } 95 96 100 public void testTryWithoutAuth() throws Exception { 101 try { 102 WebResponse wr = wc.getResponse(url); 103 fail("EarSample is not protected"); 104 } catch (AuthorizationRequiredException e) { 105 ; 106 } 107 } 108 109 113 public void testTryWithBadAuth() throws Exception { 114 try { 115 wc.setAuthorization("bad", "bad"); 116 WebResponse wr = wc.getResponse(url); 117 fail("EarSample is not protected"); 118 } catch (AuthorizationRequiredException e) { 119 ; 120 } 121 } 122 123 127 public void testTryWithJettyAuth() throws Exception { 128 try { 129 wc.setAuthorization("jetty", "jetty"); 130 WebResponse wr = wc.getResponse(url); 131 } catch (AuthorizationRequiredException e) { 132 fail("EarSample don't accept l/p jetty/jetty"); 133 } 134 } 135 136 140 public void testTryWithTomcatAuth() throws Exception { 141 try { 142 wc.setAuthorization("tomcat", "tomcat"); 143 WebResponse wr = wc.getResponse(url); 144 } catch (AuthorizationRequiredException e) { 145 fail("EarSample don't accept l/p tomcat/tomcat"); 146 } 147 } 148 149 153 public void testIsSampleOk() throws Exception { 154 try { 155 wc.setAuthorization("tomcat", "tomcat"); 156 WebResponse wr = wc.getResponse(url); 157 String txt = wr.getText(); 158 159 if (txt.indexOf("<strong>Sample is OK.</strong>") == -1) { 160 fail("The example was not ok : " + txt); 161 } 162 163 } catch (AuthorizationRequiredException e) { 164 fail("Authentication failed"); 165 } 166 } 167 168 169 } 170 | Popular Tags |