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

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

started to use constants instead of strings

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 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(Constants.TYPE_FIELD, "new_document");
42 arguments.put(Constants.COLLECTION_ID_FIELD, "testing");
43 arguments.put(Constants.DOCUMENT_CONTENT_FIELD, "albatros");
44
45 String template = as.createSubscription(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(Constants.COLLECTION_ID_FIELD, "testing");
107 arguments.put(Constants.TYPE_FIELD, "new_document");
108 arguments.put(Constants.DOCUMENT_ID_FIELD, "20041124:1");
109 arguments.put(Constants.DOCUMENT_TITLE_FIELD, "keine albatrosse in sicht");
110 arguments.put(Constants.HOST_ID_FIELD, "http://localhost:8080/soap/servlet/rpcrouter");
111
112 as.receiveEvent(arguments);
113
114 } catch (ResourceNotFoundException e) {
115 e.printStackTrace();
116 fail("no template");
117 } catch (ParseErrorException e) {
118 e.printStackTrace();
119 fail();
120 } catch (MethodInvocationException e) {
121 e.printStackTrace();
122 fail();
123 } catch (Exception e) {
124 e.printStackTrace();
125 fail();
126 }
127 }
128
129 public final void testShowFeed() {
130 try {
131 Velocity.init("/research/schweer/gsdl3/packages/gsdl-as/build/velocity.properties");
132 VelocityContext context = new VelocityContext();
133
134 Map arguments = new TreeMap();
135 arguments.put("subscriptionID", "0");
136
137 String template = as.showFeed(arguments, context);
138
139 StringWriter w = new StringWriter();
140 boolean b = Velocity.mergeTemplate(template,
141 org.apache.velocity.runtime.RuntimeSingleton.getString(Velocity.INPUT_ENCODING, Velocity.ENCODING_DEFAULT),
142 context,
143 w);
144 assertTrue(b);
145 System.out.println(w);
146 } catch (ResourceNotFoundException e) {
147 e.printStackTrace();
148 fail("no template");
149 } catch (ParseErrorException e) {
150 e.printStackTrace();
151 fail();
152 } catch (MethodInvocationException e) {
153 e.printStackTrace();
154 fail();
155 } catch (Exception e) {
156 e.printStackTrace();
157 fail();
158 }
159 }
160 protected void setUp() throws Exception {
161 as = new AlertingService();
162 }
163}
Note: See TracBrowser for help on using the repository browser.