Code Clean Up for Policy PAP-REST
[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  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21
22 package org.onap.policy.pap.xacml.rest.controller;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.doNothing;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29
30 import java.io.BufferedReader;
31 import java.io.StringReader;
32 import java.io.UnsupportedEncodingException;
33 import java.util.ArrayList;
34 import java.util.List;
35
36 import javax.servlet.http.HttpServletRequest;
37
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.mockito.Mockito;
41 import org.onap.policy.common.logging.flexlogger.FlexLogger;
42 import org.onap.policy.common.logging.flexlogger.Logger;
43 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
44 import org.onap.policy.rest.dao.CommonClassDao;
45 import org.onap.policy.rest.jpa.DCAEuuid;
46 import org.onap.policy.rest.jpa.MicroServiceLocation;
47 import org.onap.policy.rest.jpa.MicroServiceModels;
48 import org.onap.policy.rest.jpa.UserInfo;
49 import org.springframework.mock.web.MockHttpServletResponse;
50
51 /**
52  * The class <code>MicroServiceDictionaryControllerTest</code> contains tests
53  * for the class {@link <code>MicroServiceDictionaryController</code>}*
54  *
55  * All JUnits are designed to run in the local development environment
56  * where they have write privileges and can execute time-sensitive
57  * 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,\"model\": {\"name\": \"testingdata\", "
100                                 + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
101                                 + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
102                                 + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
103                                 + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
104                                 + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
105                                 + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
106                                 + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
107     
108         br = new BufferedReader(new StringReader(jsonString));
109         //--- mock the getReader() call
110         when(request.getReader()).thenReturn(br);   
111         new DictionaryUtils(commonClassDao);
112         DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
113         mock(DictionaryUtils.class);        
114         logger.info("setUp: exit");
115         }
116
117
118         @Test
119         public void testGetDCAEUUIDDictionaryByNameEntityData() {
120                 
121                 logger.info("testGetDCAEUUIDDictionaryByNameEntityData: Entering");
122
123                 MockHttpServletResponse response =  new MockHttpServletResponse();
124
125                 controller.getDCAEUUIDDictionaryByNameEntityData(response);
126                 
127                 try {
128                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
129                         logger.info("response.getContentAsString(): " + response.getContentAsString());
130                 } catch (UnsupportedEncodingException e) {
131                         fail("Exception: " + e);
132                 }
133                 
134                 logger.info("testGetDCAEUUIDDictionaryByNameEntityData: exit");
135         }
136
137         @Test
138         public void testGetDCAEUUIDDictionaryEntityData() {
139                 
140                 logger.info("testGetDCAEUUIDDictionaryEntityData: Entering");
141
142                 MockHttpServletResponse response =  new MockHttpServletResponse();
143                 
144                 controller.getDCAEUUIDDictionaryEntityData(response);
145                 
146                 try {
147                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
148                         logger.info("response.getContentAsString(): " + response.getContentAsString());
149                 } catch (UnsupportedEncodingException e) {
150                         fail("Exception: " + e);
151                 }
152                 
153                 logger.info("testGetDCAEUUIDDictionaryEntityData: exit");
154         }
155
156         @Test
157         public void testSaveDCAEUUIDDictionary() {
158                 logger.info("testSaveDCAEUUIDDictionary: Entering");
159
160                 MockHttpServletResponse response =  new MockHttpServletResponse();
161             request = mock(HttpServletRequest.class);   
162         
163                 try {
164                     // mock the getReader() call
165                         jsonString = "{\"dcaeUUIDDictionaryData\": {\"modelName\": \"test\",    \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
166                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
167                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
168                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
169                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
170                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
171                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
172                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
173                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
174                         when(request.getReader()).thenReturn(br);                   
175                         controller.saveDCAEUUIDDictionary(request, response);
176                         logger.info("response.getContentAsString(): " + response.getContentAsString());
177                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
178
179                 } catch (Exception e) {
180                         fail("Exception: " + e);
181                 }
182                 
183                 logger.info("testSaveDCAEUUIDDictionary: exit");
184         }
185
186         @Test
187         public void testRemoveDCAEUUIDDictionary() {
188                 logger.info("testRemoveDCAEUUIDDictionary: Entering");
189
190                 MockHttpServletResponse response =  new MockHttpServletResponse();
191             request = mock(HttpServletRequest.class);   
192         
193                 try {
194                     // mock the getReader() call
195                         jsonString = "{\"data\": {\"modelName\": \"test\",      \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
196                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
197                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
198                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
199                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
200                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
201                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
202                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
203                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
204                         when(request.getReader()).thenReturn(br);                   
205                         controller.removeMicroServiceConfigNameDictionary(request, response);
206                         logger.info("response.getContentAsString(): " + response.getContentAsString());
207                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
208
209                 } catch (Exception e) {
210                         fail("Exception: " + e);
211                 }
212                 
213                 logger.info("testRemoveDCAEUUIDDictionary: exit");
214         }
215
216         @Test
217         public void testGetMicroServiceConfigNameByNameDictionaryEntityData() {
218                 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
219
220                 MockHttpServletResponse response =  new MockHttpServletResponse();
221                 
222                 controller.getMicroServiceConfigNameByNameDictionaryEntityData(response);
223                 
224                 try {
225                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
226                         logger.info("response.getContentAsString(): " + response.getContentAsString());
227                 } catch (UnsupportedEncodingException e) {
228                         fail("Exception: " + e);
229                 }
230                 
231                 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: exit");
232         }
233
234         @Test
235         public void testGetMicroServiceConfigNameDictionaryEntityData() {
236                 logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
237
238                 MockHttpServletResponse response =  new MockHttpServletResponse();
239                 
240                 controller.getMicroServiceConfigNameDictionaryEntityData(response);
241                 
242                 try {
243                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
244                         logger.info("response.getContentAsString(): " + response.getContentAsString());
245                 } catch (UnsupportedEncodingException e) {
246                         fail("Exception: " + e);
247                 }
248                 
249                 logger.info("testGetMicroServiceConfigNameDictionaryEntityData: exit");
250         }
251
252         @Test
253         public void testSaveMicroServiceConfigNameDictionary() {
254                 logger.info("testSaveMicroServiceConfigNameDictionary: Entering");
255
256                 MockHttpServletResponse response =  new MockHttpServletResponse();
257             request = mock(HttpServletRequest.class);   
258         
259                 try {
260                     // mock the getReader() call
261                         jsonString = "{\"microServiceConfigNameDictionaryData\": {\"modelName\": \"test\",      \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
262                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
263                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
264                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
265                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
266                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
267                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
268                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
269                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
270                         when(request.getReader()).thenReturn(br);                   
271                         controller.saveMicroServiceConfigNameDictionary(request, response);
272                         logger.info("response.getContentAsString(): " + response.getContentAsString());
273                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
274
275                 } catch (Exception e) {
276                         fail("Exception: " + e);
277                 }
278                 
279                 logger.info("testSaveMicroServiceConfigNameDictionary: exit");
280         }
281
282         @Test
283         public void testRemoveMicroServiceConfigNameDictionary() {
284                 logger.info("testRemoveMicroServiceConfigNameDictionary: Entering");
285
286                 MockHttpServletResponse response =  new MockHttpServletResponse();
287             request = mock(HttpServletRequest.class);   
288         
289                 try {
290                     // mock the getReader() call
291                         jsonString = "{\"data\": {\"modelName\": \"test\",      \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
292                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
293                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
294                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
295                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
296                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
297                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
298                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
299                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
300                         when(request.getReader()).thenReturn(br);                   
301                         controller.removeMicroServiceConfigNameDictionary(request, response);
302                         logger.info("response.getContentAsString(): " + response.getContentAsString());
303                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
304
305                 } catch (Exception e) {
306                         fail("Exception: " + e);
307                 }
308                 
309                 logger.info("testRemoveMicroServiceConfigNameDictionary: exit");
310         }
311
312         @Test
313         public void testGetMicroServiceLocationByNameDictionaryEntityData() {
314                 
315                 logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: Entering");
316
317                 MockHttpServletResponse response =  new MockHttpServletResponse();
318                 
319                 controller.getMicroServiceLocationByNameDictionaryEntityData(response);
320                 
321                 try {
322                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
323                         logger.info("response.getContentAsString(): " + response.getContentAsString());
324                 } catch (UnsupportedEncodingException e) {
325                         fail("Exception: " + e);
326                 }
327                 
328                 logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: exit");
329         }
330
331         @Test
332         public void testGetMicroServiceLocationDictionaryEntityData() {
333                 logger.info("testGetMicroServiceLocationDictionaryEntityData: Entering");
334
335                 MockHttpServletResponse response =  new MockHttpServletResponse();
336                 
337                 controller.getMicroServiceLocationDictionaryEntityData(response);
338                 
339                 try {
340                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
341                         logger.info("response.getContentAsString(): " + response.getContentAsString());
342                 } catch (UnsupportedEncodingException e) {
343                         fail("Exception: " + e);
344                 }
345                 
346                 logger.info("testGetMicroServiceLocationDictionaryEntityData: exit");
347         }
348
349         @Test
350         public void testSaveMicroServiceLocationDictionary() {
351                 logger.info("testSaveMicroServiceLocationDictionary: Entering");
352
353                 MockHttpServletResponse response =  new MockHttpServletResponse();
354             request = mock(HttpServletRequest.class);   
355         
356                 try {
357                     // mock the getReader() call
358                         jsonString = "{\"microServiceLocationDictionaryData\": {\"modelName\": \"test\",        \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
359                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
360                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
361                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
362                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
363                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
364                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
365                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
366                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
367                         when(request.getReader()).thenReturn(br);                   
368                         controller.saveMicroServiceLocationDictionary(request, response);
369                         logger.info("response.getContentAsString(): " + response.getContentAsString());
370                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
371
372                 } catch (Exception e) {
373                         fail("Exception: " + e);
374                 }
375                 
376                 logger.info("testSaveMicroServiceLocationDictionary: exit");
377         }
378
379         @Test
380         public void testRemoveMicroServiceLocationDictionary() {
381                 logger.info("testRemoveMicroServiceLocationDictionary: Entering");
382
383                 MockHttpServletResponse response =  new MockHttpServletResponse();
384             request = mock(HttpServletRequest.class);   
385         
386                 try {
387                     // mock the getReader() call
388                         jsonString = "{\"data\": {\"modelName\": \"test\",      \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
389                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
390                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
391                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
392                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
393                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
394                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
395                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
396                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
397
398                         when(request.getReader()).thenReturn(br);                   
399                         controller.removeMicroServiceLocationDictionary(request, response);
400                         logger.info("response.getContentAsString(): " + response.getContentAsString());
401                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
402
403                 } catch (Exception e) {
404                         fail("Exception: " + e);
405                 }
406                 
407                 logger.info("testRemoveMicroServiceLocationDictionary: exit");
408         }
409
410         @Test
411         public void testGetMicroServiceAttributeByNameDictionaryEntityData() {
412                 logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: Entering");
413
414                 MockHttpServletResponse response =  new MockHttpServletResponse();
415                 
416                 controller.getMicroServiceAttributeByNameDictionaryEntityData(response);
417                 
418                 try {
419                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
420                         logger.info("response.getContentAsString(): " + response.getContentAsString());
421                 } catch (UnsupportedEncodingException e) {
422                         fail("Exception: " + e);
423                 }
424                 
425                 logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: exit");
426         }
427
428         @Test
429         public void testGetMicroServiceAttributeDictionaryEntityData() {
430                 logger.info("testGetMicroServiceAttributeDictionaryEntityData: Entering");
431
432                 MockHttpServletResponse response =  new MockHttpServletResponse();
433                 
434                 controller.getMicroServiceAttributeDictionaryEntityData(response);
435                 
436                 try {
437                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
438                         logger.info("response.getContentAsString(): " + response.getContentAsString());
439                 } catch (UnsupportedEncodingException e) {
440                         fail("Exception: " + e);
441                 }
442                 
443                 logger.info("testGetMicroServiceAttributeDictionaryEntityData: exit");
444         }
445
446         @Test
447         public void testSaveMicroServiceAttributeDictionary() {
448                 logger.info("testSaveMicroServiceAttributeDictionary: Entering");
449
450                 MockHttpServletResponse response =  new MockHttpServletResponse();
451             request = mock(HttpServletRequest.class);   
452         
453                 try {
454                     // mock the getReader() call
455                         jsonString = "{\"modelAttributeDictionaryData\": {\"modelName\": \"test\",      \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
456                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
457                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
458                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
459                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
460                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
461                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
462                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
463                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
464                         when(request.getReader()).thenReturn(br);                   
465                         controller.saveMicroServiceAttributeDictionary(request, response);
466                         logger.info("response.getContentAsString(): " + response.getContentAsString());
467                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
468
469                 } catch (Exception e) {
470                         fail("Exception: " + e);
471                 }
472                 
473                 logger.info("testSaveMicroServiceAttributeDictionary: exit");
474         }
475
476         @Test
477         public void testRemoveMicroServiceAttributeDictionary() {
478                 logger.info("testRemoveMicroServiceAttributeDictionary: Entering");
479
480                 MockHttpServletResponse response =  new MockHttpServletResponse();
481             request = mock(HttpServletRequest.class);   
482         
483                 try {
484                     // mock the getReader() call
485                         jsonString = "{\"data\": {\"modelName\": \"test\",      \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
486                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
487                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
488                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
489                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
490                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
491                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
492                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
493                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
494                         when(request.getReader()).thenReturn(br);                   
495                         controller.removeMicroServiceAttributeDictionary(request, response);
496                         logger.info("response.getContentAsString(): " + response.getContentAsString());
497                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
498
499                 } catch (Exception e) {
500                         fail("Exception: " + e);
501                 }
502                 
503                 logger.info("testRemoveMicroServiceAttributeDictionary: exit");
504         }
505
506         @Test
507         public void testGetMicroServiceModelsDictionaryByNameEntityData() {
508                 logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: Entering");
509
510                 MockHttpServletResponse response =  new MockHttpServletResponse();
511                 
512                 controller.getMicroServiceModelsDictionaryByNameEntityData(response);
513                 
514                 try {
515                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
516                         logger.info("response.getContentAsString(): " + response.getContentAsString());
517                 } catch (UnsupportedEncodingException e) {
518                         fail("Exception: " + e);
519                 }
520                 
521                 logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: exit");
522         }
523
524         @Test
525         public void testGetMicroServiceModelsDictionaryByVersionEntityData() {
526                 logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: Entering");
527
528                 MockHttpServletResponse response =  new MockHttpServletResponse();
529                 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
530                 
531             BufferedReader br = new BufferedReader(new StringReader(msModelJson));
532             request = mock(HttpServletRequest.class);   
533         
534                 try {
535                     // mock the getReader() call
536                         when(request.getReader()).thenReturn(br);                   
537                         controller.getMicroServiceModelsDictionaryByVersionEntityData(request, response);
538                         logger.info("response.getContentAsString(): " + response.getContentAsString());
539                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("No model name given"));
540
541                 } catch (Exception e) {
542                         fail("Exception: " + e);
543                 }
544                 
545                 logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: exit");
546         }
547
548         @Test
549         public void testGetMicroServiceModelsDictionaryEntityData() {
550                 logger.info("testGetMicroServiceModelsDictionaryEntityData: Entering");
551
552                 MockHttpServletResponse response =  new MockHttpServletResponse();
553                 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
554                 
555             BufferedReader br = new BufferedReader(new StringReader(msModelJson));
556             request = mock(HttpServletRequest.class);   
557         
558                 try {
559                     // mock the getReader() call
560                         when(request.getReader()).thenReturn(br);                   
561                         controller.getMicroServiceModelsDictionaryEntityData(response);
562                         logger.info("response.getContentAsString(): " + response.getContentAsString());
563                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
564
565                 } catch (Exception e) {
566                         fail("Exception: " + e);
567                 }
568                 
569                 logger.info("testGetMicroServiceModelsDictionaryEntityData: exit");
570         }
571
572         @Test
573         public void testGetMicroServiceModelsDictionaryEntityDataServiceVersion() {
574                 logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: Entering");
575
576                 MockHttpServletResponse response =  new MockHttpServletResponse();
577                 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
578                 
579             BufferedReader br = new BufferedReader(new StringReader(msModelJson));
580             request = mock(HttpServletRequest.class);   
581         
582                 try {
583                     // mock the getReader() call
584                         when(request.getReader()).thenReturn(br);                   
585                         controller.getMicroServiceModelsDictionaryEntityDataServiceVersion(response);
586                         logger.info("response.getContentAsString(): " + response.getContentAsString());
587                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
588
589                 } catch (Exception e) {
590                         fail("Exception: " + e);
591                 }
592                 
593                 logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: exit");
594         }
595
596         @Test
597         public void testGetMicroServiceModelsDictionaryClassEntityData() {
598                 logger.info("testGetMicroServiceModelsDictionaryClassEntityData: Entering");
599
600                 MockHttpServletResponse response =  new MockHttpServletResponse();
601                 String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
602                 
603             BufferedReader br = new BufferedReader(new StringReader(msModelJson));
604             request = mock(HttpServletRequest.class);   
605         
606                 try {
607                     // mock the getReader() call
608                         when(request.getReader()).thenReturn(br);                   
609                         controller.getMicroServiceModelsDictionaryClassEntityData(response);
610                         logger.info("response.getContentAsString(): " + response.getContentAsString());
611                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryClassDatas"));
612
613                 } catch (Exception e) {
614                         fail("Exception: " + e);
615                 }
616                 
617                 logger.info("testGetMicroServiceModelsDictionaryClassEntityData: exit");
618         }
619
620         @Test
621         public void testSaveMicroServiceModelsDictionary() {
622                 logger.info("testSaveMicroServiceModelsDictionary: Entering");
623
624                 MockHttpServletResponse response =  new MockHttpServletResponse();
625             request = mock(HttpServletRequest.class);   
626         
627                 try {
628                     // mock the getReader() call
629                         when(request.getReader()).thenReturn(br);                   
630                         controller.saveMicroServiceModelsDictionary(request, response);
631                         logger.info("response.getContentAsString(): " + response.getContentAsString());
632                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
633
634                 } catch (Exception e) {
635                         fail("Exception: " + e);
636                 }
637                 
638                 logger.info("testSaveMicroServiceModelsDictionary: exit");
639         }
640
641         @Test
642         public void testRemoveMicroServiceModelsDictionary() {
643                 logger.info("testRemoveMicroServiceModelsDictionary: Entering");
644
645                 MockHttpServletResponse response =  new MockHttpServletResponse();
646             request = mock(HttpServletRequest.class);   
647         
648                 try {
649                     // mock the getReader() call
650                         jsonString = "{\"data\": {\"modelName\": \"test\",      \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
651                                         + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
652                                         + " \"version\": \"\",\"createdBy\": \"someone\",       \"modifiedBy\": \"someone\",    \"content\": \"\",\"recursive\": false},"
653                                         + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"    },"
654                                         + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
655                                         + "     \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
656                                         + "     \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
657                                         + "     \"policyJSON\": {\"pmTableName\": \"test\",     \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
658                         
659                         BufferedReader br = new BufferedReader(new StringReader(jsonString));
660                         when(request.getReader()).thenReturn(br);                   
661                         controller.removeMicroServiceModelsDictionary(request, response);
662                         logger.info("response.getContentAsString(): " + response.getContentAsString());
663                         assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
664
665                 } catch (Exception e) {
666                         fail("Exception: " + e);
667                 }
668                 
669                 logger.info("testRemoveMicroServiceModelsDictionary: exit");
670         }
671
672 }