2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.xacml.rest.controller;
24 import static org.junit.Assert.assertEquals;
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;
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;
37 import javax.servlet.http.HttpServletRequest;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.Mockito;
43 import org.onap.policy.common.logging.flexlogger.FlexLogger;
44 import org.onap.policy.common.logging.flexlogger.Logger;
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;
53 * The class <code>MicroServiceDictionaryControllerTest</code> contains tests
54 * for the class {@link <code>MicroServiceDictionaryController</code>}*
56 * All JUnits are designed to run in the local development environment
57 * where they have write privileges and can execute time-sensitive
61 public class MicroServiceDictionaryControllerTest {
63 private static Logger logger = FlexLogger.getLogger(MicroServiceDictionaryControllerTest.class);
64 private static CommonClassDao commonClassDao;
65 private String jsonString = null;
66 private HttpServletRequest request = null;
67 private MicroServiceDictionaryController controller = null;
68 BufferedReader br = null;
71 public void setUp() throws Exception {
72 logger.info("setUp: Entering");
73 commonClassDao = Mockito.mock(CommonClassDao.class);
74 UserInfo userInfo = new UserInfo();
75 userInfo.setUserLoginId("testUserId");
76 userInfo.setUserName("John");
77 when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo);
79 List<String> listIds = new ArrayList<String>();
81 when(commonClassDao.getDataByColumn(DCAEuuid.class, "name")).thenReturn(listIds);
83 List<String> microList = new ArrayList<String>();
84 microList.add("MC-Model");
85 when(commonClassDao.getDataByColumn(MicroServiceLocation.class, "name")).thenReturn(microList);
87 List<Object> listId = new ArrayList<Object>();
89 when(commonClassDao.getData(DCAEuuid.class)).thenReturn(listId);
90 MicroServiceModels microServiceModels = new MicroServiceModels();
92 doNothing().when(commonClassDao).delete(microServiceModels);
94 MicroServiceDictionaryController.setCommonClassDao(commonClassDao);
96 controller = new MicroServiceDictionaryController();
98 HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
100 jsonString = "{\"microServiceModelsDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
101 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
102 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
103 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
104 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
105 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
106 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
107 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
109 br = new BufferedReader(new StringReader(jsonString));
110 //--- mock the getReader() call
111 when(request.getReader()).thenReturn(br);
113 logger.info("setUp: exit");
117 public void tearDown() throws Exception {
122 public void testGetUserInfo() {
124 logger.info("testGetUserInfo: Entering");
126 UserInfo userInfo = controller.getUserInfo("testing");
127 logger.info("userInfo.getUserName() : " + userInfo.getUserName());
129 assertEquals("John", userInfo.getUserName());
131 logger.info("testGetUserInfo: exit");
135 public void testGetDCAEUUIDDictionaryByNameEntityData() {
137 logger.info("testGetDCAEUUIDDictionaryByNameEntityData: Entering");
139 MockHttpServletResponse response = new MockHttpServletResponse();
141 controller.getDCAEUUIDDictionaryByNameEntityData(response);
144 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
145 logger.info("response.getContentAsString(): " + response.getContentAsString());
146 } catch (UnsupportedEncodingException e) {
147 fail("Exception: " + e);
150 logger.info("testGetDCAEUUIDDictionaryByNameEntityData: exit");
154 public void testGetDCAEUUIDDictionaryEntityData() {
156 logger.info("testGetDCAEUUIDDictionaryEntityData: Entering");
158 MockHttpServletResponse response = new MockHttpServletResponse();
160 controller.getDCAEUUIDDictionaryEntityData(response);
163 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
164 logger.info("response.getContentAsString(): " + response.getContentAsString());
165 } catch (UnsupportedEncodingException e) {
166 fail("Exception: " + e);
169 logger.info("testGetDCAEUUIDDictionaryEntityData: exit");
173 public void testSaveDCAEUUIDDictionary() {
174 logger.info("testSaveDCAEUUIDDictionary: Entering");
176 MockHttpServletResponse response = new MockHttpServletResponse();
177 request = mock(HttpServletRequest.class);
180 // mock the getReader() call
181 jsonString = "{\"dcaeUUIDDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
182 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
183 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
184 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
185 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
186 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
187 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
188 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
189 BufferedReader br = new BufferedReader(new StringReader(jsonString));
190 when(request.getReader()).thenReturn(br);
191 controller.saveDCAEUUIDDictionary(request, response);
192 logger.info("response.getContentAsString(): " + response.getContentAsString());
193 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
195 } catch (Exception e) {
196 fail("Exception: " + e);
199 logger.info("testSaveDCAEUUIDDictionary: exit");
203 public void testRemoveDCAEUUIDDictionary() {
204 logger.info("testRemoveDCAEUUIDDictionary: Entering");
206 MockHttpServletResponse response = new MockHttpServletResponse();
207 request = mock(HttpServletRequest.class);
210 // mock the getReader() call
211 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
212 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
213 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
214 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
215 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
216 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
217 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
218 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
219 BufferedReader br = new BufferedReader(new StringReader(jsonString));
220 when(request.getReader()).thenReturn(br);
221 controller.removeMicroServiceConfigNameDictionary(request, response);
222 logger.info("response.getContentAsString(): " + response.getContentAsString());
223 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
225 } catch (Exception e) {
226 fail("Exception: " + e);
229 logger.info("testRemoveDCAEUUIDDictionary: exit");
233 public void testGetMicroServiceConfigNameByNameDictionaryEntityData() {
234 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
236 MockHttpServletResponse response = new MockHttpServletResponse();
238 controller.getMicroServiceConfigNameByNameDictionaryEntityData(response);
241 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
242 logger.info("response.getContentAsString(): " + response.getContentAsString());
243 } catch (UnsupportedEncodingException e) {
244 fail("Exception: " + e);
247 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: exit");
251 public void testGetMicroServiceConfigNameDictionaryEntityData() {
252 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
254 MockHttpServletResponse response = new MockHttpServletResponse();
256 controller.getMicroServiceConfigNameDictionaryEntityData(response);
259 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
260 logger.info("response.getContentAsString(): " + response.getContentAsString());
261 } catch (UnsupportedEncodingException e) {
262 fail("Exception: " + e);
265 logger.info("testGetMicroServiceConfigNameDictionaryEntityData: exit");
269 public void testSaveMicroServiceConfigNameDictionary() {
270 logger.info("testSaveMicroServiceConfigNameDictionary: Entering");
272 MockHttpServletResponse response = new MockHttpServletResponse();
273 request = mock(HttpServletRequest.class);
276 // mock the getReader() call
277 jsonString = "{\"microServiceCongigNameDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
278 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
279 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
280 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
281 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
282 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
283 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
284 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
285 BufferedReader br = new BufferedReader(new StringReader(jsonString));
286 when(request.getReader()).thenReturn(br);
287 controller.saveMicroServiceConfigNameDictionary(request, response);
288 logger.info("response.getContentAsString(): " + response.getContentAsString());
289 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
291 } catch (Exception e) {
292 fail("Exception: " + e);
295 logger.info("testSaveMicroServiceConfigNameDictionary: exit");
299 public void testRemoveMicroServiceConfigNameDictionary() {
300 logger.info("testRemoveMicroServiceConfigNameDictionary: Entering");
302 MockHttpServletResponse response = new MockHttpServletResponse();
303 request = mock(HttpServletRequest.class);
306 // mock the getReader() call
307 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
308 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
309 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
310 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
311 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
312 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
313 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
314 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
315 BufferedReader br = new BufferedReader(new StringReader(jsonString));
316 when(request.getReader()).thenReturn(br);
317 controller.removeMicroServiceConfigNameDictionary(request, response);
318 logger.info("response.getContentAsString(): " + response.getContentAsString());
319 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceCongigNameDictionaryDatas"));
321 } catch (Exception e) {
322 fail("Exception: " + e);
325 logger.info("testRemoveMicroServiceConfigNameDictionary: exit");
329 public void testGetMicroServiceLocationByNameDictionaryEntityData() {
331 logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: Entering");
333 MockHttpServletResponse response = new MockHttpServletResponse();
335 controller.getMicroServiceLocationByNameDictionaryEntityData(response);
338 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
339 logger.info("response.getContentAsString(): " + response.getContentAsString());
340 } catch (UnsupportedEncodingException e) {
341 fail("Exception: " + e);
344 logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: exit");
348 public void testGetMicroServiceLocationDictionaryEntityData() {
349 logger.info("testGetMicroServiceLocationDictionaryEntityData: Entering");
351 MockHttpServletResponse response = new MockHttpServletResponse();
353 controller.getMicroServiceLocationDictionaryEntityData(response);
356 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
357 logger.info("response.getContentAsString(): " + response.getContentAsString());
358 } catch (UnsupportedEncodingException e) {
359 fail("Exception: " + e);
362 logger.info("testGetMicroServiceLocationDictionaryEntityData: exit");
366 public void testSaveMicroServiceLocationDictionary() {
367 logger.info("testSaveMicroServiceLocationDictionary: Entering");
369 MockHttpServletResponse response = new MockHttpServletResponse();
370 request = mock(HttpServletRequest.class);
373 // mock the getReader() call
374 jsonString = "{\"microServiceLocationDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
375 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
376 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
377 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
378 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
379 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
380 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
381 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
382 BufferedReader br = new BufferedReader(new StringReader(jsonString));
383 when(request.getReader()).thenReturn(br);
384 controller.saveMicroServiceLocationDictionary(request, response);
385 logger.info("response.getContentAsString(): " + response.getContentAsString());
386 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
388 } catch (Exception e) {
389 fail("Exception: " + e);
392 logger.info("testSaveMicroServiceLocationDictionary: exit");
396 public void testRemoveMicroServiceLocationDictionary() {
397 logger.info("testRemoveMicroServiceLocationDictionary: Entering");
399 MockHttpServletResponse response = new MockHttpServletResponse();
400 request = mock(HttpServletRequest.class);
403 // mock the getReader() call
404 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
405 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
406 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
407 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
408 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
409 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
410 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
411 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
412 BufferedReader br = new BufferedReader(new StringReader(jsonString));
414 when(request.getReader()).thenReturn(br);
415 controller.removeMicroServiceLocationDictionary(request, response);
416 logger.info("response.getContentAsString(): " + response.getContentAsString());
417 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
419 } catch (Exception e) {
420 fail("Exception: " + e);
423 logger.info("testRemoveMicroServiceLocationDictionary: exit");
427 public void testGetMicroServiceAttributeByNameDictionaryEntityData() {
428 logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: Entering");
430 MockHttpServletResponse response = new MockHttpServletResponse();
432 controller.getMicroServiceAttributeByNameDictionaryEntityData(response);
435 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
436 logger.info("response.getContentAsString(): " + response.getContentAsString());
437 } catch (UnsupportedEncodingException e) {
438 fail("Exception: " + e);
441 logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: exit");
445 public void testGetMicroServiceAttributeDictionaryEntityData() {
446 logger.info("testGetMicroServiceAttributeDictionaryEntityData: Entering");
448 MockHttpServletResponse response = new MockHttpServletResponse();
450 controller.getMicroServiceAttributeDictionaryEntityData(response);
453 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
454 logger.info("response.getContentAsString(): " + response.getContentAsString());
455 } catch (UnsupportedEncodingException e) {
456 fail("Exception: " + e);
459 logger.info("testGetMicroServiceAttributeDictionaryEntityData: exit");
463 public void testSaveMicroServiceAttributeDictionary() {
464 logger.info("testSaveMicroServiceAttributeDictionary: Entering");
466 MockHttpServletResponse response = new MockHttpServletResponse();
467 request = mock(HttpServletRequest.class);
470 // mock the getReader() call
471 jsonString = "{\"modelAttributeDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
472 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
473 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
474 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
475 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
476 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
477 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
478 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
479 BufferedReader br = new BufferedReader(new StringReader(jsonString));
480 when(request.getReader()).thenReturn(br);
481 controller.saveMicroServiceAttributeDictionary(request, response);
482 logger.info("response.getContentAsString(): " + response.getContentAsString());
483 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
485 } catch (Exception e) {
486 fail("Exception: " + e);
489 logger.info("testSaveMicroServiceAttributeDictionary: exit");
493 public void testRemoveMicroServiceAttributeDictionary() {
494 logger.info("testRemoveMicroServiceAttributeDictionary: Entering");
496 MockHttpServletResponse response = new MockHttpServletResponse();
497 request = mock(HttpServletRequest.class);
500 // mock the getReader() call
501 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
502 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
503 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
504 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
505 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
506 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
507 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
508 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
509 BufferedReader br = new BufferedReader(new StringReader(jsonString));
510 when(request.getReader()).thenReturn(br);
511 controller.removeMicroServiceAttributeDictionary(request, response);
512 logger.info("response.getContentAsString(): " + response.getContentAsString());
513 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
515 } catch (Exception e) {
516 fail("Exception: " + e);
519 logger.info("testRemoveMicroServiceAttributeDictionary: exit");
523 public void testGetMicroServiceModelsDictionaryByNameEntityData() {
524 logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: Entering");
526 MockHttpServletResponse response = new MockHttpServletResponse();
528 controller.getMicroServiceModelsDictionaryByNameEntityData(response);
531 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
532 logger.info("response.getContentAsString(): " + response.getContentAsString());
533 } catch (UnsupportedEncodingException e) {
534 fail("Exception: " + e);
537 logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: exit");
541 public void testGetMicroServiceModelsDictionaryByVersionEntityData() {
542 logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: Entering");
544 MockHttpServletResponse response = new MockHttpServletResponse();
545 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
547 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
548 request = mock(HttpServletRequest.class);
551 // mock the getReader() call
552 when(request.getReader()).thenReturn(br);
553 controller.getMicroServiceModelsDictionaryByVersionEntityData(request, response);
554 logger.info("response.getContentAsString(): " + response.getContentAsString());
555 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("No model name given"));
557 } catch (Exception e) {
558 fail("Exception: " + e);
561 logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: exit");
565 public void testGetMicroServiceModelsDictionaryEntityData() {
566 logger.info("testGetMicroServiceModelsDictionaryEntityData: Entering");
568 MockHttpServletResponse response = new MockHttpServletResponse();
569 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
571 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
572 request = mock(HttpServletRequest.class);
575 // mock the getReader() call
576 when(request.getReader()).thenReturn(br);
577 controller.getMicroServiceModelsDictionaryEntityData(response);
578 logger.info("response.getContentAsString(): " + response.getContentAsString());
579 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
581 } catch (Exception e) {
582 fail("Exception: " + e);
585 logger.info("testGetMicroServiceModelsDictionaryEntityData: exit");
589 public void testGetMicroServiceModelsDictionaryEntityDataServiceVersion() {
590 logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: Entering");
592 MockHttpServletResponse response = new MockHttpServletResponse();
593 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
595 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
596 request = mock(HttpServletRequest.class);
599 // mock the getReader() call
600 when(request.getReader()).thenReturn(br);
601 controller.getMicroServiceModelsDictionaryEntityDataServiceVersion(response);
602 logger.info("response.getContentAsString(): " + response.getContentAsString());
603 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
605 } catch (Exception e) {
606 fail("Exception: " + e);
609 logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: exit");
613 public void testGetMicroServiceModelsDictionaryClassEntityData() {
614 logger.info("testGetMicroServiceModelsDictionaryClassEntityData: Entering");
616 MockHttpServletResponse response = new MockHttpServletResponse();
617 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
619 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
620 request = mock(HttpServletRequest.class);
623 // mock the getReader() call
624 when(request.getReader()).thenReturn(br);
625 controller.getMicroServiceModelsDictionaryClassEntityData(response);
626 logger.info("response.getContentAsString(): " + response.getContentAsString());
627 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryClassDatas"));
629 } catch (Exception e) {
630 fail("Exception: " + e);
633 logger.info("testGetMicroServiceModelsDictionaryClassEntityData: exit");
637 public void testSaveMicroServiceModelsDictionary() {
638 logger.info("testSaveMicroServiceModelsDictionary: Entering");
640 MockHttpServletResponse response = new MockHttpServletResponse();
641 request = mock(HttpServletRequest.class);
644 // mock the getReader() call
645 when(request.getReader()).thenReturn(br);
646 controller.saveMicroServiceModelsDictionary(request, response);
647 logger.info("response.getContentAsString(): " + response.getContentAsString());
648 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
650 } catch (Exception e) {
651 fail("Exception: " + e);
654 logger.info("testSaveMicroServiceModelsDictionary: exit");
658 public void testRemoveMicroServiceModelsDictionary() {
659 logger.info("testRemoveMicroServiceModelsDictionary: Entering");
661 MockHttpServletResponse response = new MockHttpServletResponse();
662 request = mock(HttpServletRequest.class);
665 // mock the getReader() call
666 jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
667 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
668 + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
669 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
670 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
671 + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
672 + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
673 + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
675 BufferedReader br = new BufferedReader(new StringReader(jsonString));
676 when(request.getReader()).thenReturn(br);
677 controller.removeMicroServiceModelsDictionary(request, response);
678 logger.info("response.getContentAsString(): " + response.getContentAsString());
679 assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
681 } catch (Exception e) {
682 fail("Exception: " + e);
685 logger.info("testRemoveMicroServiceModelsDictionary: exit");