clean MR codebase
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / test / dmaap / DMaapTopicTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 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
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.mr.test.dmaap;
23
24 import java.io.InputStream;
25 import java.util.Properties;
26 import java.util.Scanner;
27
28 import javax.ws.rs.client.Client;
29 import javax.ws.rs.client.ClientBuilder;
30 import javax.ws.rs.client.Entity;
31 import javax.ws.rs.client.WebTarget;
32 import javax.ws.rs.core.Response;
33
34 import junit.framework.TestCase;
35
36 import org.apache.http.HttpStatus;
37 import org.json.JSONObject;
38 import org.apache.log4j.Logger;
39
40 import com.att.nsa.drumlin.till.data.sha1HmacSigner;
41
42 public class DMaapTopicTest {
43         /*private static final Logger LOGGER = Logger.getLogger(DMaapTopicTest.class);
44         Client client = ClientBuilder.newClient();
45         String topicapikey, topicsecretKey, serverCalculatedSignature;
46         Properties prop = LoadPropertyFile.getPropertyFileData();
47         String topicName = prop.getProperty("topicName");
48         String url = prop.getProperty("url");
49         String date = prop.getProperty("date");
50         WebTarget target = client.target(url);
51         DmaapApiKeyTest keyInstance = new DmaapApiKeyTest();
52
53
54
55         public boolean topicExist(String topicName) {
56                 target = target.path("/topics/" + topicName);
57                 InputStream is, issecret;
58                 Response response = target.request().get();
59                 if (response.getStatus() == HttpStatus.SC_OK) {
60                         is = (InputStream) response.getEntity();
61                         Scanner s = new Scanner(is);
62                         s.useDelimiter("\\A");
63                         JSONObject dataObj = new JSONObject(s.next());
64                         s.close();
65                         // get owner of a topic
66                         topicapikey = (String) dataObj.get("owner");
67                         target = client.target(url);
68                         target = target.path("/apiKeys/");
69                         target = target.path(topicapikey);
70                         Response response2 = target.request().get();
71                         issecret = (InputStream) response2.getEntity();
72                         Scanner st = new Scanner(issecret);
73                         st.useDelimiter("\\A");
74                         JSONObject dataObj1 = new JSONObject(st.next());
75                         st.close();
76                         // get secret key of this topic//
77                         topicsecretKey = (String) dataObj1.get("secret");
78                         serverCalculatedSignature = sha1HmacSigner.sign(date, topicsecretKey);
79                         return true;
80                 } else
81                         return false;
82         }
83
84         public void testCreateTopic() {
85                 LOGGER.info("test case create topic");
86                 createTopic(topicName);
87                 LOGGER.info("Returning after create topic");
88         }
89
90         public void testOneTopic() {
91                 LOGGER.info("test case get specific topic name " + topicName);
92                 createTopic(topicName);
93                 target = client.target(url);
94                 target = target.path("/topics/");
95                 target = target.path(topicName);
96                 Response response = target.request().get();
97                 LOGGER.info("Successfully returned after fetching topic" + topicName);
98                 keyInstance.assertStatus(response);
99                 InputStream is = (InputStream) response.getEntity();
100                 Scanner s = new Scanner(is);
101                 s.useDelimiter("\\A");
102                 JSONObject dataObj = new JSONObject(s.next());
103                 LOGGER.info("Details of " + topicName + " : " + dataObj.toString());
104                 s.close();
105         }
106
107         public void testdeleteTopic() {
108                 LOGGER.info("test case delete topic name " + topicName);
109                 createTopic(topicName);
110                 target = client.target(url);
111                 target = target.path("/topics/");
112                 target = target.path(topicName);
113                 Response response = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature)
114                                 .header("X-CambriaDate", date).delete();
115                 keyInstance.assertStatus(response);
116                 LOGGER.info("Successfully returned after deleting topic" + topicName);
117         }
118
119         public void testAllTopic() {
120                 LOGGER.info("test case fetch all topic");
121                 target = client.target(url);
122                 target = target.path("/topics");
123                 Response response = target.request().get();
124                 keyInstance.assertStatus(response);
125                 LOGGER.info("successfully returned after fetching all the topic");
126                 InputStream is = (InputStream) response.getEntity();
127                 Scanner s = new Scanner(is);
128                 s.useDelimiter("\\A");
129                 JSONObject dataObj = new JSONObject(s.next());
130                 s.close();
131                 LOGGER.info("List of all topics " + dataObj.toString());
132         }
133
134         public void testPublisherForTopic() {
135                 LOGGER.info("test case get all publishers for topic: " + topicName);
136                 // creating topic to check
137                 createTopic(topicName);
138                 target = client.target(url);
139                 target = target.path("/topics/");
140                 target = target.path(topicName);
141                 target = target.path("/producers");
142                 // checking all producer for a particular topic
143                 Response response = target.request().get();
144                 keyInstance.assertStatus(response);
145                 LOGGER.info("Successfully returned after getting all the publishers" + topicName);
146         }
147
148
149         public void testConsumerForTopic() {
150                 LOGGER.info("test case get all consumers for topic: " + topicName);
151                 // creating topic to check
152                 createTopic(topicName);
153                 target = client.target(url);
154                 target = target.path("/topics/");
155                 target = target.path(topicName);
156                 target = target.path("/consumers");
157                 // checking all consumer for a particular topic
158                 Response response = target.request().get();
159                 keyInstance.assertStatus(response);
160                 LOGGER.info("Successfully returned after getting all the consumers" + topicName);
161         }
162
163
164 */
165 }