Bulk delete schemasets in CM handle deregistration
[cps.git] / cps-service / src / test / groovy / org / onap / cps / utils / GsonSpec.groovy
1 package org.onap.cps.utils
2
3 import com.google.gson.stream.JsonReader
4 import org.onap.cps.TestUtils
5 import spock.lang.Specification
6
7
8 class GsonSpec extends Specification{
9
10     def 'Iterate over JSON data with gson JsonReader'(){
11         given: 'json data with two objects and JSON reader'
12             def jsonData = TestUtils.getResourceFileContent('multiple-object-data.json')
13             def objectUnderTest = new JsonReader(new StringReader(jsonData));
14         when: 'data is iterated over with JsonReader methods'
15             iterateWithJsonReader(objectUnderTest)
16         then: 'no exception is thrown'
17             noExceptionThrown()
18     }
19
20     def iterateWithJsonReader(JsonReader jsonReader){
21         switch(jsonReader.peek()) {
22             case "STRING":
23                 print(jsonReader.nextString() + " ")
24                 break;
25             case "BEGIN_OBJECT":
26                 jsonReader.beginObject();
27                 while (jsonReader.hasNext()) {
28                     print(jsonReader.nextName() + " ")
29                     iterateWithJsonReader(jsonReader)
30                 }
31                 jsonReader.endObject();
32                 println("")
33                 break;
34             default:
35                 break;
36         }
37     }
38
39
40 }