Update css file name in conf.py
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / controller / CreateDcaeMicroServiceControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.controller;
24
25 import static org.easymock.EasyMock.createMock;
26 import static org.easymock.EasyMock.expect;
27 import static org.easymock.EasyMock.replay;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33 import com.fasterxml.jackson.databind.DeserializationFeature;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.github.fge.jackson.JsonLoader;
37 import java.io.BufferedReader;
38 import java.io.File;
39 import java.io.FileInputStream;
40 import java.io.IOException;
41 import java.io.InputStream;
42 import java.io.StringReader;
43 import java.util.ArrayList;
44 import java.util.HashMap;
45 import java.util.LinkedList;
46 import java.util.List;
47 import java.util.Map;
48 import javax.servlet.ReadListener;
49 import javax.servlet.ServletInputStream;
50 import javax.servlet.http.HttpServletRequest;
51 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
52 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
53 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
54 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
55 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
56 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
58 import org.junit.Before;
59 import org.junit.Test;
60 import org.onap.policy.common.logging.flexlogger.FlexLogger;
61 import org.onap.policy.common.logging.flexlogger.Logger;
62 import org.onap.policy.rest.adapter.PolicyRestAdapter;
63 import org.onap.policy.rest.dao.CommonClassDao;
64 import org.onap.policy.rest.jpa.ConfigurationDataEntity;
65 import org.onap.policy.rest.jpa.MicroServiceModels;
66 import org.onap.policy.rest.jpa.PolicyEntity;
67 import org.springframework.mock.web.MockHttpServletRequest;
68 import org.springframework.mock.web.MockHttpServletResponse;
69
70 /**
71  * The class <code>CreateDcaeMicroServiceControllerTest</code> contains tests for the class
72  *
73  * <p/>All JUnits are designed to run in the local development environment where they have write privileges
74  * and can execute time-sensitive tasks.
75  *
76  */
77
78 public class CreateDcaeMicroServiceControllerTest {
79
80     private static Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceControllerTest.class);
81     private static CommonClassDao commonClassDao;
82     private String jsonString = null;
83     private String configBodyString = null;
84     private HttpServletRequest request = null;
85
86     /**
87      * setUp.
88      *
89      * @throws Exception should not throw one
90      */
91     @Before
92     public void setUp() throws Exception {
93         logger.info("setUp: Entering");
94         commonClassDao = mock(CommonClassDao.class);
95         MicroServiceModels testData = new MicroServiceModels();
96         testData.setVersion("OpenOnap-Junit");
97         testData.setModelName("modelName");
98         testData.setRuleFormation("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, "
99                 + "Contains, FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
100                 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
101         testData.setAttributes(
102                 "ParentCorrelation Name=String:defaultValue-null:required-true:MANY-false:description-null,"
103                         + "CorrelationWindow=String:defaultValue-null:required-true:MANY-false:description-null,"
104                         + "EmailNotification=String:defaultValue-null:required-true:MANY-false:description-null,"
105                         + "CorrelationPriority=string:defaultValue-null:required-true:MANY-false:description-null,");
106         testData.setRefAttributes("SymptomTriggerSignature=resource-model-symptomEntity:MANY-true:description-null,"
107                 + "triggerSignature=resource-model-entity:MANY-true:description-null,"
108                 + "SelectServerScope=SELECTSERVERSCOPE:MANY-false,logicalConnector=LOGICALCONNECTOR:MANY-false,"
109                 + "ParentCorrelationTraversal=PARENTCORRELATIONTRAVERSAL:MANY-false,");
110         testData.setSubAttributes(
111                 "{\"symptomAlarms\":{\"symptomContains\":\"SYMPTOMCONTAINS:defaultValue-null:required-true:MANY-false:"
112                         + "description-null\",\"symptomFilterValue\":\"string:defaultValue-null:"
113                         + "required-true:MANY-false:"
114                         + "description-null\",\"symptomVnfType\":\"SYMPTOMVNFTYPE:defaultValue-null:"
115                         + "required-true:MANY-false:"
116                         + "description-null\"},\"symptomElement\":{\"symptomSignatures\":\"symptomRange:required-true:"
117                         + "MANY-true:description-null\",\"symptomTraversal\":\"SYMPTOMTRAVERSAL:defaultValue-null:"
118                         + "required-true:MANY-false:description-null\"},\"alarms\":{\"Contains\":\"CONTAINS:"
119                         + "defaultValue-null:required-true:MANY-false:description-null\",\"VnfType\":\"VNFTYPE:"
120                         + "defaultValue-null:required-true:MANY-false:description-null\",\"FilterValue\":\"string:"
121                         + "defaultValue-null:required-true:MANY-false:description-null\"},\"resource-model-entity\":"
122                         + "{\"signaturesAlarm\":\"element:required-false:MANY-false:description-null\"},\"range\":"
123                         + "{\"alarmSignature\":\"alarms:required-true:MANY-false:description-null\"},\"symptomRange\":"
124                         + "{\"symptomSignature\":\"symptomAlarms:required-true:MANY-false:description-null\"},"
125                         + "\"element\":"
126                         + "{\"alarmSignatures\":\"range:required-true:MANY-true:description-null\",\"traversal\":"
127                         + "\"TRAVERSAL:" + "defaultValue-null:required-true:MANY-false:description-null\"},"
128                         + "\"resource-model-symptomEntity\":"
129                         + "{\"signaturesSymptom\":\"symptomElement:required-false:MANY-false:description-null\"}}");
130         testData.setAnnotation(
131                 "alarmSignatures=matching-true, symptomContains=matching-true, symptomSignatures=matching-true, "
132                         + "symptomTraversal=matching-true, symptomVnfType=matching-true, Contains=matching-true, "
133                         + "SelectServerScope=matching-true, VnfType=matching-true, traversal=matching-true, "
134                         + "logicalConnector=matching-true, ParentCorrelationTraversal=matching-true");
135         testData.setEnumValues("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
136                 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures.symptomSignature"
137                 + "[symptomVnfType, symptomContains, symptomFilterValue]");
138         testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
139                 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
140                 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
141         List<Object> microServiceModelsData = new ArrayList<Object>();
142         microServiceModelsData.add(testData);
143
144         // mock the getDataById() call
145         when(commonClassDao.getDataById(MicroServiceModels.class, "modelName:version", "TESTMODEL" + ":" + "TODAY"))
146                 .thenReturn(microServiceModelsData);
147
148         jsonString = "{\"policyData\":{\"error\":\"\",\"inprocess\":false,\"model\":{\"name\":\"DCAE\","
149                 + "\"subScopename\":\"\",\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":"
150                 + "\"2019-02-26 09:56:23.0\",\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":"
151                 + "\"\",\"createdBy\":\"super-admin\",\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\","
152                 + "\"content\":\"\",\"recursive\":false},\"tempModel\":{\"name\":\"DCAE\",\"subScopename\":\"\","
153                 + "\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":\"2019-02-26 09:56:23.0\","
154                 + "\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":\"\",\"createdBy\":\"super-admin\","
155                 + "\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\",\"content\":\"\","
156                 + "\"recursive\":false},\"$$hashKey\":\"object:354\",\"policy\":{\"policyType\":\"Config\","
157                 + "\"configPolicyType\":\"Micro Service\",\"serviceType\":\"TESTMODEL\",\"version\":\"TODAY\","
158                 + "\"ruleGridData\":[\"Correlation Priority\",\"Correlation Window\","
159                 + "\"Email Notification for failures\",\"Select Server Scope\","
160                 + "\"Parent Correlation Name\",\"Parent Correlation Traversal\","
161                 + "\"traversal\",\"FilterValue\"],\"policyName\":\"testttt\",\"onapName\":"
162                 + "\"asdafadf\",\"guard\":\"True\",\"riskType\":\"sfsgs\",\"riskLevel\":\"1\","
163                 + "\"priority\":\"1\",\"configName\":\"Search\",\"location\":\"Search\","
164                 + "\"uuid\":\"Search\",\"policyScope\":\"PolicyScope_ssaaa123\"}},"
165                 + "\"policyJSON\":{\"DCAEProcessingRules@0.processingRules_json\":"
166                 + "\"eyJuYW1lIjogIkpvaG4iLCAiYWdlIjogIjI4IiwgImNpdHkiOiAiTmV3IFlvcmsifQ==\"}}";
167
168         configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\","
169                 + "\"templateVersion\":\"1607\",\"version\":\"HD\",\"priority\":\"2\","
170                 + "\"content\":{\"lastPolled\":\"1\",\"boolen-test\":\"true\",\"created\":\"test\","
171                 + "\"retiredDate\":\"test\",\"scope\":\"SNIRO_PLACEMENT_VDHV\",\"name\":\"test\","
172                 + "\"lastModified\":\"test\",\"state\":\"CREATED\",\"type\":\"CONFIG\",\"intent\":\"test\","
173                 + "\"target\":\"SNIRO\"}}";
174
175         request = mock(HttpServletRequest.class);
176         BufferedReader br = new BufferedReader(new StringReader(jsonString));
177         // mock the getReader() call
178         when(request.getReader()).thenReturn(br);
179
180         logger.info("setUp: exit");
181     }
182
183     /**
184      * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test.
185      */
186
187     @Test
188     public void testSetDataToPolicyRestAdapter() {
189
190         logger.debug("testSetDataToPolicyRestAdapter: enter");
191
192         CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
193
194         JsonNode root = null;
195         ObjectMapper mapper = new ObjectMapper();
196         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
197         PolicyRestAdapter policyData = null;
198         try {
199             root = JsonLoader.fromString(jsonString);
200             policyData = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
201         } catch (Exception e) {
202             logger.error("testSetDataToPolicyRestAdapter", e);
203         }
204         CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
205         PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root);
206         assertTrue(result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty());
207
208         logger.debug("result.getJsonBody() : " + result.getJsonBody());
209         logger.debug("testSetDataToPolicyRestAdapter: exit");
210     }
211
212     /**
213      * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, HttpServletResponse) method test.
214      */
215
216     @Test
217     public void testGetDcaeMsTemplateData() {
218
219         logger.debug("testGetDCAEMSTemplateData: enter");
220
221         CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
222         MockHttpServletResponse response = new MockHttpServletResponse();
223         String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
224         try {
225
226             CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
227
228             BufferedReader br = new BufferedReader(new StringReader(msModelJson));
229             // mock the getReader() call
230             when(request.getReader()).thenReturn(br);
231
232             List<Object> microServiceModelsData = new ArrayList<Object>();
233             MicroServiceModels testData = new MicroServiceModels();
234             testData.setVersion("1707.4.1.2-Junit");
235             microServiceModelsData.add(testData);
236             // mock the getDataById() call with the same MS model name
237             when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
238                     .thenReturn(microServiceModelsData);
239
240             controller.getDCAEMSTemplateData(request, response);
241
242             assertTrue(
243                     response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData"));
244
245             logger.debug("response: " + response.getContentAsString());
246
247         } catch (Exception e) {
248             logger.error("testGetDCAEMSTemplateData", e);
249         }
250
251         logger.debug("testGetDCAEMSTemplateData: exit");
252     }
253
254     /**
255      * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse) method test.
256      */
257
258     @Test
259     public void testGetModelServiceVersionData() {
260
261         logger.debug("testGetModelServiceVersionData: enter");
262
263         CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
264         MockHttpServletResponse response = new MockHttpServletResponse();
265         String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
266         try {
267
268             CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
269
270             BufferedReader br = new BufferedReader(new StringReader(msModelJson));
271             // mock the getReader() call
272             when(request.getReader()).thenReturn(br);
273
274             List<Object> microServiceModelsData = new ArrayList<Object>();
275             MicroServiceModels testData = new MicroServiceModels();
276             testData.setVersion("1707.4.1.2-Junit");
277             microServiceModelsData.add(testData);
278
279             // mock the getDataById() call with the same MS model name
280             when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
281                     .thenReturn(microServiceModelsData);
282             controller.getModelServiceVersionData(request, response);
283
284             assertTrue(response.getContentAsString() != null
285                     && response.getContentAsString().contains("1707.4.1.2-Junit"));
286
287             logger.debug("response: " + response.getContentAsString());
288
289         } catch (Exception e) {
290             logger.error("testGetModelServiceVersionData", e);
291             fail("testGetModelServiceVersionData failed due to: " + e);
292         }
293
294         logger.debug("testGetModelServiceVersionData: exit");
295     }
296
297     /**
298      * Run the void getDCAEPriorityValuesData(HttpServletRequest, HttpServletResponse) method test.
299      */
300
301     @Test
302     public void testGetDcaePriorityValuesData() {
303
304         logger.debug("testGetDCAEPriorityValuesData: enter");
305
306         CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
307
308         MockHttpServletRequest request = new MockHttpServletRequest();
309         MockHttpServletResponse response = new MockHttpServletResponse();
310         try {
311             controller.getDCAEPriorityValuesData(request, response);
312             assertTrue(
313                     response.getContentAsString() != null && response.getContentAsString().contains("priorityDatas"));
314             logger.debug("response: " + response.getContentAsString());
315         } catch (Exception e) {
316             logger.error("testGetDCAEPriorityValuesData", e);
317             fail("testGetDCAEPriorityValuesData failed due to: " + e);
318         }
319
320         logger.debug("testGetDCAEPriorityValuesData: exit");
321     }
322
323     /**
324      * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test.
325      */
326
327     @Test
328     public void testPrePopulateDcaeMsPolicyData() {
329
330         logger.debug("testPrePopulateDCAEMSPolicyData: enter");
331
332         CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
333
334         // populate an entity object for testing
335         PolicyEntity entity = new PolicyEntity();
336         ConfigurationDataEntity configData = new ConfigurationDataEntity();
337         configData.setConfigBody(configBodyString);
338         entity.setConfigurationData(configData);
339
340         JsonNode root = null;
341         ObjectMapper mapper = new ObjectMapper();
342         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
343         PolicyRestAdapter restAdapter = null;
344
345         try {
346             root = JsonLoader.fromString(jsonString);
347             restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
348
349             // create guard attribute
350             MatchType matchType = new MatchType();
351             // set value
352             AttributeValueType attributeValue1 = new AttributeValueType();
353             attributeValue1.getContent().add("True");
354             matchType.setAttributeValue(attributeValue1);
355             // set Id
356             AttributeDesignatorType designator = new AttributeDesignatorType();
357             designator.setAttributeId("guard");
358             matchType.setAttributeDesignator(designator);
359             AllOfType alltype = new AllOfType();
360             alltype.getMatch().add(matchType);
361
362             // add a dummy MatchType object since while (matchList.size()>1 ...)
363             MatchType matchDummy = new MatchType();
364             // set value
365             AttributeValueType dummyValue = new AttributeValueType();
366             dummyValue.getContent().add("dummy");
367             matchDummy.setAttributeValue(dummyValue);
368             // set Id
369             AttributeDesignatorType designatorDummy = new AttributeDesignatorType();
370             designatorDummy.setAttributeId("dummyId");
371             matchDummy.setAttributeDesignator(designatorDummy);
372
373             alltype.getMatch().add(matchDummy);
374             AnyOfType anyOfType = new AnyOfType();
375             anyOfType.getAllOf().add(alltype);
376
377             TargetType target = new TargetType();
378             target.getAnyOf().add(anyOfType);
379
380             // create RiskType attribute
381             AnyOfType anyRiskType = new AnyOfType();
382             AllOfType allRiskType = new AllOfType();
383             MatchType matchRiskType = new MatchType();
384             // set value
385             AttributeValueType riskTypeValue = new AttributeValueType();
386             riskTypeValue.getContent().add("test");
387             matchRiskType.setAttributeValue(riskTypeValue);
388             // set Id
389             AttributeDesignatorType designatorRiskType = new AttributeDesignatorType();
390             designatorRiskType.setAttributeId("RiskType");
391             matchRiskType.setAttributeDesignator(designatorRiskType);
392             allRiskType.getMatch().add(matchRiskType);
393
394             // add a dummy MatchType object since while (matchList.size()>1 ...)
395             MatchType matchDummy1 = new MatchType();
396             // set value
397             AttributeValueType dummy1Value = new AttributeValueType();
398             dummy1Value.getContent().add("dummy");
399             matchDummy1.setAttributeValue(dummy1Value);
400             // set Id
401             AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType();
402             designatorDummy1.setAttributeId("dummyId");
403             matchDummy1.setAttributeDesignator(designatorDummy1);
404
405             allRiskType.getMatch().add(matchDummy1);
406
407             anyRiskType.getAllOf().add(allRiskType);
408
409             target.getAnyOf().add(anyRiskType);
410
411             // create RiskLevel attribute
412             MatchType matchRiskLevel = new MatchType();
413             // set value
414             AttributeValueType riskLevel = new AttributeValueType();
415             riskLevel.getContent().add("3");
416             matchRiskLevel.setAttributeValue(riskLevel);
417             // set Id
418             AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType();
419             designatorRiskLevel.setAttributeId("RiskLevel");
420             matchRiskLevel.setAttributeDesignator(designatorRiskLevel);
421             AllOfType allRiskLevel = new AllOfType();
422             allRiskLevel.getMatch().add(matchRiskLevel);
423
424             // add a dummy MatchType object since while (matchList.size()>1 ...)
425             MatchType matchDummy2 = new MatchType();
426             // set value
427             AttributeValueType dummy2Value = new AttributeValueType();
428             dummy2Value.getContent().add("dummy");
429             matchDummy2.setAttributeValue(dummy2Value);
430             // set Id
431             AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType();
432             designatorDummy2.setAttributeId("dummyId");
433             matchDummy2.setAttributeDesignator(designatorDummy2);
434
435             allRiskLevel.getMatch().add(matchDummy2);
436             AnyOfType anyRiskLevel = new AnyOfType();
437             anyRiskLevel.getAllOf().add(allRiskLevel);
438             target.getAnyOf().add(anyRiskLevel);
439             PolicyType policyType = new PolicyType();
440             policyType.setTarget(target);
441
442             restAdapter.setPolicyData(policyType);
443
444             controller.prePopulateDCAEMSPolicyData(restAdapter, entity);
445
446             logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType());
447             logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel());
448             logger.error("restAdapter.getGuard() : " + restAdapter.getGuard());
449
450             assertEquals("True", restAdapter.getGuard());
451             assertEquals("3", restAdapter.getRiskLevel());
452             assertEquals("test", restAdapter.getRiskType());
453
454         } catch (Exception e) {
455             logger.error("testPrePopulateDCAEMSPolicyData", e);
456             fail("testPrePopulateDCAEMSPolicyData failed due to: " + e);
457         }
458
459         logger.debug("testPrePopulateDCAEMSPolicyData: exit");
460
461     }
462
463     /**
464      * Run the Map<String,String> convert(String, String) method test.
465      */
466
467     @Test
468     public void testConvert() {
469         logger.debug("testConvert: enter");
470
471         String str = "k1=v1,k2=v2,k3=v3";
472         String split = ",";
473         Map<String, String> result = new CreateDcaeMicroServiceController().convert(str, split);
474         assertTrue(result != null && result.size() == 3);
475
476         logger.debug("testConvert: exit");
477     }
478
479     /**
480      * Run the Map<String,String> convertMap(Map<String,String>, Map<String,String>) method test.
481      */
482
483     @Test
484     public void testConvertMap() {
485         logger.debug("testConvertMap: enter");
486         Map<String, String> attributesMap = new HashMap<String, String>();
487
488         attributesMap.put("keyOne", "valueOne");
489         attributesMap.put("keyTwo", "valueTwo");
490         attributesMap.put("keyThree", "valueThree");
491         Map<String, String> attributesRefMap = new HashMap<String, String>();
492
493         attributesRefMap.put("key4", "value4");
494         attributesRefMap.put("key5", "value5");
495         attributesRefMap.put("key6", "value6");
496         CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
497         Map<String, String> attributesListRefMap = controller.getAttributesListRefMap();
498         LinkedList<String> list = new LinkedList<String>();
499
500         attributesListRefMap.put("key7", "value7");
501
502         list.add("l1");
503         list.add("l2");
504         Map<String, LinkedList<String>> arrayTextList = controller.getArrayTextList();
505         arrayTextList.put("key8", list);
506
507         Map<String, String> result = controller.convertMap(attributesMap, attributesRefMap);
508
509         assertTrue(result != null && result.size() == 8);
510
511         assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]"));
512
513         logger.debug("testConvertMap: exit");
514     }
515
516     /**
517      * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test.
518      */
519
520     // @Ignore
521     @Test
522     public void testSetMsModelData() {
523
524         logger.debug("testSetMSModelData: enter");
525
526         HttpServletRequest request = createMock(HttpServletRequest.class);
527         expect(request.getContentType())
528                 .andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p");
529         expect(request.getMethod()).andReturn("post");
530         expect(request.getHeader("Content-length")).andReturn("7809");
531
532         expect(request.getContentLength()).andReturn(7809);
533
534         try {
535             // value of fileName needs to be matched to your local directory
536             String fileName = "";
537             try {
538                 ClassLoader classLoader = getClass().getClassLoader();
539                 fileName = new File(classLoader.getResource("schedulerPolicies-v1707.xmi").getFile()).getAbsolutePath();
540             } catch (Exception e1) {
541                 logger.error("Exception Occured while loading file" + e1);
542             }
543             expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName));
544             expect(request.getCharacterEncoding()).andReturn("UTF-8");
545             expect(request.getContentLength()).andReturn(1024);
546             replay(request);
547
548         } catch (Exception e) {
549             logger.error("testSetMSModelData" + e);
550             e.printStackTrace();
551         }
552
553         logger.debug("testSetMSModelData: exit");
554     }
555
556     /**
557      * @ Get File Stream.
558      *
559      */
560     private class MockServletInputStream extends ServletInputStream {
561
562         InputStream fis = null;
563
564         public MockServletInputStream(String fileName) {
565             try {
566                 fis = new FileInputStream(fileName);
567             } catch (Exception genExe) {
568                 genExe.printStackTrace();
569             }
570         }
571
572         @Override
573         public int read() throws IOException {
574             if (fis.available() > 0) {
575                 return fis.read();
576             }
577             return 0;
578         }
579
580         @Override
581         public int read(byte[] bytes, int len, int size) throws IOException {
582             if (fis.available() > 0) {
583                 int length = fis.read(bytes, len, size);
584                 return length;
585             }
586             return -1;
587         }
588
589         @Override
590         public boolean isFinished() {
591             return false;
592         }
593
594         @Override
595         public boolean isReady() {
596             return false;
597         }
598
599         @Override
600         public void setReadListener(ReadListener arg0) {
601
602         }
603     }
604 }