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