1 /* -----------------------------------------------------------------------
2 * Copyright 2016 King County Library System
3 * Bill Erickson <berickxx@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * -----------------------------------------------------------------------
16 package org.evergreen_ils.hatch;
18 import java.util.logging.Logger;
21 public class TestHatch {
23 static final Logger logger = Hatch.getLogger();
25 public static void pause() {
28 } catch (InterruptedException e) {}
31 public static void doSends() {
35 // initialize connection to set origin info
36 JSONObject obj = new JSONObject();
37 obj.put("msgid", msgid++);
38 obj.put("clientid", clientid);
39 obj.put("action", "init");
40 obj.put("origin", "https://test.hatch.evergreen-ils.org");
45 // get a list of stored keys
46 obj = new JSONObject();
47 obj.put("msgid", msgid++);
48 obj.put("clientid", clientid);
49 obj.put("action", "keys");
55 obj = new JSONObject();
56 obj.put("msgid", msgid++);
57 obj.put("clientid", clientid);
58 obj.put("action", "set");
59 obj.put("key", "eg.hatch.test.key1");
60 obj.put("content", "Rando content, now with cheese");
66 obj = new JSONObject();
67 obj.put("msgid", msgid++);
68 obj.put("clientid", clientid);
69 obj.put("action", "get");
70 obj.put("key", "eg.hatch.test.key1");
74 obj = new JSONObject();
75 obj.put("msgid", msgid++);
76 obj.put("clientid", clientid);
77 obj.put("action", "set");
78 obj.put("key", "eg.hatch.test.key2");
79 JSONArray arr = new JSONArray();
82 obj.put("content", arr);
87 obj = new JSONObject();
88 obj.put("msgid", msgid++);
89 obj.put("clientid", clientid);
90 obj.put("action", "get");
91 obj.put("key", "eg.hatch.test.key2");
96 obj = new JSONObject();
97 obj.put("msgid", msgid++);
98 obj.put("clientid", clientid);
99 obj.put("action", "keys");
104 // get a list of printers
105 obj = new JSONObject();
106 obj.put("msgid", msgid++);
107 obj.put("clientid", clientid);
108 obj.put("action", "printers");
116 obj = new JSONObject();
117 obj.put("msgid", msgid++);
118 obj.put("clientid", clientid);
119 obj.put("action", "print");
120 obj.put("contentType", "text/plain");
121 obj.put("content", "Hello, World!");
122 obj.put("showDialog", true); // avoid auto-print while testing
127 obj = new JSONObject();
128 obj.put("msgid", msgid++);
129 obj.put("clientid", clientid);
130 obj.put("action", "print");
131 obj.put("contentType", "text/html");
132 obj.put("content", "<html><body><b>HELLO WORLD</b><img src='" +
133 "http://evergreen-ils.org/wp-content/uploads/2013/09/copy-Evergreen_Logo_sm072.jpg"
134 + "'/></body></html>");
135 obj.put("showDialog", true); // avoid auto-print while testing
137 JSONObject settings = new JSONObject();
138 settings.put("copies", 2);
139 obj.put("settings", settings);
148 * Log all received message as a JSON string
150 public static void doReceive() {
152 JSONObject resp = io.recvMessage();
153 logger.info("TestJSON:doReceive(): " + resp.toString());
157 public static void main (String[] args) {
158 io = new MessageIO();
161 if (args.length > 0 && args[0].equals("receive")) {