1
1
package com .mtt .api .test .steps .task ;
2
2
3
+ import com .mtt .api .model .CreateTaskBean ;
4
+ import com .mtt .api .model .request .CreateTaskRequest ;
3
5
import com .mtt .api .test .client .task .client .TaskTester ;
4
6
import com .mtt .api .test .client .task .client .impl .HttpTaskApiClientTester ;
5
7
import com .mtt .api .test .client .task .response .TaskResponseValidator ;
21
23
22
24
public class TaskSteps {
23
25
26
+ //NOTE:: Alternatively can use restEasy :) ..see the APIClient for an example
24
27
private TaskTester taskHttpClient ;
25
28
private TaskResponseValidator taskResponse ;
26
29
27
30
private Wiser wiser ;
28
31
29
32
private Long taskId ;
33
+ private CreateTaskRequest createTaskRequest ;
30
34
31
35
@ Autowired
32
36
@ Qualifier ("taskFixture" )
@@ -45,6 +49,10 @@ public synchronized void loadFixture() {
45
49
wiser .start ();
46
50
47
51
taskHttpClient = new HttpTaskApiClientTester (apiHost , new DefaultHttpClient (new ThreadSafeClientConnManager ()));
52
+
53
+ taskId = null ;
54
+ createTaskRequest = null ;
55
+ taskResponse = null ;
48
56
}
49
57
50
58
@ After ("@task-fixture" )
@@ -56,8 +64,6 @@ public synchronized void cleanUpFixture() {
56
64
wiser .stop ();
57
65
wiser = null ;
58
66
}
59
-
60
- taskId = null ;
61
67
}
62
68
63
69
@ Given ("^the user enters a task id of (.*?)$" )
@@ -75,6 +81,52 @@ public void responseCodeIs(Integer responseCode) {
75
81
taskResponse .assertResponseStatusCode (responseCode );
76
82
}
77
83
84
+ @ Then ("^the (.*?) field should be \" (.*?)\" $" )
85
+ public void checkFieldValue (String field , String value ) {
86
+ taskResponse .assertField (field , value );
87
+ }
88
+
89
+ @ Given ("^the user wants to create a new task$" )
90
+ public void initialiseTask () {
91
+ createTaskRequest = new CreateTaskRequest ();
92
+ }
93
+
94
+ @ Given ("^the title field is set to \" (.*?)\" $" )
95
+ public void updateTitleTaskRequest (String value ) {
96
+ createTaskRequest .setTitle (value );
97
+ taskHttpClient .withTitle (value );
98
+ }
99
+
100
+ @ Given ("^the description field is set to \" (.*?)\" $" )
101
+ public void updateDescriptionTaskRequest (String value ) {
102
+ createTaskRequest .setDescription (value );
103
+ taskHttpClient .withDescription (value );
104
+ }
105
+
106
+ @ Given ("^the checked field is set to \" (.*?)\" $" )
107
+ public void updateCheckedTaskRequest (String checked ) {
108
+ boolean boolValue = Boolean .valueOf (checked );
109
+ createTaskRequest .setChecked (boolValue );
110
+ taskHttpClient .withCheckedValue (boolValue );
111
+ }
112
+
113
+ @ Given ("^the userId field is set to \" (.*?)\" $" )
114
+ public void updateUserIdTaskRequest (String value ) {
115
+ createTaskRequest .setUserId (Long .valueOf (value ));
116
+ taskHttpClient .withUserId (Long .valueOf (value ));
117
+ }
118
+
119
+ @ When ("^the user tries to create the task$" )
120
+ public void createTask () throws Exception {
121
+ taskResponse = taskHttpClient .createTask ();
122
+ }
123
+
124
+ @ Then ("^the response should contain an error \" (.*?)\" for the (.*?) field$" )
125
+ public void checkError (String errorCode , String field ) {
126
+ taskResponse .assertBodyContainsFieldError (field );
127
+ taskResponse .assertBodyContainsFieldError (field , errorCode );
128
+ }
129
+
78
130
}
79
131
80
132
0 commit comments