DMAAP-MR - Merge MR repos
[dmaap/messagerouter/messageservice.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 public class DMaapTopicTest {
25         /*private static final Logger LOGGER = Logger.getLogger(DMaapTopicTest.class);
26         Client client = ClientBuilder.newClient();
27         String topicapikey, topicsecretKey, serverCalculatedSignature;
28         Properties prop = LoadPropertyFile.getPropertyFileData();
29         String topicName = prop.getProperty("topicName");
30         String url = prop.getProperty("url");
31         String date = prop.getProperty("date");
32         WebTarget target = client.target(url);
33         DmaapApiKeyTest keyInstance = new DmaapApiKeyTest();
34
35
36
37         public boolean topicExist(String topicName) {
38                 target = target.path("/topics/" + topicName);
39                 InputStream is, issecret;
40                 Response response = target.request().get();
41                 if (response.getStatus() == HttpStatus.SC_OK) {
42                         is = (InputStream) response.getEntity();
43                         Scanner s = new Scanner(is);
44                         s.useDelimiter("\\A");
45                         JSONObject dataObj = new JSONObject(s.next());
46                         s.close();
47                         // get owner of a topic
48                         topicapikey = (String) dataObj.get("owner");
49                         target = client.target(url);
50                         target = target.path("/apiKeys/");
51                         target = target.path(topicapikey);
52                         Response response2 = target.request().get();
53                         issecret = (InputStream) response2.getEntity();
54                         Scanner st = new Scanner(issecret);
55                         st.useDelimiter("\\A");
56                         JSONObject dataObj1 = new JSONObject(st.next());
57                         st.close();
58                         // get secret key of this topic//
59                         topicsecretKey = (String) dataObj1.get("secret");
60                         serverCalculatedSignature = sha1HmacSigner.sign(date, topicsecretKey);
61                         return true;
62                 } else
63                         return false;
64         }
65
66         public void testCreateTopic() {
67                 LOGGER.info("test case create topic");
68                 createTopic(topicName);
69                 LOGGER.info("Returning after create topic");
70         }
71
72         public void testOneTopic() {
73                 LOGGER.info("test case get specific topic name " + topicName);
74                 createTopic(topicName);
75                 target = client.target(url);
76                 target = target.path("/topics/");
77                 target = target.path(topicName);
78                 Response response = target.request().get();
79                 LOGGER.info("Successfully returned after fetching topic" + topicName);
80                 keyInstance.assertStatus(response);
81                 InputStream is = (InputStream) response.getEntity();
82                 Scanner s = new Scanner(is);
83                 s.useDelimiter("\\A");
84                 JSONObject dataObj = new JSONObject(s.next());
85                 LOGGER.info("Details of " + topicName + " : " + dataObj.toString());
86                 s.close();
87         }
88
89         public void testdeleteTopic() {
90                 LOGGER.info("test case delete topic name " + topicName);
91                 createTopic(topicName);
92                 target = client.target(url);
93                 target = target.path("/topics/");
94                 target = target.path(topicName);
95                 Response response = target.request().header("X-CambriaAuth", topicapikey + ":" + serverCalculatedSignature)
96                                 .header("X-CambriaDate", date).delete();
97                 keyInstance.assertStatus(response);
98                 LOGGER.info("Successfully returned after deleting topic" + topicName);
99         }
100
101         public void testAllTopic() {
102                 LOGGER.info("test case fetch all topic");
103                 target = client.target(url);
104                 target = target.path("/topics");
105                 Response response = target.request().get();
106                 keyInstance.assertStatus(response);
107                 LOGGER.info("successfully returned after fetching all the topic");
108                 InputStream is = (InputStream) response.getEntity();
109                 Scanner s = new Scanner(is);
110                 s.useDelimiter("\\A");
111                 JSONObject dataObj = new JSONObject(s.next());
112                 s.close();
113                 LOGGER.info("List of all topics " + dataObj.toString());
114         }
115
116         public void testPublisherForTopic() {
117                 LOGGER.info("test case get all publishers for topic: " + topicName);
118                 // creating topic to check
119                 createTopic(topicName);
120                 target = client.target(url);
121                 target = target.path("/topics/");
122                 target = target.path(topicName);
123                 target = target.path("/producers");
124                 // checking all producer for a particular topic
125                 Response response = target.request().get();
126                 keyInstance.assertStatus(response);
127                 LOGGER.info("Successfully returned after getting all the publishers" + topicName);
128         }
129
130
131         public void testConsumerForTopic() {
132                 LOGGER.info("test case get all consumers for topic: " + topicName);
133                 // creating topic to check
134                 createTopic(topicName);
135                 target = client.target(url);
136                 target = target.path("/topics/");
137                 target = target.path(topicName);
138                 target = target.path("/consumers");
139                 // checking all consumer for a particular topic
140                 Response response = target.request().get();
141                 keyInstance.assertStatus(response);
142                 LOGGER.info("Successfully returned after getting all the consumers" + topicName);
143         }
144
145
146 */
147 }