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