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