001: package org.objectweb.celtix.js.rhino;
002:
003: import java.io.File;
004:
005: import javax.xml.ws.Service;
006:
007: import junit.framework.TestCase;
008:
009: import org.easymock.classextension.EasyMock;
010:
011: import org.mozilla.javascript.EvaluatorException;
012: import org.mozilla.javascript.Scriptable;
013:
014: public class ProviderFactoryTest extends TestCase {
015:
016: private String epAddr = "http://celtix.objectweb.org/";
017:
018: private ProviderFactory ph;
019: private AbstractDOMProvider dpMock;
020:
021: protected void setUp() throws Exception {
022: super .setUp();
023: dpMock = EasyMock.createMock(AbstractDOMProvider.class);
024: ph = new ProviderFactory(epAddr) {
025: protected AbstractDOMProvider createProvider(
026: Service.Mode mode, Scriptable scope,
027: Scriptable wspVar, String epAddress,
028: boolean isBase, boolean e4x) throws Exception {
029: return dpMock;
030: }
031: };
032: }
033:
034: public void testMsgJSFile() throws Exception {
035: dpMock.publish();
036: dpMock.publish();
037: EasyMock.replay(dpMock);
038: File f = new File(getClass().getResource("msg.js").getFile());
039: ph.createAndPublish(f);
040: EasyMock.verify(dpMock);
041: }
042:
043: public void testBadJSFile() throws Exception {
044: EasyMock.replay(dpMock);
045: final String fname = "broken.js";
046: File f = new File(getClass().getResource(fname).getFile());
047: try {
048: ph.createAndPublish(f);
049: fail("expected exception did not occur");
050: } catch (EvaluatorException ex) {
051: assertTrue("wrong exception", ex.getMessage().startsWith(
052: "syntax error"));
053: }
054: EasyMock.verify(dpMock);
055: }
056:
057: public void testEmptyJSFile() throws Exception {
058: EasyMock.replay(dpMock);
059: final String fname = "empty.js";
060: File f = new File(getClass().getResource(fname).getFile());
061: try {
062: ph.createAndPublish(f);
063: fail("expected exception did not occur");
064: } catch (Exception ex) {
065: assertEquals("wrong exception message", f.getPath()
066: + ProviderFactory.NO_PROVIDER, ex.getMessage());
067: }
068: EasyMock.verify(dpMock);
069: }
070:
071: public void testNoSuchJSFile() throws Exception {
072: EasyMock.replay(dpMock);
073: final String fname = "none.js";
074: File f = new File(fname);
075: try {
076: ph.createAndPublish(f);
077: fail("expected exception did not occur");
078: } catch (Exception ex) {
079: assertEquals("wrong exception message", f.getPath()
080: + ProviderFactory.NO_SUCH_FILE, ex.getMessage());
081: }
082: EasyMock.verify(dpMock);
083: }
084:
085: public void testIllegalServiceMode() throws Exception {
086: EasyMock.replay(dpMock);
087: final String fname = "illegal1.js";
088: File f = new File(getClass().getResource(fname).getFile());
089: try {
090: ph.createAndPublish(f);
091: fail("expected exception did not occur");
092: } catch (Exception ex) {
093: assertEquals("wrong exception message", f.getPath()
094: + ProviderFactory.ILLEGAL_SVCMD_MODE + "bogus", ex
095: .getMessage());
096: }
097: EasyMock.verify(dpMock);
098: }
099:
100: public void testIllegalServiceModeType() throws Exception {
101: EasyMock.replay(dpMock);
102: final String fname = "illegal2.js";
103: File f = new File(getClass().getResource(fname).getFile());
104: try {
105: ph.createAndPublish(f);
106: fail("expected exception did not occur");
107: } catch (Exception ex) {
108: assertEquals("wrong exception message", f.getPath()
109: + ProviderFactory.ILLEGAL_SVCMD_TYPE, ex
110: .getMessage());
111: }
112: EasyMock.verify(dpMock);
113: }
114:
115: public void testProviderException() throws Exception {
116: dpMock.publish();
117: EasyMock.expectLastCall().andThrow(
118: new AbstractDOMProvider.JSDOMProviderException(
119: AbstractDOMProvider.NO_EP_ADDR));
120: EasyMock.replay(dpMock);
121: File f = new File(getClass().getResource("msg.js").getFile());
122: try {
123: ph.createAndPublish(f);
124: fail("expected exception did not occur");
125: } catch (Exception ex) {
126: assertEquals("wrong exception message", f.getPath() + ": "
127: + AbstractDOMProvider.NO_EP_ADDR, ex.getMessage());
128: }
129: EasyMock.verify(dpMock);
130: }
131: }
|