1 package org.objectweb.celtix.js.rhino; 2 3 import java.io.File ; 4 5 import javax.xml.ws.Service; 6 7 import junit.framework.TestCase; 8 9 import org.easymock.classextension.EasyMock; 10 11 import org.mozilla.javascript.EvaluatorException; 12 import org.mozilla.javascript.Scriptable; 13 14 15 public class ProviderFactoryTest extends TestCase { 16 17 private String epAddr = "http://celtix.objectweb.org/"; 18 19 private ProviderFactory ph; 20 private AbstractDOMProvider dpMock; 21 22 protected void setUp() throws Exception { 23 super.setUp(); 24 dpMock = EasyMock.createMock(AbstractDOMProvider.class); 25 ph = new ProviderFactory(epAddr) { 26 protected AbstractDOMProvider createProvider(Service.Mode mode, 27 Scriptable scope, 28 Scriptable wspVar, 29 String epAddress, 30 boolean isBase, 31 boolean e4x) 32 throws Exception { 33 return dpMock; 34 } 35 }; 36 } 37 38 public void testMsgJSFile() throws Exception { 39 dpMock.publish(); 40 dpMock.publish(); 41 EasyMock.replay(dpMock); 42 File f = new File (getClass().getResource("msg.js").getFile()); 43 ph.createAndPublish(f); 44 EasyMock.verify(dpMock); 45 } 46 47 public void testBadJSFile() throws Exception { 48 EasyMock.replay(dpMock); 49 final String fname = "broken.js"; 50 File f = new File (getClass().getResource(fname).getFile()); 51 try { 52 ph.createAndPublish(f); 53 fail("expected exception did not occur"); 54 } catch (EvaluatorException ex) { 55 assertTrue("wrong exception", ex.getMessage().startsWith("syntax error")); 56 } 57 EasyMock.verify(dpMock); 58 } 59 60 public void testEmptyJSFile() throws Exception { 61 EasyMock.replay(dpMock); 62 final String fname = "empty.js"; 63 File f = new File (getClass().getResource(fname).getFile()); 64 try { 65 ph.createAndPublish(f); 66 fail("expected exception did not occur"); 67 } catch (Exception ex) { 68 assertEquals("wrong exception message", 69 f.getPath() + ProviderFactory.NO_PROVIDER, 70 ex.getMessage()); 71 } 72 EasyMock.verify(dpMock); 73 } 74 75 public void testNoSuchJSFile() throws Exception { 76 EasyMock.replay(dpMock); 77 final String fname = "none.js"; 78 File f = new File (fname); 79 try { 80 ph.createAndPublish(f); 81 fail("expected exception did not occur"); 82 } catch (Exception ex) { 83 assertEquals("wrong exception message", 84 f.getPath() + ProviderFactory.NO_SUCH_FILE, 85 ex.getMessage()); 86 } 87 EasyMock.verify(dpMock); 88 } 89 90 public void testIllegalServiceMode() throws Exception { 91 EasyMock.replay(dpMock); 92 final String fname = "illegal1.js"; 93 File f = new File (getClass().getResource(fname).getFile()); 94 try { 95 ph.createAndPublish(f); 96 fail("expected exception did not occur"); 97 } catch (Exception ex) { 98 assertEquals("wrong exception message", 99 f.getPath() + ProviderFactory.ILLEGAL_SVCMD_MODE + "bogus", 100 ex.getMessage()); 101 } 102 EasyMock.verify(dpMock); 103 } 104 105 public void testIllegalServiceModeType() throws Exception { 106 EasyMock.replay(dpMock); 107 final String fname = "illegal2.js"; 108 File f = new File (getClass().getResource(fname).getFile()); 109 try { 110 ph.createAndPublish(f); 111 fail("expected exception did not occur"); 112 } catch (Exception ex) { 113 assertEquals("wrong exception message", 114 f.getPath() + ProviderFactory.ILLEGAL_SVCMD_TYPE, 115 ex.getMessage()); 116 } 117 EasyMock.verify(dpMock); 118 } 119 120 public void testProviderException() throws Exception { 121 dpMock.publish(); 122 EasyMock.expectLastCall() 123 .andThrow(new AbstractDOMProvider.JSDOMProviderException(AbstractDOMProvider.NO_EP_ADDR)); 124 EasyMock.replay(dpMock); 125 File f = new File (getClass().getResource("msg.js").getFile()); 126 try { 127 ph.createAndPublish(f); 128 fail("expected exception did not occur"); 129 } catch (Exception ex) { 130 assertEquals("wrong exception message", 131 f.getPath() + ": " + AbstractDOMProvider.NO_EP_ADDR, 132 ex.getMessage()); 133 } 134 EasyMock.verify(dpMock); 135 } 136 } 137 | Popular Tags |