Updating certificates to fix healthcheck
[aaf/sms.git] / sms-client / src / test / java / org / onap / aaf / sms / SmsTest.java
1 /*
2  * Copyright 2018 Intel Corporation, Inc
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.aaf.sms;
18
19 import javax.net.ssl.SSLSocketFactory;
20 import java.net.URL;
21 import javax.net.ssl.HttpsURLConnection;
22 import org.onap.aaf.sms.SmsResponse;
23 import org.onap.aaf.sms.SmsClient;
24 import java.io.InputStream;
25 import java.io.OutputStream;
26 import java.io.InputStreamReader;
27 import java.io.BufferedReader;
28 import java.io.OutputStreamWriter;
29 import java.util.Map;
30 import java.util.HashMap;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.ArrayList;
34 import org.json.JSONArray;
35 import org.json.JSONException;
36 import org.json.JSONObject;
37
38 public class SmsTest extends SmsClient {
39
40     public SmsTest(String host, int port, SSLSocketFactory s) {
41         super(host, port, s);
42     }
43     public SmsTest(String host, int port, String version, SSLSocketFactory s) {
44         super(host, port, version, s);
45     }
46     public  SmsResponse execute(String reqtype, String t, String ins, boolean input, boolean output) {
47         Map<String, Object> m;
48         SmsResponse resp = new SmsResponse();
49         System.out.println(t);
50
51         switch ( reqtype ) {
52             case "POST":
53                 if ( t.matches("(.*)/v1/sms/domain")) {
54                     resp.setSuccess(true);
55                     resp.setResponseCode(201);
56                     try {
57                         m = strtomap(ins);
58                     } catch ( Exception e ) {
59                         resp.setResponse(null);
60                         return(resp);
61                     }
62                     resp.setResponse(m);
63                 } else {
64                     if ( t.matches("(.*)/v1/sms/(.*)/secret") ) {
65                         resp.setSuccess(true);
66                         resp.setResponseCode(201);
67                     }
68                 }
69             break;
70             case "GET":
71                 if ( t.matches("(.*)/v1/sms/(.*)/secret") ) {
72                     resp.setSuccess(true);
73                     resp.setResponseCode(200);
74                     String jstr = "{\"secretnames\":[\"testsec1\",\"newtest\"]}";
75                     try {
76                         m = strtomap(jstr);
77                     } catch ( Exception e ) {
78                         resp.setResponse(null);
79                         return(resp);
80                     }
81                     resp.setResponse(m);
82                 } else {
83                     if ( t.matches("(.*)/v1/sms/(.*)/secret/testsec1")) {
84                         resp.setSuccess(true);
85                         resp.setResponseCode(200);
86                         String js = "{\"name\":\"testsec1\",\"values\":{\"username\":\"dbuser\",\"passwd\":\"jdX784i-5k\"}}";
87                         try {
88                             m = strtomap(js);
89                             Map<String, Object> sm = (Map<String, Object>)m.get("values");
90                         } catch ( Exception e ) {
91                             resp.setResponse(null);
92                             return(resp);
93                         }
94                         resp.setResponse(m);
95                     }
96                 }
97             break;
98             case "DELETE":
99                 if ( t.matches("(.*)/v1/sms/domain/(.*)") ) {
100                     // for both delete domain & secret case
101                     resp.setSuccess(true);
102                     resp.setResponseCode(204);
103                     resp.setResponse(null);
104                 }
105             break;
106
107         }
108         return resp;
109     }
110 }