source: trunk/greenstone3-extensions/gsdl-as/test-src/org/greenstone/gsdlas/AlertingServiceTest.java@ 8720

Last change on this file since 8720 was 8720, checked in by schweer, 19 years ago

worked on web interface

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/*
2 * Created on Nov 24, 2004
3 * Copyright (C) Andrea Schweer, 2004
4 *
5 * This file is part of the Greenstone Alerting Service.
6 * Refer to the COPYING file in the base directory of this package
7 * for licensing information.
8 */
9package org.greenstone.gsdlas;
10
11import java.io.StringWriter;
12import java.util.Map;
13import java.util.TreeMap;
14
15import org.apache.velocity.VelocityContext;
16import org.apache.velocity.app.Velocity;
17import org.apache.velocity.exception.*;
18
19import junit.framework.TestCase;
20
21/**
22 * @author schweer
23 *
24 * TODO To change the template for this generated type comment go to
25 * Window - Preferences - Java - Code Style - Code Templates
26 */
27public class AlertingServiceTest extends TestCase {
28
29 private AlertingService as;
30
31 public static void main(String[] args) {
32 junit.textui.TestRunner.run(AlertingServiceTest.class);
33 }
34
35 public final void testSubscribe() {
36 try {
37 Velocity.init("/research/schweer/gsdl3/packages/gsdl-as/build/velocity.properties");
38 VelocityContext context = new VelocityContext();
39
40 Map arguments = new TreeMap();
41 arguments.put("type", "new_document");
42 arguments.put("collectionID", "testing");
43 arguments.put("document_content", "albatros");
44
45 String template = as.subscribe(arguments, context);
46
47 StringWriter w = new StringWriter();
48 boolean b = Velocity.mergeTemplate(template,
49 org.apache.velocity.runtime.RuntimeSingleton.getString(Velocity.INPUT_ENCODING, Velocity.ENCODING_DEFAULT),
50 context,
51 w);
52 assertTrue(b);
53 System.out.println(w);
54 } catch (ResourceNotFoundException e) {
55 e.printStackTrace();
56 fail("no template");
57 } catch (ParseErrorException e) {
58 e.printStackTrace();
59 fail();
60 } catch (MethodInvocationException e) {
61 e.printStackTrace();
62 fail();
63 } catch (Exception e) {
64 e.printStackTrace();
65 fail();
66 }
67 }
68
69 public final void testListSubscriptions() {
70 try {
71 Velocity.init("/research/schweer/gsdl3/packages/gsdl-as/build/velocity.properties");
72 VelocityContext context = new VelocityContext();
73
74 Map arguments = new TreeMap();
75
76 String template = as.listSubscriptions(arguments, context);
77
78 StringWriter w = new StringWriter();
79 boolean b = Velocity.mergeTemplate(template,
80 org.apache.velocity.runtime.RuntimeSingleton.getString(Velocity.INPUT_ENCODING, Velocity.ENCODING_DEFAULT),
81 context,
82 w);
83 assertTrue(b);
84 System.out.println(w);
85 } catch (ResourceNotFoundException e) {
86 e.printStackTrace();
87 fail("no template");
88 } catch (ParseErrorException e) {
89 e.printStackTrace();
90 fail();
91 } catch (MethodInvocationException e) {
92 e.printStackTrace();
93 fail();
94 } catch (Exception e) {
95 e.printStackTrace();
96 fail();
97 }
98 }
99
100 public final void testReceiveEvent() {
101 try {
102 Velocity.init("/research/schweer/gsdl3/packages/gsdl-as/build/velocity.properties");
103 VelocityContext context = new VelocityContext();
104
105 Map arguments = new TreeMap();
106 arguments.put("collectionID", "testing");
107 arguments.put("type", "new_document");
108 arguments.put("documentID", "20041124:1");
109 arguments.put("document_title", "keine albatrosse in sicht");
110 arguments.put("host_url", "http://localhost:8080/soap/servlet/rpcrouter");
111
112 String template = as.receiveEvent(arguments, context);
113
114 StringWriter w = new StringWriter();
115 boolean b = Velocity.mergeTemplate(template,
116 org.apache.velocity.runtime.RuntimeSingleton.getString(Velocity.INPUT_ENCODING, Velocity.ENCODING_DEFAULT),
117 context,
118 w);
119 assertTrue(b);
120 System.out.println(w);
121 } catch (ResourceNotFoundException e) {
122 e.printStackTrace();
123 fail("no template");
124 } catch (ParseErrorException e) {
125 e.printStackTrace();
126 fail();
127 } catch (MethodInvocationException e) {
128 e.printStackTrace();
129 fail();
130 } catch (Exception e) {
131 e.printStackTrace();
132 fail();
133 }
134 }
135
136 public final void testShowFeed() {
137 try {
138 Velocity.init("/research/schweer/gsdl3/packages/gsdl-as/build/velocity.properties");
139 VelocityContext context = new VelocityContext();
140
141 Map arguments = new TreeMap();
142 arguments.put("subscriptionID", "0");
143
144 String template = as.showFeed(arguments, context);
145
146 StringWriter w = new StringWriter();
147 boolean b = Velocity.mergeTemplate(template,
148 org.apache.velocity.runtime.RuntimeSingleton.getString(Velocity.INPUT_ENCODING, Velocity.ENCODING_DEFAULT),
149 context,
150 w);
151 assertTrue(b);
152 System.out.println(w);
153 } catch (ResourceNotFoundException e) {
154 e.printStackTrace();
155 fail("no template");
156 } catch (ParseErrorException e) {
157 e.printStackTrace();
158 fail();
159 } catch (MethodInvocationException e) {
160 e.printStackTrace();
161 fail();
162 } catch (Exception e) {
163 e.printStackTrace();
164 fail();
165 }
166 }
167 protected void setUp() throws Exception {
168 as = new AlertingService();
169 }
170}
Note: See TracBrowser for help on using the repository browser.