|
| 1 | +note 'Specification for HelliumServer public API' |
| 2 | + |
| 3 | +def DATA_UNIQUE_KEY = "sm3243dgb357y" |
| 4 | +def DATA_UNIQUE_KEY_2 = "AAsmsdg23327y" |
| 5 | + |
| 6 | +type 'Data' message { |
| 7 | + string_data 'string' |
| 8 | + numeric_data 'int32' optional |
| 9 | + boolean_truth 'bool' |
| 10 | +} |
| 11 | + |
| 12 | +type 'ReturnedData' message { |
| 13 | + data 'Data' optional |
| 14 | +} |
| 15 | + |
| 16 | +service { |
| 17 | + |
| 18 | + name 'HelliumServer' |
| 19 | + |
| 20 | + version '0.1' |
| 21 | + location 'http://helium-1222.appspot.com/' |
| 22 | + //location 'http://localhost:8080' |
| 23 | + |
| 24 | + // API DECLARATION START |
| 25 | + ////////////////////////////////////// |
| 26 | + get 'data/@id' spec { |
| 27 | + name 'Get stored data.' |
| 28 | + description 'Retrieve stored data information by unique ID' |
| 29 | + response 'ReturnedData' |
| 30 | + } |
| 31 | + |
| 32 | + post 'data/@id' spec { |
| 33 | + name 'Post data object.' |
| 34 | + description 'Sends data object to server. Saves this data by specified unique ID. Returns same object that was send' |
| 35 | + body 'Data' |
| 36 | + response 'Data' |
| 37 | + } |
| 38 | + |
| 39 | + put 'data/@id' spec { |
| 40 | + name 'Store data object.' |
| 41 | + description 'Saves data object by specified ID' |
| 42 | + body 'Data' |
| 43 | + } |
| 44 | + |
| 45 | + delete 'data/@id' spec { |
| 46 | + name 'Delete stored data.' |
| 47 | + description 'Deletes earlier stored data object from server by specified ID' |
| 48 | + } |
| 49 | + ////////////////////////////////////// |
| 50 | + // API DECLARATION END |
| 51 | + |
| 52 | + // TESTS FOR API |
| 53 | + // Each behaviour begins with 'describe' |
| 54 | + ///////////////////////////////////// |
| 55 | + describe "Could retrieve/delete stored data." spec { |
| 56 | + |
| 57 | + beforeEach { |
| 58 | + def response = service.put 'data/@id' with { |
| 59 | + path { id DATA_UNIQUE_KEY } |
| 60 | + body { |
| 61 | + string_data 'some important info about object' |
| 62 | + numeric_data 15 |
| 63 | + boolean_truth false |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + response.mustSucceed() |
| 68 | + } |
| 69 | + |
| 70 | + it("Retrieve data with \'get\'.") { |
| 71 | + def response = service.get 'data/@id' with { |
| 72 | + path { id DATA_UNIQUE_KEY } |
| 73 | + } |
| 74 | + |
| 75 | + response.mustSucceed() |
| 76 | + assert response.body.data.string_data == 'some important info about object' |
| 77 | + assert response.body.data.numeric_data == 15 |
| 78 | + assert response.body.data.boolean_truth == false |
| 79 | + } |
| 80 | + |
| 81 | + it("Delete data with \'delete\'.") { |
| 82 | + def response = service.delete 'data/@id' with { |
| 83 | + path { id DATA_UNIQUE_KEY } |
| 84 | + } |
| 85 | + |
| 86 | + response.mustSucceed() |
| 87 | + } |
| 88 | + |
| 89 | + // Cleanup. |
| 90 | + afterEach { |
| 91 | + def response = service.delete 'data/@id' with { |
| 92 | + path { id DATA_UNIQUE_KEY } |
| 93 | + } |
| 94 | + |
| 95 | + response.mustSucceed() |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + describe "Can't retrieve deleted information." spec { |
| 100 | + |
| 101 | + beforeEach { |
| 102 | + def response = service.put 'data/@id' with { |
| 103 | + path { id DATA_UNIQUE_KEY_2 } |
| 104 | + body { |
| 105 | + string_data 'Another super important data.' |
| 106 | + numeric_data 15 |
| 107 | + boolean_truth false |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + response.mustSucceed() |
| 112 | + } |
| 113 | + |
| 114 | + describe 'delete/retrieve actions' spec { |
| 115 | + |
| 116 | + beforeEach { |
| 117 | + def response = service.delete 'data/@id' with { |
| 118 | + path { id DATA_UNIQUE_KEY_2 } |
| 119 | + } |
| 120 | + |
| 121 | + response.mustSucceed() |
| 122 | + } |
| 123 | + |
| 124 | + it("Try to retrieve data with \'get\'.") { |
| 125 | + def response = service.get 'data/@id' with { |
| 126 | + path { id DATA_UNIQUE_KEY_2 } |
| 127 | + } |
| 128 | + |
| 129 | + response.mustSucceed() |
| 130 | + assert response.body.data == null |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + // Cleanup. |
| 135 | + afterEach { |
| 136 | + def response = service.delete 'data/@id' with { |
| 137 | + path { id DATA_UNIQUE_KEY_2 } |
| 138 | + } |
| 139 | + |
| 140 | + response.mustSucceed() |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + describe "Post command could override earlier saved data." spec { |
| 145 | + beforeEach { |
| 146 | + def response = service.post 'data/@id' with { |
| 147 | + path { id DATA_UNIQUE_KEY } |
| 148 | + body { |
| 149 | + string_data 'Answer to life universe and everything.' |
| 150 | + numeric_data 42 |
| 151 | + boolean_truth false |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + response.mustSucceed() |
| 156 | + assert response.body.string_data == 'Answer to life universe and everything.' |
| 157 | + assert response.body.numeric_data == 42 |
| 158 | + assert response.body.boolean_truth == false |
| 159 | + } |
| 160 | + |
| 161 | + describe "Another \'post\' with same ID should override stored data." spec { |
| 162 | + beforeEach { |
| 163 | + def response = service.post 'data/@id' with { |
| 164 | + path { id DATA_UNIQUE_KEY } |
| 165 | + body { |
| 166 | + string_data 'Another answer to life.' |
| 167 | + numeric_data 45 |
| 168 | + boolean_truth true |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + response.mustSucceed() |
| 173 | + assert response.body.string_data == 'Another answer to life.' |
| 174 | + assert response.body.numeric_data == 45 |
| 175 | + assert response.body.boolean_truth == true |
| 176 | + } |
| 177 | + |
| 178 | + it('Retrieve last saved data with \'get\' command.') { |
| 179 | + def response = service.get 'data/@id' with { |
| 180 | + path { id DATA_UNIQUE_KEY } |
| 181 | + } |
| 182 | + |
| 183 | + response.mustSucceed() |
| 184 | + assert response.body.data.string_data == 'Another answer to life.' |
| 185 | + assert response.body.data.numeric_data == 45 |
| 186 | + assert response.body.data.boolean_truth == true |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + // Cleanup. |
| 191 | + afterEach { |
| 192 | + def response = service.delete 'data/@id' with { |
| 193 | + path { id DATA_UNIQUE_KEY } |
| 194 | + } |
| 195 | + |
| 196 | + response.mustSucceed() |
| 197 | + } |
| 198 | + } |
| 199 | +} |
0 commit comments