![]() |
Hubiquitus Android
0.3
Android client for hubiquitus protocol
|
00001 /* 00002 * Copyright (c) Novedia Group 2012. 00003 * 00004 * This file is part of Hubiquitus. 00005 * 00006 * Hubiquitus is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * Hubiquitus is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with Hubiquitus. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 package org.hubiquitus.hapi.test; 00021 00022 import java.util.Calendar; 00023 import org.hubiquitus.hapi.client.HClient; 00024 import org.hubiquitus.hapi.hStructures.HAck; 00025 import org.hubiquitus.hapi.hStructures.HAckValue; 00026 import org.hubiquitus.hapi.hStructures.HAlert; 00027 import org.hubiquitus.hapi.hStructures.HConvState; 00028 import org.hubiquitus.hapi.hStructures.HLocation; 00029 import org.hubiquitus.hapi.hStructures.HMeasure; 00030 import org.hubiquitus.hapi.hStructures.HMessage; 00031 import org.hubiquitus.hapi.hStructures.HMessageOptions; 00032 import org.hubiquitus.hapi.hStructures.HMessagePriority; 00033 import org.hubiquitus.hapi.util.DateISO8601; 00034 import org.hubiquitus.hapi.util.HJsonDictionnary; 00035 import org.junit.Assert; 00036 import org.junit.Test; 00037 import exceptions.MissingAttrException; 00038 00043 public class HBuilderTest { 00044 00045 @Test 00046 public void HMessageBuildTest() { 00047 HClient hclient = new HClient(); 00048 00049 HMessageOptions hmessageOption = new HMessageOptions(); 00050 00051 hmessageOption.setAuthor("me"); 00052 hmessageOption.setConvid("convid:123456789"); 00053 00054 HJsonDictionnary headers = new HJsonDictionnary(); 00055 headers.put("header1", "1"); 00056 headers.put("header2", "2"); 00057 hmessageOption.setHeaders(headers); 00058 00059 HLocation location = new HLocation(); 00060 hmessageOption.setLocation(location); 00061 00062 hmessageOption.setPriority(HMessagePriority.INFO); 00063 00064 String dateIso = DateISO8601.now(); 00065 Calendar date = DateISO8601.toCalendar(dateIso); 00066 hmessageOption.setRelevance(date); 00067 00068 hmessageOption.setTransient(false); 00069 00070 HJsonDictionnary payload = new HJsonDictionnary(); 00071 payload.put("test", "test"); 00072 HMessage hmessage = null; 00073 try { 00074 hmessage = hclient.buildMessage("chid:123456789", "string", payload, hmessageOption); 00075 } catch (MissingAttrException e) { 00076 Assert.fail(); 00077 } 00078 00079 Assert.assertEquals(hmessage.getAuthor(), "me"); 00080 Assert.assertEquals(hmessage.getChid(), "chid:123456789"); 00081 Assert.assertEquals(hmessage.getConvid(), "convid:123456789"); 00082 Assert.assertEquals(hmessage.getMsgid(), null); 00083 Assert.assertEquals(hmessage.getType(), "string"); 00084 Assert.assertEquals(hmessage.getHeaders().toString(), headers.toString()); 00085 Assert.assertEquals(hmessage.getLocation().toString(), location.toString()); 00086 Assert.assertEquals(hmessage.getPayload().toString(), payload.toString()); 00087 Assert.assertEquals(hmessage.getPriority(), HMessagePriority.INFO); 00088 Assert.assertEquals(hmessage.getPublished(), null); 00089 Assert.assertEquals(hmessage.getRelevance(), date); 00090 Assert.assertEquals(hmessage.getTransient(), false); 00091 } 00092 00093 00094 @Test 00095 public void HConvStateBuildTest() { 00096 HClient hclient = new HClient(); 00097 00098 HMessageOptions hmessageOption = new HMessageOptions(); 00099 00100 hmessageOption.setAuthor("me"); 00101 00102 HJsonDictionnary headers = new HJsonDictionnary(); 00103 headers.put("header1", "1"); 00104 headers.put("header2", "2"); 00105 hmessageOption.setHeaders(headers); 00106 00107 HLocation location = new HLocation(); 00108 hmessageOption.setLocation(location); 00109 00110 hmessageOption.setPriority(HMessagePriority.INFO); 00111 00112 String dateIso = DateISO8601.now(); 00113 Calendar date = DateISO8601.toCalendar(dateIso); 00114 hmessageOption.setRelevance(date); 00115 00116 hmessageOption.setTransient(false); 00117 00118 HMessage hmessage = null; 00119 try { 00120 hmessage = hclient.buildConvState("test channel", "test conv id" , "test status", hmessageOption); 00121 } catch (MissingAttrException e) { 00122 Assert.fail(); 00123 } 00124 00125 HConvState hconvstate = new HConvState(); 00126 hconvstate.setStatus("test status"); 00127 00128 Assert.assertEquals(hmessage.getType(),"hconvstate"); 00129 Assert.assertEquals(hmessage.getPayload().toString(),hconvstate.toString()); 00130 } 00131 00132 @Test 00133 public void HAckBuildTest() { 00134 HClient hclient = new HClient(); 00135 00136 HMessageOptions hmessageOption = new HMessageOptions(); 00137 00138 hmessageOption.setAuthor("me"); 00139 hmessageOption.setConvid("convid:123456789"); 00140 00141 HJsonDictionnary headers = new HJsonDictionnary(); 00142 headers.put("header1", "1"); 00143 headers.put("header2", "2"); 00144 hmessageOption.setHeaders(headers); 00145 00146 HLocation location = new HLocation(); 00147 hmessageOption.setLocation(location); 00148 00149 hmessageOption.setPriority(HMessagePriority.INFO); 00150 00151 String dateIso = DateISO8601.now(); 00152 Calendar date = DateISO8601.toCalendar(dateIso); 00153 hmessageOption.setRelevance(date); 00154 00155 hmessageOption.setTransient(false); 00156 00157 HAckValue ackvalue = HAckValue.READ; 00158 String hackid = "ackid:123456789"; 00159 00160 HMessage hmessage = null; 00161 try { 00162 hmessage = hclient.buildAck("chid:123456789", hackid , ackvalue, hmessageOption); 00163 } catch (MissingAttrException e) { 00164 Assert.fail(); 00165 } 00166 00167 HAck hack = new HAck(); 00168 hack.setAck(ackvalue); 00169 hack.setAckid(hackid); 00170 00171 Assert.assertEquals(hmessage.getType(),"hack"); 00172 Assert.assertEquals(hmessage.getPayload().toString(),hack.toString()); 00173 } 00174 00175 @Test 00176 public void HAlertBuildTest() { 00177 HClient hclient = new HClient(); 00178 00179 HMessageOptions hmessageOption = new HMessageOptions(); 00180 00181 hmessageOption.setAuthor("me"); 00182 hmessageOption.setConvid("convid:123456789"); 00183 00184 HJsonDictionnary headers = new HJsonDictionnary(); 00185 headers.put("header1", "1"); 00186 headers.put("header2", "2"); 00187 hmessageOption.setHeaders(headers); 00188 00189 HLocation location = new HLocation(); 00190 hmessageOption.setLocation(location); 00191 00192 hmessageOption.setPriority(HMessagePriority.INFO); 00193 00194 String dateIso = DateISO8601.now(); 00195 Calendar date = DateISO8601.toCalendar(dateIso); 00196 hmessageOption.setRelevance(date); 00197 00198 hmessageOption.setTransient(false); 00199 00200 String alert = "WARNING WARNING"; 00201 00202 HMessage hmessage = null; 00203 try { 00204 hmessage = hclient.buildAlert("chid:123456789",alert, hmessageOption); 00205 } catch (MissingAttrException e) { 00206 Assert.fail(); 00207 } 00208 00209 HAlert halert = new HAlert(); 00210 halert.setAlert(alert); 00211 00212 Assert.assertEquals(hmessage.getType(),"halert"); 00213 Assert.assertEquals(hmessage.getPayload().toString(),halert.toString()); 00214 } 00215 00216 @Test 00217 public void HBuildMeasureTest() { 00218 HClient hclient = new HClient(); 00219 00220 HMessageOptions hmessageOption = new HMessageOptions(); 00221 00222 hmessageOption.setAuthor("me"); 00223 hmessageOption.setConvid("convid:123456789"); 00224 00225 HJsonDictionnary headers = new HJsonDictionnary(); 00226 headers.put("header1", "1"); 00227 headers.put("header2", "2"); 00228 hmessageOption.setHeaders(headers); 00229 00230 HLocation location = new HLocation(); 00231 hmessageOption.setLocation(location); 00232 00233 hmessageOption.setPriority(HMessagePriority.INFO); 00234 00235 String dateIso = DateISO8601.now(); 00236 Calendar date = DateISO8601.toCalendar(dateIso); 00237 hmessageOption.setRelevance(date); 00238 00239 hmessageOption.setTransient(false); 00240 00241 String unit = "metre"; 00242 String value = "100"; 00243 00244 HMessage hmessage = null; 00245 try { 00246 hmessage = hclient.buildMeasure("chid:123456789",value,unit, hmessageOption); 00247 } catch (MissingAttrException e) { 00248 Assert.fail(); 00249 } 00250 00251 HMeasure hmeasure = new HMeasure(); 00252 hmeasure.setUnit(unit); 00253 hmeasure.setValue(value); 00254 00255 Assert.assertEquals(hmessage.getType(),"hmeasure"); 00256 Assert.assertEquals(hmessage.getPayload().toString(),hmeasure.toString()); 00257 } 00258 } 00259