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