2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.policy.controller;
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;
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;
39 import java.io.BufferedReader;
41 import java.io.FileInputStream;
42 import java.io.IOException;
43 import java.io.InputStream;
44 import java.io.StringReader;
45 import java.util.ArrayList;
46 import java.util.HashMap;
47 import java.util.LinkedList;
48 import java.util.List;
51 import javax.servlet.ReadListener;
52 import javax.servlet.ServletInputStream;
53 import javax.servlet.http.HttpServletRequest;
55 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
56 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
58 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
59 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
60 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
61 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
63 import org.junit.Before;
64 import org.junit.Test;
65 import org.onap.policy.common.logging.flexlogger.FlexLogger;
66 import org.onap.policy.common.logging.flexlogger.Logger;
67 import org.onap.policy.rest.adapter.PolicyRestAdapter;
68 import org.onap.policy.rest.dao.CommonClassDao;
69 import org.onap.policy.rest.jpa.ConfigurationDataEntity;
70 import org.onap.policy.rest.jpa.MicroServiceModels;
71 import org.onap.policy.rest.jpa.PolicyEntity;
72 import org.springframework.mock.web.MockHttpServletRequest;
73 import org.springframework.mock.web.MockHttpServletResponse;
76 * The class <code>CreateDcaeMicroServiceControllerTest</code> contains tests for the class
78 * <p/>All JUnits are designed to run in the local development environment where they have write privileges
79 * and can execute time-sensitive tasks.
83 public class CreateDcaeMicroServiceControllerTest {
85 private static Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceControllerTest.class);
86 private static CommonClassDao commonClassDao;
87 private String jsonString = null;
88 private String configBodyString = null;
89 private HttpServletRequest request = null;
94 * @throws Exception should not throw one
97 public void setUp() throws Exception {
98 logger.info("setUp: Entering");
99 commonClassDao = mock(CommonClassDao.class);
100 MicroServiceModels testData = new MicroServiceModels();
101 testData.setVersion("OpenOnap-Junit");
102 testData.setModelName("modelName");
103 testData.setRuleFormation("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, "
104 + "Contains, FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
105 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
106 testData.setAttributes(
107 "ParentCorrelation Name=String:defaultValue-null:required-true:MANY-false:description-null,"
108 + "CorrelationWindow=String:defaultValue-null:required-true:MANY-false:description-null,"
109 + "EmailNotification=String:defaultValue-null:required-true:MANY-false:description-null,"
110 + "CorrelationPriority=string:defaultValue-null:required-true:MANY-false:description-null,");
111 testData.setRefAttributes("SymptomTriggerSignature=resource-model-symptomEntity:MANY-true:description-null,"
112 + "triggerSignature=resource-model-entity:MANY-true:description-null,"
113 + "SelectServerScope=SELECTSERVERSCOPE:MANY-false,logicalConnector=LOGICALCONNECTOR:MANY-false,"
114 + "ParentCorrelationTraversal=PARENTCORRELATIONTRAVERSAL:MANY-false,");
115 testData.setSubAttributes(
116 "{\"symptomAlarms\":{\"symptomContains\":\"SYMPTOMCONTAINS:defaultValue-null:required-true:MANY-false:"
117 + "description-null\",\"symptomFilterValue\":\"string:defaultValue-null:"
118 + "required-true:MANY-false:"
119 + "description-null\",\"symptomVnfType\":\"SYMPTOMVNFTYPE:defaultValue-null:"
120 + "required-true:MANY-false:"
121 + "description-null\"},\"symptomElement\":{\"symptomSignatures\":\"symptomRange:required-true:"
122 + "MANY-true:description-null\",\"symptomTraversal\":\"SYMPTOMTRAVERSAL:defaultValue-null:"
123 + "required-true:MANY-false:description-null\"},\"alarms\":{\"Contains\":\"CONTAINS:"
124 + "defaultValue-null:required-true:MANY-false:description-null\",\"VnfType\":\"VNFTYPE:"
125 + "defaultValue-null:required-true:MANY-false:description-null\",\"FilterValue\":\"string:"
126 + "defaultValue-null:required-true:MANY-false:description-null\"},\"resource-model-entity\":"
127 + "{\"signaturesAlarm\":\"element:required-false:MANY-false:description-null\"},\"range\":"
128 + "{\"alarmSignature\":\"alarms:required-true:MANY-false:description-null\"},\"symptomRange\":"
129 + "{\"symptomSignature\":\"symptomAlarms:required-true:MANY-false:description-null\"},"
131 + "{\"alarmSignatures\":\"range:required-true:MANY-true:description-null\",\"traversal\":"
132 + "\"TRAVERSAL:" + "defaultValue-null:required-true:MANY-false:description-null\"},"
133 + "\"resource-model-symptomEntity\":"
134 + "{\"signaturesSymptom\":\"symptomElement:required-false:MANY-false:description-null\"}}");
135 testData.setAnnotation(
136 "alarmSignatures=matching-true, symptomContains=matching-true, symptomSignatures=matching-true, "
137 + "symptomTraversal=matching-true, symptomVnfType=matching-true, Contains=matching-true, "
138 + "SelectServerScope=matching-true, VnfType=matching-true, traversal=matching-true, "
139 + "logicalConnector=matching-true, ParentCorrelationTraversal=matching-true");
140 testData.setEnumValues("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
141 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures.symptomSignature"
142 + "[symptomVnfType, symptomContains, symptomFilterValue]");
143 testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
144 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
145 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
146 List<Object> microServiceModelsData = new ArrayList<Object>();
147 microServiceModelsData.add(testData);
149 // mock the getDataById() call
150 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName:version", "TESTMODEL" + ":" + "TODAY"))
151 .thenReturn(microServiceModelsData);
153 jsonString = "{\"policyData\":{\"error\":\"\",\"inprocess\":false,\"model\":{\"name\":\"DCAE\","
154 + "\"subScopename\":\"\",\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":"
155 + "\"2019-02-26 09:56:23.0\",\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":"
156 + "\"\",\"createdBy\":\"super-admin\",\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\","
157 + "\"content\":\"\",\"recursive\":false},\"tempModel\":{\"name\":\"DCAE\",\"subScopename\":\"\","
158 + "\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":\"2019-02-26 09:56:23.0\","
159 + "\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":\"\",\"createdBy\":\"super-admin\","
160 + "\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\",\"content\":\"\","
161 + "\"recursive\":false},\"$$hashKey\":\"object:354\",\"policy\":{\"policyType\":\"Config\","
162 + "\"configPolicyType\":\"Micro Service\",\"serviceType\":\"TESTMODEL\",\"version\":\"TODAY\","
163 + "\"ruleGridData\":[\"Correlation Priority\",\"Correlation Window\","
164 + "\"Email Notification for failures\",\"Select Server Scope\","
165 + "\"Parent Correlation Name\",\"Parent Correlation Traversal\","
166 + "\"traversal\",\"FilterValue\"],\"policyName\":\"testttt\",\"onapName\":"
167 + "\"asdafadf\",\"guard\":\"True\",\"riskType\":\"sfsgs\",\"riskLevel\":\"1\","
168 + "\"priority\":\"1\",\"configName\":\"Search\",\"location\":\"Search\","
169 + "\"uuid\":\"Search\",\"policyScope\":\"PolicyScope_ssaaa123\"}},"
170 + "\"policyJSON\":{\"Correlation Priority\":\"testttt\",\"Correlation Window\":"
171 + "\"testttt\",\"Email Notification for failures\":\"sds@l.com\","
172 + "\"Select Server Scope\":\"testttt\",\"Parent Correlation Name\":"
173 + "\"testttt\",\"Parent Correlation Traversal\":\"testttt\",\"logicalConnector\":"
174 + "\"OR\",\"triggerSignature@0.signaturesAlarm.alarmSignatures@0.traversal\":\"testttt\","
175 + "\"triggerSignature@0.signaturesAlarm.alarmSignatures@0.alarmSignature@0.VnfType\":"
176 + "\" testttt\",\"triggerSignature@0.signaturesAlarm.alarmSignatures@0."
177 + "alarmSignature@0.Contains\":\"AND\",\"triggerSignature@0.signaturesAlarm."
178 + "alarmSignatures@0.alarmSignature@0.FilterValue\":\"testttt\"}}";
180 configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\","
181 + "\"templateVersion\":\"1607\",\"version\":\"HD\",\"priority\":\"2\","
182 + "\"content\":{\"lastPolled\":\"1\",\"boolen-test\":\"true\",\"created\":\"test\","
183 + "\"retiredDate\":\"test\",\"scope\":\"SNIRO_PLACEMENT_VDHV\",\"name\":\"test\","
184 + "\"lastModified\":\"test\",\"state\":\"CREATED\",\"type\":\"CONFIG\",\"intent\":\"test\","
185 + "\"target\":\"SNIRO\"}}";
187 request = mock(HttpServletRequest.class);
188 BufferedReader br = new BufferedReader(new StringReader(jsonString));
189 // mock the getReader() call
190 when(request.getReader()).thenReturn(br);
192 logger.info("setUp: exit");
196 * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test.
200 public void testSetDataToPolicyRestAdapter() {
202 logger.debug("testSetDataToPolicyRestAdapter: enter");
204 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
206 JsonNode root = null;
207 ObjectMapper mapper = new ObjectMapper();
208 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
209 PolicyRestAdapter policyData = null;
211 root = JsonLoader.fromString(jsonString);
212 policyData = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
213 } catch (Exception e) {
214 logger.error("testSetDataToPolicyRestAdapter", e);
216 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
217 PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root);
218 assertTrue(result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty());
220 logger.debug("result.getJsonBody() : " + result.getJsonBody());
221 logger.debug("testSetDataToPolicyRestAdapter: exit");
225 * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, HttpServletResponse) method test.
229 public void testGetDcaeMsTemplateData() {
231 logger.debug("testGetDCAEMSTemplateData: enter");
233 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
234 MockHttpServletResponse response = new MockHttpServletResponse();
235 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
238 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
240 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
241 // mock the getReader() call
242 when(request.getReader()).thenReturn(br);
244 List<Object> microServiceModelsData = new ArrayList<Object>();
245 MicroServiceModels testData = new MicroServiceModels();
246 testData.setVersion("1707.4.1.2-Junit");
247 microServiceModelsData.add(testData);
248 // mock the getDataById() call with the same MS model name
249 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
250 .thenReturn(microServiceModelsData);
252 controller.getDCAEMSTemplateData(request, response);
255 response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData"));
257 logger.debug("response: " + response.getContentAsString());
259 } catch (Exception e) {
260 logger.error("testGetDCAEMSTemplateData", e);
263 logger.debug("testGetDCAEMSTemplateData: exit");
267 * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse) method test.
271 public void testGetModelServiceVersionData() {
273 logger.debug("testGetModelServiceVersionData: enter");
275 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
276 MockHttpServletResponse response = new MockHttpServletResponse();
277 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
280 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
282 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
283 // mock the getReader() call
284 when(request.getReader()).thenReturn(br);
286 List<Object> microServiceModelsData = new ArrayList<Object>();
287 MicroServiceModels testData = new MicroServiceModels();
288 testData.setVersion("1707.4.1.2-Junit");
289 microServiceModelsData.add(testData);
291 // mock the getDataById() call with the same MS model name
292 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
293 .thenReturn(microServiceModelsData);
294 controller.getModelServiceVersionData(request, response);
296 assertTrue(response.getContentAsString() != null
297 && response.getContentAsString().contains("1707.4.1.2-Junit"));
299 logger.debug("response: " + response.getContentAsString());
301 } catch (Exception e) {
302 logger.error("testGetModelServiceVersionData", e);
303 fail("testGetModelServiceVersionData failed due to: " + e);
306 logger.debug("testGetModelServiceVersionData: exit");
310 * Run the void getDCAEPriorityValuesData(HttpServletRequest, HttpServletResponse) method test.
314 public void testGetDcaePriorityValuesData() {
316 logger.debug("testGetDCAEPriorityValuesData: enter");
318 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
320 MockHttpServletRequest request = new MockHttpServletRequest();
321 MockHttpServletResponse response = new MockHttpServletResponse();
323 controller.getDCAEPriorityValuesData(request, response);
325 response.getContentAsString() != null && response.getContentAsString().contains("priorityDatas"));
326 logger.debug("response: " + response.getContentAsString());
327 } catch (Exception e) {
328 logger.error("testGetDCAEPriorityValuesData", e);
329 fail("testGetDCAEPriorityValuesData failed due to: " + e);
332 logger.debug("testGetDCAEPriorityValuesData: exit");
336 * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test.
340 public void testPrePopulateDcaeMsPolicyData() {
342 logger.debug("testPrePopulateDCAEMSPolicyData: enter");
344 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
346 // populate an entity object for testing
347 PolicyEntity entity = new PolicyEntity();
348 ConfigurationDataEntity configData = new ConfigurationDataEntity();
349 configData.setConfigBody(configBodyString);
350 entity.setConfigurationData(configData);
352 JsonNode root = null;
353 ObjectMapper mapper = new ObjectMapper();
354 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
355 PolicyRestAdapter restAdapter = null;
358 root = JsonLoader.fromString(jsonString);
359 restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
361 // create guard attribute
362 MatchType matchType = new MatchType();
364 AttributeValueType attributeValue1 = new AttributeValueType();
365 attributeValue1.getContent().add("True");
366 matchType.setAttributeValue(attributeValue1);
368 AttributeDesignatorType designator = new AttributeDesignatorType();
369 designator.setAttributeId("guard");
370 matchType.setAttributeDesignator(designator);
371 AllOfType alltype = new AllOfType();
372 alltype.getMatch().add(matchType);
374 // add a dummy MatchType object since while (matchList.size()>1 ...)
375 MatchType matchDummy = new MatchType();
377 AttributeValueType dummyValue = new AttributeValueType();
378 dummyValue.getContent().add("dummy");
379 matchDummy.setAttributeValue(dummyValue);
381 AttributeDesignatorType designatorDummy = new AttributeDesignatorType();
382 designatorDummy.setAttributeId("dummyId");
383 matchDummy.setAttributeDesignator(designatorDummy);
385 alltype.getMatch().add(matchDummy);
386 AnyOfType anyOfType = new AnyOfType();
387 anyOfType.getAllOf().add(alltype);
389 TargetType target = new TargetType();
390 target.getAnyOf().add(anyOfType);
392 // create RiskType attribute
393 AnyOfType anyRiskType = new AnyOfType();
394 AllOfType allRiskType = new AllOfType();
395 MatchType matchRiskType = new MatchType();
397 AttributeValueType riskTypeValue = new AttributeValueType();
398 riskTypeValue.getContent().add("test");
399 matchRiskType.setAttributeValue(riskTypeValue);
401 AttributeDesignatorType designatorRiskType = new AttributeDesignatorType();
402 designatorRiskType.setAttributeId("RiskType");
403 matchRiskType.setAttributeDesignator(designatorRiskType);
404 allRiskType.getMatch().add(matchRiskType);
406 // add a dummy MatchType object since while (matchList.size()>1 ...)
407 MatchType matchDummy1 = new MatchType();
409 AttributeValueType dummy1Value = new AttributeValueType();
410 dummy1Value.getContent().add("dummy");
411 matchDummy1.setAttributeValue(dummy1Value);
413 AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType();
414 designatorDummy1.setAttributeId("dummyId");
415 matchDummy1.setAttributeDesignator(designatorDummy1);
417 allRiskType.getMatch().add(matchDummy1);
419 anyRiskType.getAllOf().add(allRiskType);
421 target.getAnyOf().add(anyRiskType);
423 // create RiskLevel attribute
424 MatchType matchRiskLevel = new MatchType();
426 AttributeValueType riskLevel = new AttributeValueType();
427 riskLevel.getContent().add("3");
428 matchRiskLevel.setAttributeValue(riskLevel);
430 AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType();
431 designatorRiskLevel.setAttributeId("RiskLevel");
432 matchRiskLevel.setAttributeDesignator(designatorRiskLevel);
433 AllOfType allRiskLevel = new AllOfType();
434 allRiskLevel.getMatch().add(matchRiskLevel);
436 // add a dummy MatchType object since while (matchList.size()>1 ...)
437 MatchType matchDummy2 = new MatchType();
439 AttributeValueType dummy2Value = new AttributeValueType();
440 dummy2Value.getContent().add("dummy");
441 matchDummy2.setAttributeValue(dummy2Value);
443 AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType();
444 designatorDummy2.setAttributeId("dummyId");
445 matchDummy2.setAttributeDesignator(designatorDummy2);
447 allRiskLevel.getMatch().add(matchDummy2);
448 AnyOfType anyRiskLevel = new AnyOfType();
449 anyRiskLevel.getAllOf().add(allRiskLevel);
450 target.getAnyOf().add(anyRiskLevel);
451 PolicyType policyType = new PolicyType();
452 policyType.setTarget(target);
454 restAdapter.setPolicyData(policyType);
456 controller.prePopulateDCAEMSPolicyData(restAdapter, entity);
458 logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType());
459 logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel());
460 logger.error("restAdapter.getGuard() : " + restAdapter.getGuard());
462 assertEquals("True", restAdapter.getGuard());
463 assertEquals("3", restAdapter.getRiskLevel());
464 assertEquals("test", restAdapter.getRiskType());
466 } catch (Exception e) {
467 logger.error("testPrePopulateDCAEMSPolicyData", e);
468 fail("testPrePopulateDCAEMSPolicyData failed due to: " + e);
471 logger.debug("testPrePopulateDCAEMSPolicyData: exit");
476 * Run the Map<String,String> convert(String, String) method test.
480 public void testConvert() {
481 logger.debug("testConvert: enter");
483 String str = "k1=v1,k2=v2,k3=v3";
485 Map<String, String> result = new CreateDcaeMicroServiceController().convert(str, split);
486 assertTrue(result != null && result.size() == 3);
488 logger.debug("testConvert: exit");
492 * Run the Map<String,String> convertMap(Map<String,String>, Map<String,String>) method test.
496 public void testConvertMap() {
497 logger.debug("testConvertMap: enter");
498 Map<String, String> attributesMap = new HashMap<String, String>();
500 attributesMap.put("keyOne", "valueOne");
501 attributesMap.put("keyTwo", "valueTwo");
502 attributesMap.put("keyThree", "valueThree");
503 Map<String, String> attributesRefMap = new HashMap<String, String>();
505 attributesRefMap.put("key4", "value4");
506 attributesRefMap.put("key5", "value5");
507 attributesRefMap.put("key6", "value6");
508 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
509 Map<String, String> attributesListRefMap = controller.getAttributesListRefMap();
510 LinkedList<String> list = new LinkedList<String>();
512 attributesListRefMap.put("key7", "value7");
516 Map<String, LinkedList<String>> arrayTextList = controller.getArrayTextList();
517 arrayTextList.put("key8", list);
519 Map<String, String> result = controller.convertMap(attributesMap, attributesRefMap);
521 assertTrue(result != null && result.size() == 8);
523 assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]"));
525 logger.debug("testConvertMap: exit");
529 * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test.
534 public void testSetMsModelData() {
536 logger.debug("testSetMSModelData: enter");
538 HttpServletRequest request = createMock(HttpServletRequest.class);
539 expect(request.getContentType())
540 .andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p");
541 expect(request.getMethod()).andReturn("post");
542 expect(request.getHeader("Content-length")).andReturn("7809");
544 expect(request.getContentLength()).andReturn(7809);
547 // value of fileName needs to be matched to your local directory
548 String fileName = "";
550 ClassLoader classLoader = getClass().getClassLoader();
551 fileName = new File(classLoader.getResource("schedulerPolicies-v1707.xmi").getFile()).getAbsolutePath();
552 } catch (Exception e1) {
553 logger.error("Exception Occured while loading file" + e1);
555 expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName));
556 expect(request.getCharacterEncoding()).andReturn("UTF-8");
557 expect(request.getContentLength()).andReturn(1024);
560 } catch (Exception e) {
561 logger.error("testSetMSModelData" + e);
565 logger.debug("testSetMSModelData: exit");
572 private class MockServletInputStream extends ServletInputStream {
574 InputStream fis = null;
576 public MockServletInputStream(String fileName) {
578 fis = new FileInputStream(fileName);
579 } catch (Exception genExe) {
580 genExe.printStackTrace();
585 public int read() throws IOException {
586 if (fis.available() > 0) {
593 public int read(byte[] bytes, int len, int size) throws IOException {
594 if (fis.available() > 0) {
595 int length = fis.read(bytes, len, size);
602 public boolean isFinished() {
607 public boolean isReady() {
612 public void setReadListener(ReadListener arg0) {