@@ -37,26 +37,26 @@ public void testCheckSignTrue() {
3737 String key = "tgGsR8FTuLXzzVBsp3rngeSgOB2E2pMFJDwAXarbrs92GmLiiy" ;
3838 String time = "1389956320" ;
3939 String content = "{\n "
40- + " \" ops\" :[\n "
41- + " {\n "
42- + " \" ref\" :null,\n "
43- + " \" type\" :\" data\" ,\n "
44- + " \" obj_id\" :\" 52d8d74610e87b10d98c8d90\" ,\n "
45- + " \" conv_id\" :\" 270\" ,\n "
46- + " \" node_id\" :\" 52d837d210e87b10d979e98c\" ,\n "
47- + " \" data\" :{\n "
48- + " \" id\" :1077413\n "
49- + " },\n "
50- + " \" extra\" :{\n "
51- + " \" id\" :\" 1412737\" ,\n "
52- + " \" hide_products\" :\" N\" ,\n "
53- + " \" properties\" :\" Y\" ,\n "
54- + " \" show_all\" :\" Y\" ,\n "
55- + " \" codeProduct\" : \" CRED\" \n "
56- + " }\n "
57- + " }\n "
58- + " ]\n "
59- + "}" ;
40+ + " \" ops\" :[\n "
41+ + " {\n "
42+ + " \" ref\" :null,\n "
43+ + " \" type\" :\" data\" ,\n "
44+ + " \" obj_id\" :\" 52d8d74610e87b10d98c8d90\" ,\n "
45+ + " \" conv_id\" :\" 270\" ,\n "
46+ + " \" node_id\" :\" 52d837d210e87b10d979e98c\" ,\n "
47+ + " \" data\" :{\n "
48+ + " \" id\" :1077413\n "
49+ + " },\n "
50+ + " \" extra\" :{\n "
51+ + " \" id\" :\" 1412737\" ,\n "
52+ + " \" hide_products\" :\" N\" ,\n "
53+ + " \" properties\" :\" Y\" ,\n "
54+ + " \" show_all\" :\" Y\" ,\n "
55+ + " \" codeProduct\" : \" CRED\" \n "
56+ + " }\n "
57+ + " }\n "
58+ + " ]\n "
59+ + "}" ;
6060 boolean expResult = true ;
6161 boolean result = CorezoidMessage .checkSign (sign , key , time , content );
6262 assertEquals (expResult , result );
@@ -72,26 +72,26 @@ public void testCheckSignFalse() {
7272 String key = "tgGsR8FTuLXzzVBsp3rngeSgOB2E2pMFJDwAXarbrs92GmLiiy" ;
7373 String time = "1389956320" ;
7474 String content = "{\n "
75- + " \" ops\" :[\n "
76- + " {\n "
77- + " \" ref\" :null,\n "
78- + " \" type\" :\" data\" ,\n "
79- + " \" obj_id\" :\" 52d8d74610e87b10d98c8d90\" ,\n "
80- + " \" conv_id\" :\" 270\" ,\n "
81- + " \" node_id\" :\" 52d837d210e87b10d979e98c\" ,\n "
82- + " \" data\" :{\n "
83- + " \" id\" :1077413\n "
84- + " },\n "
85- + " \" extra\" :{\n "
86- + " \" id\" :\" 1412737\" ,\n "
87- + " \" hide_products\" :\" N\" ,\n "
88- + " \" properties\" :\" Y\" ,\n "
89- + " \" show_all\" :\" Y\" ,\n "
90- + " \" codeProduct\" : \" CRED\" \n "
91- + " }\n "
92- + " }\n "
93- + " ]\n "
94- + "}" ;
75+ + " \" ops\" :[\n "
76+ + " {\n "
77+ + " \" ref\" :null,\n "
78+ + " \" type\" :\" data\" ,\n "
79+ + " \" obj_id\" :\" 52d8d74610e87b10d98c8d90\" ,\n "
80+ + " \" conv_id\" :\" 270\" ,\n "
81+ + " \" node_id\" :\" 52d837d210e87b10d979e98c\" ,\n "
82+ + " \" data\" :{\n "
83+ + " \" id\" :1077413\n "
84+ + " },\n "
85+ + " \" extra\" :{\n "
86+ + " \" id\" :\" 1412737\" ,\n "
87+ + " \" hide_products\" :\" N\" ,\n "
88+ + " \" properties\" :\" Y\" ,\n "
89+ + " \" show_all\" :\" Y\" ,\n "
90+ + " \" codeProduct\" : \" CRED\" \n "
91+ + " }\n "
92+ + " }\n "
93+ + " ]\n "
94+ + "}" ;
9595 boolean expResult = false ;
9696 boolean result = CorezoidMessage .checkSign (sign , key , time , content );
9797 assertEquals (expResult , result );
@@ -106,11 +106,11 @@ public void testCheckSignFalse() {
106106 */
107107 public void testCheckAnswerReturnsNotEmptyMap () throws Exception {
108108 String answerOk = "{\n "
109- + " \" request_proc\" :\" ok\" ,\n "
110- + " \" ops\" :[\n "
111- + " {\" id\" :\" \" ,\" proc\" :\" ok\" ,\" obj\" :\" task\" ,\" ref\" :\" PB11345969838\" ,\" obj_id\" :\" 52e266a05f845f6ec484d611\" }\n "
112- + " ]\n "
113- + "}" ;
109+ + " \" request_proc\" :\" ok\" ,\n "
110+ + " \" ops\" :[\n "
111+ + " {\" id\" :\" \" ,\" proc\" :\" ok\" ,\" obj\" :\" task\" ,\" ref\" :\" PB11345969838\" ,\" obj_id\" :\" 52e266a05f845f6ec484d611\" }\n "
112+ + " ]\n "
113+ + "}" ;
114114 Map <String , String > map = CorezoidMessage .parseAnswer (answerOk );
115115 assertEquals (true , !map .isEmpty ());
116116 System .out .println (">>testCheckAnswerReturnsNotEmptyMap :\t " + map .toString ());
@@ -124,11 +124,11 @@ public void testCheckAnswerReturnsNotEmptyMap() throws Exception {
124124 */
125125 public void testcheckAnswerShouldThrowException () throws Exception {
126126 String answerFail = "{\n "
127- + " \" request_proc\" :\" fail\" ,\n "
128- + " \" ops\" :[\n "
129- + " {\" id\" :\" \" ,\" proc\" :\" ok\" ,\" obj\" :\" task\" ,\" ref\" :\" PB11345969838\" ,\" obj_id\" :\" 52e266a05f845f6ec484d611\" }\n "
130- + " ]\n "
131- + "}" ;
127+ + " \" request_proc\" :\" fail\" ,\n "
128+ + " \" ops\" :[\n "
129+ + " {\" id\" :\" \" ,\" proc\" :\" ok\" ,\" obj\" :\" task\" ,\" ref\" :\" PB11345969838\" ,\" obj_id\" :\" 52e266a05f845f6ec484d611\" }\n "
130+ + " ]\n "
131+ + "}" ;
132132 try {
133133 Map <String , String > map = CorezoidMessage .parseAnswer (answerFail );
134134 fail ("Exception was expected" );
@@ -233,7 +233,7 @@ public void testGetConAnswerMessage() {
233233 /**
234234 * Requst builder tests
235235 */
236- public void testGetConvQueryMessage () {
236+ public void testGetConvQueryCreateMessage () {
237237 JSONObject data = new JSONObject ()
238238 .element ("phone" , "1" )
239239 .element ("card" , "2" );
@@ -242,16 +242,54 @@ public void testGetConvQueryMessage() {
242242 String key = "123" ;
243243 String apiLogin = "12345" ;
244244 CorezoidMessage mes = CorezoidMessage .request (key , apiLogin , Arrays .asList (RequestOperation .create (conv_id , ref , data )));
245- System .out .println (">>testGetConvQueryMessage :" );
245+ System .out .println (">>testGetConvQueryCreateMessage :" );
246246 System .out .println ("body \t \t " + mes .body );
247247 System .out .println ("url \t \t " + mes .url );
248248 String expBody = "{\" ops\" :[{\" ref\" :\" 11\" ,\" conv_id\" :\" 1234\" ,\" type\" :\" create\" ,\" obj\" :\" task\" ,\" data\" :{\" phone\" :\" 1\" ,\" card\" :\" 2\" }}]}" ;
249249 assertEquals (expBody , mes .body );
250250
251251 }
252- /**
253- * MessageBuilder Exceptions test
254- */
252+ /**
253+ * Requst builder tests
254+ */
255+ public void testGetConvQueryModifyRefMessage () {
256+ JSONObject data = new JSONObject ()
257+ .element ("phone" , "1" )
258+ .element ("card" , "2" );
259+ String ref = "11" ;
260+ String conv_id = "1234" ;
261+ String key = "123" ;
262+ String apiLogin = "12345" ;
263+ CorezoidMessage mes = CorezoidMessage .request (key , apiLogin , Arrays .asList (RequestOperation .modifyRef (conv_id , ref , data )));
264+ System .out .println (">>testGetConvQueryModifyRefMessage :" );
265+ System .out .println ("body \t \t " + mes .body );
266+ System .out .println ("url \t \t " + mes .url );
267+ String expBody = "{\" ops\" :[{\" ref\" :\" 11\" ,\" conv_id\" :\" 1234\" ,\" type\" :\" modify\" ,\" obj\" :\" task\" ,\" data\" :{\" phone\" :\" 1\" ,\" card\" :\" 2\" }}]}" ;
268+ assertEquals (expBody , mes .body );
269+
270+ }
271+ /**
272+ * Requst builder tests
273+ */
274+ public void testGetConvQueryModifyIdMessage () {
275+ JSONObject data = new JSONObject ()
276+ .element ("phone" , "1" )
277+ .element ("card" , "2" );
278+ String taskId = "11" ;
279+ String conv_id = "1234" ;
280+ String key = "123" ;
281+ String apiLogin = "12345" ;
282+ CorezoidMessage mes = CorezoidMessage .request (key , apiLogin , Arrays .asList (RequestOperation .modifyId (conv_id , taskId , data )));
283+ System .out .println (">>testGetConvQueryModifyRefMessage :" );
284+ System .out .println ("body \t \t " + mes .body );
285+ System .out .println ("url \t \t " + mes .url );
286+ String expBody = "{\" ops\" :[{\" obj_id\" :\" 11\" ,\" conv_id\" :\" 1234\" ,\" type\" :\" modify\" ,\" obj\" :\" task\" ,\" data\" :{\" phone\" :\" 1\" ,\" card\" :\" 2\" }}]}" ;
287+ assertEquals (expBody , mes .body );
288+
289+ }
290+ /**
291+ * MessageBuilder Exceptions test
292+ */
255293 public void testConveyorQueryShouldThrowException () {
256294 JSONObject data = new JSONObject ()
257295 .element ("phone" , "1" )
@@ -292,4 +330,35 @@ public void testConveyorQueryShouldThrowException() {
292330 System .out .println (">>testConveyorQueryBuilderShouldThrowException :\t " + ex .getMessage ());
293331 }
294332 }
333+ public void testRequestOperationShouldThrowException (){
334+ JSONObject data = new JSONObject ()
335+ .element ("phone" , "1" )
336+ .element ("card" , "2" );
337+ String ref = "11" ;
338+ String taskId = "12" ;
339+ String conv_id = "1234" ;
340+ String apiSecret = "1234" ;
341+ String apiLogin = "12345" ;
342+ RequestOperation op = null ;
343+ try {
344+ op = RequestOperation .modifyId (conv_id , null , data );
345+ }catch (Exception ex ){
346+ System .out .println (">>testRequestOperationShouldThrowException :\t " + ex .getMessage ());
347+ }
348+ try {
349+ op = RequestOperation .modifyId (conv_id , "" , data );
350+ }catch (Exception ex ){
351+ System .out .println (">>testRequestOperationShouldThrowException :\t " + ex .getMessage ());
352+ }
353+ try {
354+ op = RequestOperation .modifyRef (conv_id , null , data );
355+ }catch (Exception ex ){
356+ System .out .println (">>testRequestOperationShouldThrowException :\t " + ex .getMessage ());
357+ }
358+ try {
359+ op = RequestOperation .modifyRef (conv_id , "" , data );
360+ }catch (Exception ex ){
361+ System .out .println (">>testRequestOperationShouldThrowException :\t " + ex .getMessage ());
362+ }
363+ }
295364}
0 commit comments