Consolidate PolicyRestAdapter setup
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / controller / MicroServiceDictionaryControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.pap.xacml.rest.controller;
24
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
30
31 import java.io.BufferedReader;
32 import java.io.StringReader;
33 import java.io.UnsupportedEncodingException;
34 import java.util.ArrayList;
35 import java.util.List;
36
37 import javax.servlet.http.HttpServletRequest;
38
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.Mockito;
42 import org.onap.policy.common.logging.flexlogger.FlexLogger;
43 import org.onap.policy.common.logging.flexlogger.Logger;
44 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
45 import org.onap.policy.rest.dao.CommonClassDao;
46 import org.onap.policy.rest.jpa.DCAEuuid;
47 import org.onap.policy.rest.jpa.MicroServiceLocation;
48 import org.onap.policy.rest.jpa.MicroServiceModels;
49 import org.onap.policy.rest.jpa.UserInfo;
50 import org.springframework.mock.web.MockHttpServletResponse;
51
52 /**
53  * The class <code>MicroServiceDictionaryControllerTest</code> contains tests for the class
54  * {@link <code>MicroServiceDictionaryController</code>}*
55  *
56  * All JUnits are designed to run in the local development environment where they have write privileges and can execute
57  * time-sensitive tasks.
58  */
59
60 public class MicroServiceDictionaryControllerTest {
61
62     private static Logger logger = FlexLogger.getLogger(MicroServiceDictionaryControllerTest.class);
63     private static CommonClassDao commonClassDao;
64     private String jsonString = null;
65     private HttpServletRequest request = null;
66     private MicroServiceDictionaryController controller = null;
67     BufferedReader br = null;
68
69     @Before
70     public void setUp() throws Exception {
71         logger.info("setUp: Entering");
72         commonClassDao = Mockito.mock(CommonClassDao.class);
73         UserInfo userInfo = new UserInfo();
74         userInfo.setUserLoginId("testUserId");
75         userInfo.setUserName("John");
76         when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo);
77
78         List<String> listIds = new ArrayList<String>();
79         listIds.add("Jack");
80         when(commonClassDao.getDataByColumn(DCAEuuid.class, "name")).thenReturn(listIds);
81
82         List<String> microList = new ArrayList<String>();
83         microList.add("MC-Model");
84         when(commonClassDao.getDataByColumn(MicroServiceLocation.class, "name")).thenReturn(microList);
85
86         List<Object> listId = new ArrayList<Object>();
87         listId.add("smith");
88         when(commonClassDao.getData(DCAEuuid.class)).thenReturn(listId);
89         MicroServiceModels microServiceModels = new MicroServiceModels();
90
91         doNothing().when(commonClassDao).delete(microServiceModels);
92
93         MicroServiceDictionaryController.setCommonClassDao(commonClassDao);
94
95         controller = new MicroServiceDictionaryController();
96
97         HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
98
99         jsonString = "{\"microServiceModelsDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false,"
100                 + "\"model\": {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],"
101                 + "\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\","
102                 + "\"createdBy\": \"someone\",\"modifiedBy\": \"someone\",\"content\": \"\","
103                 + "\"recursive\": false},\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
104                 + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
105                 + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
106                 + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
107                 + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
108                 + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
109                 + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
110
111         br = new BufferedReader(new StringReader(jsonString));
112         // --- mock the getReader() call
113         when(request.getReader()).thenReturn(br);
114         new DictionaryUtils(commonClassDao);
115         DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
116         mock(DictionaryUtils.class);
117         logger.info("setUp: exit");
118     }
119
120     @Test
121     public void testSaveMicroServiceHeaderDefaultValues() {
122         logger.info("testSaveMicroServiceHeaderDefaultValues: Entering");
123
124         MockHttpServletResponse response = new MockHttpServletResponse();
125         request = mock(HttpServletRequest.class);
126
127         try {
128             // mock the getReader() call
129             jsonString =
130                     "{\"modelAttributeDictionaryData\": {\"onapName\": \"test\",\"guard\": false,\"priority\": \"3\","
131                             + " \"riskType\": \"test\", \"riskLevel\": \"7\", \"modelName\": \"testname\"}}";
132             BufferedReader br = new BufferedReader(new StringReader(jsonString));
133             when(request.getReader()).thenReturn(br);
134             controller.saveMicroServiceHeaderDefaultValues(request, response);
135             logger.info("response.getContentAsString(): " + response.getContentAsString());
136             assertTrue(response.getContentAsString() != null
137                     && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
138
139         } catch (Exception e) {
140             fail("Exception: " + e);
141         }
142
143         logger.info("testSaveMicroServiceHeaderDefaultValues: exit");
144     }
145
146     @Test
147     public void testGetMicroServiceHeaderDefaultsEntityDataByName() {
148         logger.info("testGetMicroServiceHeaderDefaultsEntityDataByName: Entering");
149
150         MockHttpServletResponse response = new MockHttpServletResponse();
151
152         controller.getMicroServiceHeaderDefaultsEntityDataByName(response);
153
154         try {
155             assertTrue(response.getContentAsString() != null
156                     && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
157             logger.info("response.getContentAsString(): " + response.getContentAsString());
158         } catch (UnsupportedEncodingException e) {
159             fail("Exception: " + e);
160         }
161
162         logger.info("testGetMicroServiceHeaderDefaultsEntityDataByName: exit");
163     }
164
165     @Test
166     public void testGetMicroServiceHeaderDefaultsEntityData() {
167         logger.info("testGetMicroServiceHeaderDefaultsEntityData: Entering");
168
169         MockHttpServletResponse response = new MockHttpServletResponse();
170
171         controller.getMicroServiceHeaderDefaultsEntityData(response);
172
173         try {
174             assertTrue(response.getContentAsString() != null
175                     && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
176             logger.info("response.getContentAsString(): " + response.getContentAsString());
177         } catch (UnsupportedEncodingException e) {
178             fail("Exception: " + e);
179         }
180
181         logger.info("testGetMicroServiceHeaderDefaultsEntityData: exit");
182     }
183
184     @Test
185     public void testRemoveMicroServiceHeaderDefaults() {
186         logger.info("testRemoveMicroServiceHeaderDefaults: Entering");
187
188         MockHttpServletResponse response = new MockHttpServletResponse();
189         request = mock(HttpServletRequest.class);
190
191         try {
192             // mock the getReader() call
193             jsonString =
194                     "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
195                             + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
196                             + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
197                             + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},"
198                             + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
199                             + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
200                             + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
201                             + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
202                             + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
203                             + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
204                             + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
205             BufferedReader br = new BufferedReader(new StringReader(jsonString));
206             when(request.getReader()).thenReturn(br);
207             controller.removeMicroServiceHeaderDefaults(request, response);
208             logger.info("response.getContentAsString(): " + response.getContentAsString());
209             assertTrue(response.getContentAsString() != null
210                     && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
211
212         } catch (Exception e) {
213             fail("Exception: " + e);
214         }
215
216         logger.info("testRemoveMicroServiceHeaderDefaults: exit");
217     }
218
219     @Test
220     public void testGetDCAEUUIDDictionaryByNameEntityData() {
221
222         logger.info("testGetDCAEUUIDDictionaryByNameEntityData: Entering");
223
224         MockHttpServletResponse response = new MockHttpServletResponse();
225
226         controller.getDCAEUUIDDictionaryByNameEntityData(response);
227
228         try {
229             assertTrue(response.getContentAsString() != null
230                     && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
231             logger.info("response.getContentAsString(): " + response.getContentAsString());
232         } catch (UnsupportedEncodingException e) {
233             fail("Exception: " + e);
234         }
235
236         logger.info("testGetDCAEUUIDDictionaryByNameEntityData: exit");
237     }
238
239     @Test
240     public void testGetDCAEUUIDDictionaryEntityData() {
241
242         logger.info("testGetDCAEUUIDDictionaryEntityData: Entering");
243
244         MockHttpServletResponse response = new MockHttpServletResponse();
245
246         controller.getDCAEUUIDDictionaryEntityData(response);
247
248         try {
249             assertTrue(response.getContentAsString() != null
250                     && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
251             logger.info("response.getContentAsString(): " + response.getContentAsString());
252         } catch (UnsupportedEncodingException e) {
253             fail("Exception: " + e);
254         }
255
256         logger.info("testGetDCAEUUIDDictionaryEntityData: exit");
257     }
258
259     @Test
260     public void testSaveDCAEUUIDDictionary() {
261         logger.info("testSaveDCAEUUIDDictionary: Entering");
262
263         MockHttpServletResponse response = new MockHttpServletResponse();
264         request = mock(HttpServletRequest.class);
265
266         try {
267             // mock the getReader() call
268             jsonString = "{\"dcaeUUIDDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false,"
269                     + "\"model\": {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],"
270                     + "\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
271                     + " \"version\": \"\",\"createdBy\": \"someone\",\"modifiedBy\": \"someone\","
272                     + "\"content\": \"\",\"recursive\": false},\"tempModel\": "
273                     + "{\"name\": \"testingdata\",\"subScopename\": \"\"},"
274                     + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
275                     + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
276                     + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
277                     + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
278                     + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
279                     + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
280             BufferedReader br = new BufferedReader(new StringReader(jsonString));
281             when(request.getReader()).thenReturn(br);
282             controller.saveDCAEUUIDDictionary(request, response);
283             logger.info("response.getContentAsString(): " + response.getContentAsString());
284             assertTrue(response.getContentAsString() != null
285                     && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
286         } catch (Exception e) {
287             fail("Exception: " + e);
288         }
289         logger.info("testSaveDCAEUUIDDictionary: exit");
290     }
291
292     @Test
293     public void testRemoveDCAEUUIDDictionary() {
294         logger.info("testRemoveDCAEUUIDDictionary: Entering");
295
296         MockHttpServletResponse response = new MockHttpServletResponse();
297         request = mock(HttpServletRequest.class);
298
299         try {
300             // mock the getReader() call
301             jsonString =
302                     "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
303                             + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
304                             + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
305                             + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},"
306                             + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
307                             + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
308                             + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
309                             + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
310                             + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
311                             + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
312                             + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
313             BufferedReader br = new BufferedReader(new StringReader(jsonString));
314             when(request.getReader()).thenReturn(br);
315             controller.removeMicroServiceConfigNameDictionary(request, response);
316             logger.info("response.getContentAsString(): " + response.getContentAsString());
317             assertTrue(response.getContentAsString() != null
318                     && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
319         } catch (Exception e) {
320             fail("Exception: " + e);
321         }
322         logger.info("testRemoveDCAEUUIDDictionary: exit");
323     }
324
325     @Test
326     public void testGetMicroServiceConfigNameByNameDictionaryEntityData() {
327         logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
328
329         MockHttpServletResponse response = new MockHttpServletResponse();
330
331         controller.getMicroServiceConfigNameByNameDictionaryEntityData(response);
332
333         try {
334             assertTrue(response.getContentAsString() != null
335                     && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
336             logger.info("response.getContentAsString(): " + response.getContentAsString());
337         } catch (UnsupportedEncodingException e) {
338             fail("Exception: " + e);
339         }
340
341         logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: exit");
342     }
343
344     @Test
345     public void testGetMicroServiceConfigNameDictionaryEntityData() {
346         logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
347
348         MockHttpServletResponse response = new MockHttpServletResponse();
349
350         controller.getMicroServiceConfigNameDictionaryEntityData(response);
351
352         try {
353             assertTrue(response.getContentAsString() != null
354                     && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
355             logger.info("response.getContentAsString(): " + response.getContentAsString());
356         } catch (UnsupportedEncodingException e) {
357             fail("Exception: " + e);
358         }
359
360         logger.info("testGetMicroServiceConfigNameDictionaryEntityData: exit");
361     }
362
363     @Test
364     public void testSaveMicroServiceConfigNameDictionary() {
365         logger.info("testSaveMicroServiceConfigNameDictionary: Entering");
366
367         MockHttpServletResponse response = new MockHttpServletResponse();
368         request = mock(HttpServletRequest.class);
369
370         try {
371             // mock the getReader() call
372             jsonString = "{\"microServiceConfigNameDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false,"
373                     + "\"model\": {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],"
374                     + "\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\","
375                     + "\"createdBy\": \"someone\",\"modifiedBy\": \"someone\",\"content\": \"\","
376                     + "\"recursive\": false},\"tempModel\": {\"name\": \"testingdata\","
377                     + "\"subScopename\": \"\"},\"policy\": "
378                     + "{\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
379                     + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
380                     + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
381                     + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
382                     + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
383                     + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
384             BufferedReader br = new BufferedReader(new StringReader(jsonString));
385             when(request.getReader()).thenReturn(br);
386             controller.saveMicroServiceConfigNameDictionary(request, response);
387             logger.info("response.getContentAsString(): " + response.getContentAsString());
388             assertTrue(response.getContentAsString() != null
389                     && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
390         } catch (Exception e) {
391             fail("Exception: " + e);
392         }
393         logger.info("testSaveMicroServiceConfigNameDictionary: exit");
394     }
395
396     @Test
397     public void testRemoveMicroServiceConfigNameDictionary() {
398         logger.info("testRemoveMicroServiceConfigNameDictionary: Entering");
399
400         MockHttpServletResponse response = new MockHttpServletResponse();
401         request = mock(HttpServletRequest.class);
402
403         try {
404             // mock the getReader() call
405             jsonString =
406                     "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
407                             + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
408                             + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
409                             + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},"
410                             + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
411                             + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
412                             + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
413                             + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
414                             + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
415                             + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
416                             + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
417             BufferedReader br = new BufferedReader(new StringReader(jsonString));
418             when(request.getReader()).thenReturn(br);
419             controller.removeMicroServiceConfigNameDictionary(request, response);
420             logger.info("response.getContentAsString(): " + response.getContentAsString());
421             assertTrue(response.getContentAsString() != null
422                     && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
423         } catch (Exception e) {
424             fail("Exception: " + e);
425         }
426         logger.info("testRemoveMicroServiceConfigNameDictionary: exit");
427     }
428
429     @Test
430     public void testGetMicroServiceLocationByNameDictionaryEntityData() {
431
432         logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: Entering");
433
434         MockHttpServletResponse response = new MockHttpServletResponse();
435
436         controller.getMicroServiceLocationByNameDictionaryEntityData(response);
437
438         try {
439             assertTrue(response.getContentAsString() != null
440                     && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
441             logger.info("response.getContentAsString(): " + response.getContentAsString());
442         } catch (UnsupportedEncodingException e) {
443             fail("Exception: " + e);
444         }
445
446         logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: exit");
447     }
448
449     @Test
450     public void testGetMicroServiceLocationDictionaryEntityData() {
451         logger.info("testGetMicroServiceLocationDictionaryEntityData: Entering");
452
453         MockHttpServletResponse response = new MockHttpServletResponse();
454
455         controller.getMicroServiceLocationDictionaryEntityData(response);
456
457         try {
458             assertTrue(response.getContentAsString() != null
459                     && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
460             logger.info("response.getContentAsString(): " + response.getContentAsString());
461         } catch (UnsupportedEncodingException e) {
462             fail("Exception: " + e);
463         }
464
465         logger.info("testGetMicroServiceLocationDictionaryEntityData: exit");
466     }
467
468     @Test
469     public void testSaveMicroServiceLocationDictionary() {
470         logger.info("testSaveMicroServiceLocationDictionary: Entering");
471
472         MockHttpServletResponse response = new MockHttpServletResponse();
473         request = mock(HttpServletRequest.class);
474
475         try {
476             // mock the getReader() call
477             jsonString = "{\"microServiceLocationDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false,"
478                     + "\"model\": {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],"
479                     + "\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\","
480                     + "\"version\": \"\",\"createdBy\": \"someone\",\"modifiedBy\": \"someone\","
481                     + "\"content\": \"\",\"recursive\": false},\"tempModel\": "
482                     + "{\"name\": \"testingdata\",\"subScopename\": \"\"},"
483                     + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
484                     + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
485                     + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
486                     + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
487                     + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
488                     + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
489             BufferedReader br = new BufferedReader(new StringReader(jsonString));
490             when(request.getReader()).thenReturn(br);
491             controller.saveMicroServiceLocationDictionary(request, response);
492             logger.info("response.getContentAsString(): " + response.getContentAsString());
493             assertTrue(response.getContentAsString() != null
494                     && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
495
496         } catch (Exception e) {
497             fail("Exception: " + e);
498         }
499
500         logger.info("testSaveMicroServiceLocationDictionary: exit");
501     }
502
503     @Test
504     public void testRemoveMicroServiceLocationDictionary() {
505         logger.info("testRemoveMicroServiceLocationDictionary: Entering");
506
507         MockHttpServletResponse response = new MockHttpServletResponse();
508         request = mock(HttpServletRequest.class);
509
510         try {
511             // mock the getReader() call
512             jsonString =
513                     "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
514                             + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
515                             + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
516                             + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},\"policy\": "
517                             + "{\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
518                             + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
519                             + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
520                             + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
521                             + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
522                             + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
523             BufferedReader br = new BufferedReader(new StringReader(jsonString));
524
525             when(request.getReader()).thenReturn(br);
526             controller.removeMicroServiceLocationDictionary(request, response);
527             logger.info("response.getContentAsString(): " + response.getContentAsString());
528             assertTrue(response.getContentAsString() != null
529                     && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
530         } catch (Exception e) {
531             fail("Exception: " + e);
532         }
533         logger.info("testRemoveMicroServiceLocationDictionary: exit");
534     }
535
536     @Test
537     public void testGetMicroServiceAttributeByNameDictionaryEntityData() {
538         logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: Entering");
539
540         MockHttpServletResponse response = new MockHttpServletResponse();
541
542         controller.getMicroServiceAttributeByNameDictionaryEntityData(response);
543
544         try {
545             assertTrue(response.getContentAsString() != null
546                     && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
547             logger.info("response.getContentAsString(): " + response.getContentAsString());
548         } catch (UnsupportedEncodingException e) {
549             fail("Exception: " + e);
550         }
551
552         logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: exit");
553     }
554
555     @Test
556     public void testGetMicroServiceAttributeDictionaryEntityData() {
557         logger.info("testGetMicroServiceAttributeDictionaryEntityData: Entering");
558
559         MockHttpServletResponse response = new MockHttpServletResponse();
560
561         controller.getMicroServiceAttributeDictionaryEntityData(response);
562
563         try {
564             assertTrue(response.getContentAsString() != null
565                     && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
566             logger.info("response.getContentAsString(): " + response.getContentAsString());
567         } catch (UnsupportedEncodingException e) {
568             fail("Exception: " + e);
569         }
570
571         logger.info("testGetMicroServiceAttributeDictionaryEntityData: exit");
572     }
573
574     @Test
575     public void testSaveMicroServiceAttributeDictionary() {
576         logger.info("testSaveMicroServiceAttributeDictionary: Entering");
577
578         MockHttpServletResponse response = new MockHttpServletResponse();
579         request = mock(HttpServletRequest.class);
580
581         try {
582             // mock the getReader() call
583             jsonString = "{\"modelAttributeDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false,"
584                     + "\"model\": {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],"
585                     + "\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\","
586                     + "\"createdBy\": \"someone\",\"modifiedBy\": \"someone\",\"content\": \"\","
587                     + "\"recursive\": false},\"tempModel\": " + "{\"name\": \"testingdata\",\"subScopename\": \"\"},"
588                     + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
589                     + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
590                     + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
591                     + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
592                     + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
593                     + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
594             BufferedReader br = new BufferedReader(new StringReader(jsonString));
595             when(request.getReader()).thenReturn(br);
596             controller.saveMicroServiceAttributeDictionary(request, response);
597             logger.info("response.getContentAsString(): " + response.getContentAsString());
598             assertTrue(response.getContentAsString() != null
599                     && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
600         } catch (Exception e) {
601             fail("Exception: " + e);
602         }
603         logger.info("testSaveMicroServiceAttributeDictionary: exit");
604     }
605
606     @Test
607     public void testRemoveMicroServiceAttributeDictionary() {
608         logger.info("testRemoveMicroServiceAttributeDictionary: Entering");
609
610         MockHttpServletResponse response = new MockHttpServletResponse();
611         request = mock(HttpServletRequest.class);
612
613         try {
614             // mock the getReader() call
615             jsonString =
616                     "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
617                             + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
618                             + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
619                             + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},\"tempModel\": "
620                             + "{\"name\": \"testingdata\",\"subScopename\": \"\"},\"policy\": "
621                             + "{\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
622                             + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
623                             + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
624                             + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
625                             + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
626                             + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
627             BufferedReader br = new BufferedReader(new StringReader(jsonString));
628             when(request.getReader()).thenReturn(br);
629             controller.removeMicroServiceAttributeDictionary(request, response);
630             logger.info("response.getContentAsString(): " + response.getContentAsString());
631             assertTrue(response.getContentAsString() != null
632                     && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
633
634         } catch (Exception e) {
635             fail("Exception: " + e);
636         }
637
638         logger.info("testRemoveMicroServiceAttributeDictionary: exit");
639     }
640
641     @Test
642     public void testGetMicroServiceModelsDictionaryByNameEntityData() {
643         logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: Entering");
644
645         MockHttpServletResponse response = new MockHttpServletResponse();
646
647         controller.getMicroServiceModelsDictionaryByNameEntityData(response);
648
649         try {
650             assertTrue(response.getContentAsString() != null
651                     && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
652             logger.info("response.getContentAsString(): " + response.getContentAsString());
653         } catch (UnsupportedEncodingException e) {
654             fail("Exception: " + e);
655         }
656
657         logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: exit");
658     }
659
660     @Test
661     public void testGetMicroServiceModelsDictionaryByVersionEntityData() {
662         logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: Entering");
663
664         MockHttpServletResponse response = new MockHttpServletResponse();
665         String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
666
667         BufferedReader br = new BufferedReader(new StringReader(msModelJson));
668         request = mock(HttpServletRequest.class);
669
670         try {
671             // mock the getReader() call
672             when(request.getReader()).thenReturn(br);
673             controller.getMicroServiceModelsDictionaryByVersionEntityData(request, response);
674             logger.info("response.getContentAsString(): " + response.getContentAsString());
675             assertTrue(response.getContentAsString() != null
676                     && response.getContentAsString().contains("No model name given"));
677
678         } catch (Exception e) {
679             fail("Exception: " + e);
680         }
681
682         logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: exit");
683     }
684
685     @Test
686     public void testGetMicroServiceModelsDictionaryEntityData() {
687         logger.info("testGetMicroServiceModelsDictionaryEntityData: Entering");
688
689         MockHttpServletResponse response = new MockHttpServletResponse();
690         String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
691
692         BufferedReader br = new BufferedReader(new StringReader(msModelJson));
693         request = mock(HttpServletRequest.class);
694
695         try {
696             // mock the getReader() call
697             when(request.getReader()).thenReturn(br);
698             controller.getMicroServiceModelsDictionaryEntityData(response);
699             logger.info("response.getContentAsString(): " + response.getContentAsString());
700             assertTrue(response.getContentAsString() != null
701                     && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
702
703         } catch (Exception e) {
704             fail("Exception: " + e);
705         }
706
707         logger.info("testGetMicroServiceModelsDictionaryEntityData: exit");
708     }
709
710     @Test
711     public void testGetMicroServiceModelsDictionaryEntityDataServiceVersion() {
712         logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: Entering");
713
714         MockHttpServletResponse response = new MockHttpServletResponse();
715         String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
716
717         BufferedReader br = new BufferedReader(new StringReader(msModelJson));
718         request = mock(HttpServletRequest.class);
719
720         try {
721             // mock the getReader() call
722             when(request.getReader()).thenReturn(br);
723             controller.getMicroServiceModelsDictionaryEntityDataServiceVersion(response);
724             logger.info("response.getContentAsString(): " + response.getContentAsString());
725             assertTrue(response.getContentAsString() != null
726                     && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
727
728         } catch (Exception e) {
729             fail("Exception: " + e);
730         }
731
732         logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: exit");
733     }
734
735     @Test
736     public void testGetMicroServiceModelsDictionaryClassEntityData() {
737         logger.info("testGetMicroServiceModelsDictionaryClassEntityData: Entering");
738
739         MockHttpServletResponse response = new MockHttpServletResponse();
740         String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
741
742         BufferedReader br = new BufferedReader(new StringReader(msModelJson));
743         request = mock(HttpServletRequest.class);
744
745         try {
746             // mock the getReader() call
747             when(request.getReader()).thenReturn(br);
748             controller.getMicroServiceModelsDictionaryClassEntityData(response);
749             logger.info("response.getContentAsString(): " + response.getContentAsString());
750             assertTrue(response.getContentAsString() != null
751                     && response.getContentAsString().contains("microServiceModelsDictionaryClassDatas"));
752
753         } catch (Exception e) {
754             fail("Exception: " + e);
755         }
756
757         logger.info("testGetMicroServiceModelsDictionaryClassEntityData: exit");
758     }
759
760     @Test
761     public void testSaveMicroServiceModelsDictionary() {
762         logger.info("testSaveMicroServiceModelsDictionary: Entering");
763
764         MockHttpServletResponse response = new MockHttpServletResponse();
765         request = mock(HttpServletRequest.class);
766
767         try {
768             // mock the getReader() call
769             when(request.getReader()).thenReturn(br);
770             controller.saveMicroServiceModelsDictionary(request, response);
771             logger.info("response.getContentAsString(): " + response.getContentAsString());
772             assertTrue(response.getContentAsString() != null
773                     && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
774
775         } catch (Exception e) {
776             fail("Exception: " + e);
777         }
778
779         logger.info("testSaveMicroServiceModelsDictionary: exit");
780     }
781
782     @Test
783     public void testRemoveMicroServiceModelsDictionary() {
784         logger.info("testRemoveMicroServiceModelsDictionary: Entering");
785
786         MockHttpServletResponse response = new MockHttpServletResponse();
787         request = mock(HttpServletRequest.class);
788
789         try {
790             // mock the getReader() call
791             jsonString =
792                     "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
793                             + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
794                             + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
795                             + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},"
796                             + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
797                             + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
798                             + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
799                             + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
800                             + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
801                             + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
802                             + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
803
804             BufferedReader br = new BufferedReader(new StringReader(jsonString));
805             when(request.getReader()).thenReturn(br);
806             controller.removeMicroServiceModelsDictionary(request, response);
807             logger.info("response.getContentAsString(): " + response.getContentAsString());
808             assertTrue(response.getContentAsString() != null
809                     && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
810         } catch (Exception e) {
811             fail("Exception: " + e);
812         }
813         logger.info("testRemoveMicroServiceModelsDictionary: exit");
814     }
815
816     @Test
817     public void testRemoveMicroServiceDictionaryData() {
818         logger.info("testRemoveMicroServiceModelsDictionary: Entering");
819
820         MockHttpServletResponse response = new MockHttpServletResponse();
821         request = mock(HttpServletRequest.class);
822
823         try {
824             jsonString =
825                     "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
826                             + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,"
827                             + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\","
828                             + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false},"
829                             + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"},"
830                             + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\","
831                             + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\","
832                             + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\","
833                             + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\","
834                             + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}},"
835                             + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}";
836
837             BufferedReader br = new BufferedReader(new StringReader(jsonString));
838             when(request.getReader()).thenReturn(br);
839             controller.removeMicroServiceDictionaryData(request, response);
840             logger.info("response.getContentAsString(): " + response.getContentAsString());
841             assertTrue(response.getContentAsString() != null
842                     && response.getContentAsString().contains("microServiceDictionaryData"));
843         } catch (Exception e) {
844             fail("Exception: " + e);
845         }
846         logger.info("testRemoveMicroServiceModelsDictionary: exit");
847     }
848
849     @Test
850     public void getMicroServiceDictNameDictionaryEntityData() {
851         logger.info("getMicroServiceDictNameDictionaryEntityData: Entering");
852
853         MockHttpServletResponse response = new MockHttpServletResponse();
854         String msModelJson = "{\"microServiceDictionaryData\":[\"modelName\"]}";
855
856         BufferedReader br = new BufferedReader(new StringReader(msModelJson));
857         request = mock(HttpServletRequest.class);
858
859         try {
860             when(request.getReader()).thenReturn(br);
861             controller.getMicroServiceDictNameDictionaryEntityData(response);
862             logger.info("response.getContentAsString(): " + response.getContentAsString());
863             assertTrue(response.getContentAsString() != null
864                     && response.getContentAsString().contains("microServiceDictionaryData"));
865
866         } catch (Exception e) {
867             fail("Exception: " + e);
868         }
869
870         logger.info("getMicroServiceDictNameDictionaryEntityData: exit");
871     }
872
873     @Test
874     public void testSaveDictionaryData() {
875         logger.info("testSaveDictionaryData: Entering");
876
877         MockHttpServletResponse response = new MockHttpServletResponse();
878         request = mock(HttpServletRequest.class);
879
880         try {
881             jsonString = "{\"microServiceDictionaryDatas\": {\"id\": 1,\"dictionaryName\": \"tes1t\","
882                     + "\"dictionaryUrl\": \"tes1t\",\"dictionaryDataByName\": \"test\"}}";
883             BufferedReader br = new BufferedReader(new StringReader(jsonString));
884             when(request.getReader()).thenReturn(br);
885             controller.saveDictionaryData(request, response);
886             logger.info("response.getContentAsString(): " + response.getContentAsString());
887             assertTrue(response.getContentAsString() != null
888                     && response.getContentAsString().contains("microServiceDictionaryDatas"));
889         } catch (Exception e) {
890             fail("Exception: " + e);
891         }
892         logger.info("testSaveDictionaryData: exit");
893     }
894 }