2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.vestest;
21 import java.io.BufferedReader;
22 import java.io.FileNotFoundException;
23 import java.io.FileReader;
24 import java.io.IOException;
25 import java.io.InputStreamReader;
27 import org.json.simple.JSONObject;
28 import org.json.simple.parser.JSONParser;
29 import org.junit.Test;
30 import org.onap.dcae.commonFunction.CommonStartup;
32 import com.google.gson.JsonIOException;
33 import com.google.gson.JsonParser;
34 import com.google.gson.JsonSyntaxException;
37 public class InputJsonValidation {
40 static String valresult = null;
44 public void nonvalidJSONValidation(){
46 JSONObject jsonObject = null;
47 JSONParser parser=new JSONParser();
49 //String jsonfilepath="C:/Users/vv770d/git/restfulcollector/src/test/resources/fujistu_non_valid_json.txt";
50 String jsonfilepath="src/test/resources/VES_invalid.txt";
51 String retValue="false";
54 obj=parser.parse(new FileReader(jsonfilepath));
59 System.out.println("Exception while opening the file");
62 jsonObject=(JSONObject) obj;
66 schema = new JsonParser().parse(new FileReader(VESCollectorJunitTest.schemaFile)).toString();
67 //System.out.println("Schema value: " + schema.toString());
68 } catch (JsonIOException e) {
69 // TODO Auto-generated catch block
71 } catch (JsonSyntaxException e) {
72 // TODO Auto-generated catch block
74 } catch (FileNotFoundException e) {
75 // TODO Auto-generated catch block
80 retValue=CommonStartup.schemavalidate(jsonObject.toString(), schema);
83 VESCollectorJunitTest.output = retValue;
87 // The below test case meant for verifying json schema on provided json file
89 public void validJSONValidation(){
91 JSONObject jsonObject = null;
92 JSONParser parser=new JSONParser();
95 String jsonfilepath="src/test/resources/VES_valid.txt";
96 String retValue="false";
99 obj=parser.parse(new FileReader(jsonfilepath));
104 System.out.println("Exception while opening the file");
107 jsonObject=(JSONObject) obj;
111 schema = new JsonParser().parse(new FileReader(VESCollectorJunitTest.schemaFile)).toString();
112 } catch (JsonIOException e) {
113 // TODO Auto-generated catch block
115 } catch (JsonSyntaxException e) {
116 // TODO Auto-generated catch block
118 } catch (FileNotFoundException e) {
119 // TODO Auto-generated catch block
124 retValue=CommonStartup.schemavalidate(jsonObject.toString(), schema);
126 VESCollectorJunitTest.output = retValue;
132 //validating valid json reception and its posting to DMAP.
134 public void eventReception(){
137 String testCurlCommand = "curl -i -X POST -d @C:/Users/vv770d/git/restfulcollector/src/test/resources/fujistu-3.txt --header \"Content-Type: application/json\" http://localhost:8080/eventListener/v1";
139 //final Process terminal = curlCommand.start();
141 Process p = Runtime.getRuntime().exec(testCurlCommand);
142 BufferedReader stdInput = new BufferedReader(new
143 InputStreamReader(p.getInputStream()));
145 BufferedReader stdError = new BufferedReader(new
146 InputStreamReader(p.getErrorStream()));
148 // read the output from the command
151 while ((s = stdInput.readLine()) != null) {
152 if (s.contains("HTTP/1.1 200 OK")){
155 VESCollectorJunitTest.output = "true";
159 } catch (IOException e) {
160 // TODO Auto-generated catch block