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
77 * {@link <code>CreateDcaeMicroServiceController</code>}*
79 * All JUnits are designed to run in the local development environment where they have write privileges and can execute
80 * time-sensitive tasks.
84 public class CreateDcaeMicroServiceControllerTest {
86 private static Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceControllerTest.class);
87 private static CommonClassDao commonClassDao;
88 private String jsonString = null;
89 private String configBodyString = null;
90 private HttpServletRequest request = null;
93 public void setUp() throws Exception {
94 logger.info("setUp: Entering");
95 commonClassDao = mock(CommonClassDao.class);
96 List<Object> microServiceModelsData = new ArrayList<Object>();
97 MicroServiceModels testData = new MicroServiceModels();
98 testData.setVersion("OpenOnap-Junit");
99 testData.setModelName("modelName");
100 testData.setRuleFormation("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, "
101 + "Contains, FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
102 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
103 testData.setAttributes(
104 "ParentCorrelation Name=String:defaultValue-null:required-true:MANY-false:description-null,"
105 + "CorrelationWindow=String:defaultValue-null:required-true:MANY-false:description-null,"
106 + "EmailNotification=String:defaultValue-null:required-true:MANY-false:description-null,"
107 + "CorrelationPriority=string:defaultValue-null:required-true:MANY-false:description-null,");
108 testData.setRef_attributes("SymptomTriggerSignature=resource-model-symptomEntity:MANY-true:description-null,"
109 + "triggerSignature=resource-model-entity:MANY-true:description-null,"
110 + "SelectServerScope=SELECTSERVERSCOPE:MANY-false,logicalConnector=LOGICALCONNECTOR:MANY-false,"
111 + "ParentCorrelationTraversal=PARENTCORRELATIONTRAVERSAL:MANY-false,");
112 testData.setSub_attributes(
113 "{\"symptomAlarms\":{\"symptomContains\":\"SYMPTOMCONTAINS:defaultValue-null:required-true:MANY-false:"
114 + "description-null\",\"symptomFilterValue\":\"string:defaultValue-null:"
115 + "required-true:MANY-false:"
116 + "description-null\",\"symptomVnfType\":\"SYMPTOMVNFTYPE:defaultValue-null:"
117 + "required-true:MANY-false:"
118 + "description-null\"},\"symptomElement\":{\"symptomSignatures\":\"symptomRange:required-true:"
119 + "MANY-true:description-null\",\"symptomTraversal\":\"SYMPTOMTRAVERSAL:defaultValue-null:"
120 + "required-true:MANY-false:description-null\"},\"alarms\":{\"Contains\":\"CONTAINS:"
121 + "defaultValue-null:required-true:MANY-false:description-null\",\"VnfType\":\"VNFTYPE:"
122 + "defaultValue-null:required-true:MANY-false:description-null\",\"FilterValue\":\"string:"
123 + "defaultValue-null:required-true:MANY-false:description-null\"},\"resource-model-entity\":"
124 + "{\"signaturesAlarm\":\"element:required-false:MANY-false:description-null\"},\"range\":"
125 + "{\"alarmSignature\":\"alarms:required-true:MANY-false:description-null\"},\"symptomRange\":"
126 + "{\"symptomSignature\":\"symptomAlarms:required-true:MANY-false:description-null\"},"
128 + "{\"alarmSignatures\":\"range:required-true:MANY-true:description-null\",\"traversal\":"
129 + "\"TRAVERSAL:" + "defaultValue-null:required-true:MANY-false:description-null\"},"
130 + "\"resource-model-symptomEntity\":"
131 + "{\"signaturesSymptom\":\"symptomElement:required-false:MANY-false:description-null\"}}");
132 testData.setAnnotation(
133 "alarmSignatures=matching-true, symptomContains=matching-true, symptomSignatures=matching-true, "
134 + "symptomTraversal=matching-true, symptomVnfType=matching-true, Contains=matching-true, "
135 + "SelectServerScope=matching-true, VnfType=matching-true, traversal=matching-true, "
136 + "logicalConnector=matching-true, ParentCorrelationTraversal=matching-true");
137 testData.setEnumValues("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
138 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures.symptomSignature"
139 + "[symptomVnfType, symptomContains, symptomFilterValue]");
140 testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
141 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
142 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
143 microServiceModelsData.add(testData);
145 // mock the getDataById() call
146 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName:version", "TESTMODEL" + ":" + "TODAY"))
147 .thenReturn(microServiceModelsData);
149 jsonString = "{\"policyData\":{\"error\":\"\",\"inprocess\":false,\"model\":{\"name\":\"DCAE\","
150 + "\"subScopename\":\"\",\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":"
151 + "\"2019-02-26 09:56:23.0\",\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":"
152 + "\"\",\"createdBy\":\"super-admin\",\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\","
153 + "\"content\":\"\",\"recursive\":false},\"tempModel\":{\"name\":\"DCAE\",\"subScopename\":\"\","
154 + "\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":\"2019-02-26 09:56:23.0\","
155 + "\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":\"\",\"createdBy\":\"super-admin\","
156 + "\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\",\"content\":\"\","
157 + "\"recursive\":false},\"$$hashKey\":\"object:354\",\"policy\":{\"policyType\":\"Config\","
158 + "\"configPolicyType\":\"Micro Service\",\"serviceType\":\"TESTMODEL\",\"version\":\"TODAY\","
159 + "\"ruleGridData\":[\"Correlation Priority\",\"Correlation Window\","
160 + "\"Email Notification for failures\",\"Select Server Scope\","
161 + "\"Parent Correlation Name\",\"Parent Correlation Traversal\","
162 + "\"traversal\",\"FilterValue\"],\"policyName\":\"testttt\",\"onapName\":"
163 + "\"asdafadf\",\"guard\":\"True\",\"riskType\":\"sfsgs\",\"riskLevel\":\"1\","
164 + "\"priority\":\"1\",\"configName\":\"Search\",\"location\":\"Search\","
165 + "\"uuid\":\"Search\",\"policyScope\":\"PolicyScope_ssaaa123\"}},"
166 + "\"policyJSON\":{\"Correlation Priority\":\"testttt\",\"Correlation Window\":"
167 + "\"testttt\",\"Email Notification for failures\":\"sds@l.com\","
168 + "\"Select Server Scope\":\"testttt\",\"Parent Correlation Name\":"
169 + "\"testttt\",\"Parent Correlation Traversal\":\"testttt\",\"logicalConnector\":"
170 + "\"OR\",\"triggerSignature@0.signaturesAlarm.alarmSignatures@0.traversal\":\"testttt\","
171 + "\"triggerSignature@0.signaturesAlarm.alarmSignatures@0.alarmSignature@0.VnfType\":"
172 + "\" testttt\",\"triggerSignature@0.signaturesAlarm.alarmSignatures@0."
173 + "alarmSignature@0.Contains\":\"AND\",\"triggerSignature@0.signaturesAlarm."
174 + "alarmSignatures@0.alarmSignature@0.FilterValue\":\"testttt\"}}";
176 configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\","
177 + "\"templateVersion\":\"1607\",\"version\":\"HD\",\"priority\":\"2\","
178 + "\"content\":{\"lastPolled\":\"1\",\"boolen-test\":\"true\",\"created\":\"test\","
179 + "\"retiredDate\":\"test\",\"scope\":\"SNIRO_PLACEMENT_VDHV\",\"name\":\"test\","
180 + "\"lastModified\":\"test\",\"state\":\"CREATED\",\"type\":\"CONFIG\",\"intent\":\"test\","
181 + "\"target\":\"SNIRO\"}}";
183 request = mock(HttpServletRequest.class);
184 BufferedReader br = new BufferedReader(new StringReader(jsonString));
185 // mock the getReader() call
186 when(request.getReader()).thenReturn(br);
188 logger.info("setUp: exit");
192 * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test.
196 public void testSetDataToPolicyRestAdapter() {
198 logger.debug("testSetDataToPolicyRestAdapter: enter");
200 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
202 JsonNode root = null;
203 ObjectMapper mapper = new ObjectMapper();
204 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
205 PolicyRestAdapter policyData = null;
207 root = JsonLoader.fromString(jsonString);
208 policyData = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
209 } catch (Exception e) {
210 logger.error("testSetDataToPolicyRestAdapter", e);
212 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
213 PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root);
214 assertTrue(result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty());
216 logger.debug("result.getJsonBody() : " + result.getJsonBody());
217 logger.debug("testSetDataToPolicyRestAdapter: exit");
221 * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, HttpServletResponse) method test.
225 public void testGetDcaeMsTemplateData() {
227 logger.debug("testGetDCAEMSTemplateData: enter");
229 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
230 MockHttpServletResponse response = new MockHttpServletResponse();
231 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
234 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
236 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
237 // mock the getReader() call
238 when(request.getReader()).thenReturn(br);
240 List<Object> microServiceModelsData = new ArrayList<Object>();
241 MicroServiceModels testData = new MicroServiceModels();
242 testData.setVersion("1707.4.1.2-Junit");
243 microServiceModelsData.add(testData);
244 // mock the getDataById() call with the same MS model name
245 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
246 .thenReturn(microServiceModelsData);
248 controller.getDCAEMSTemplateData(request, response);
251 response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData"));
253 logger.debug("response: " + response.getContentAsString());
255 } catch (Exception e) {
256 logger.error("testGetDCAEMSTemplateData", e);
259 logger.debug("testGetDCAEMSTemplateData: exit");
263 * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse) method test.
267 public void testGetModelServiceVersionData() {
269 logger.debug("testGetModelServiceVersionData: enter");
271 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
272 MockHttpServletResponse response = new MockHttpServletResponse();
273 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
276 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
278 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
279 // mock the getReader() call
280 when(request.getReader()).thenReturn(br);
282 List<Object> microServiceModelsData = new ArrayList<Object>();
283 MicroServiceModels testData = new MicroServiceModels();
284 testData.setVersion("1707.4.1.2-Junit");
285 microServiceModelsData.add(testData);
287 // mock the getDataById() call with the same MS model name
288 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
289 .thenReturn(microServiceModelsData);
290 controller.getModelServiceVersionData(request, response);
292 assertTrue(response.getContentAsString() != null
293 && response.getContentAsString().contains("1707.4.1.2-Junit"));
295 logger.debug("response: " + response.getContentAsString());
297 } catch (Exception e) {
298 logger.error("testGetModelServiceVersionData", e);
299 fail("testGetModelServiceVersionData failed due to: " + e);
302 logger.debug("testGetModelServiceVersionData: exit");
306 * Run the void getDCAEPriorityValuesData(HttpServletRequest, HttpServletResponse) method test.
310 public void testGetDcaePriorityValuesData() {
312 logger.debug("testGetDCAEPriorityValuesData: enter");
314 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
316 MockHttpServletRequest request = new MockHttpServletRequest();
317 MockHttpServletResponse response = new MockHttpServletResponse();
319 controller.getDCAEPriorityValuesData(request, response);
321 response.getContentAsString() != null && response.getContentAsString().contains("priorityDatas"));
322 logger.debug("response: " + response.getContentAsString());
323 } catch (Exception e) {
324 logger.error("testGetDCAEPriorityValuesData", e);
325 fail("testGetDCAEPriorityValuesData failed due to: " + e);
328 logger.debug("testGetDCAEPriorityValuesData: exit");
332 * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test.
336 public void testPrePopulateDcaeMsPolicyData() {
338 logger.debug("testPrePopulateDCAEMSPolicyData: enter");
340 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
342 // populate an entity object for testing
343 PolicyEntity entity = new PolicyEntity();
344 ConfigurationDataEntity configData = new ConfigurationDataEntity();
345 configData.setConfigBody(configBodyString);
346 entity.setConfigurationData(configData);
348 JsonNode root = null;
349 ObjectMapper mapper = new ObjectMapper();
350 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
351 PolicyRestAdapter restAdapter = null;
354 root = JsonLoader.fromString(jsonString);
355 restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
356 TargetType target = new TargetType();
358 // create guard attribute
359 AnyOfType anyOfType = new AnyOfType();
360 AllOfType alltype = new AllOfType();
361 MatchType matchType = new MatchType();
363 AttributeValueType attributeValue1 = new AttributeValueType();
364 attributeValue1.getContent().add("True");
365 matchType.setAttributeValue(attributeValue1);
367 AttributeDesignatorType designator = new AttributeDesignatorType();
368 designator.setAttributeId("guard");
369 matchType.setAttributeDesignator(designator);
370 alltype.getMatch().add(matchType);
372 // add a dummy MatchType object since while (matchList.size()>1 ...)
373 MatchType matchDummy = new MatchType();
375 AttributeValueType dummyValue = new AttributeValueType();
376 dummyValue.getContent().add("dummy");
377 matchDummy.setAttributeValue(dummyValue);
379 AttributeDesignatorType designatorDummy = new AttributeDesignatorType();
380 designatorDummy.setAttributeId("dummyId");
381 matchDummy.setAttributeDesignator(designatorDummy);
383 alltype.getMatch().add(matchDummy);
384 anyOfType.getAllOf().add(alltype);
386 target.getAnyOf().add(anyOfType);
388 // create RiskType attribute
389 AnyOfType anyRiskType = new AnyOfType();
390 AllOfType allRiskType = new AllOfType();
391 MatchType matchRiskType = new MatchType();
393 AttributeValueType riskTypeValue = new AttributeValueType();
394 riskTypeValue.getContent().add("test");
395 matchRiskType.setAttributeValue(riskTypeValue);
397 AttributeDesignatorType designatorRiskType = new AttributeDesignatorType();
398 designatorRiskType.setAttributeId("RiskType");
399 matchRiskType.setAttributeDesignator(designatorRiskType);
400 allRiskType.getMatch().add(matchRiskType);
402 // add a dummy MatchType object since while (matchList.size()>1 ...)
403 MatchType matchDummy1 = new MatchType();
405 AttributeValueType dummy1Value = new AttributeValueType();
406 dummy1Value.getContent().add("dummy");
407 matchDummy1.setAttributeValue(dummy1Value);
409 AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType();
410 designatorDummy1.setAttributeId("dummyId");
411 matchDummy1.setAttributeDesignator(designatorDummy1);
413 allRiskType.getMatch().add(matchDummy1);
415 anyRiskType.getAllOf().add(allRiskType);
417 target.getAnyOf().add(anyRiskType);
419 // create RiskLevel attribute
420 MatchType matchRiskLevel = new MatchType();
422 AttributeValueType riskLevel = new AttributeValueType();
423 riskLevel.getContent().add("3");
424 matchRiskLevel.setAttributeValue(riskLevel);
426 AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType();
427 designatorRiskLevel.setAttributeId("RiskLevel");
428 matchRiskLevel.setAttributeDesignator(designatorRiskLevel);
429 AllOfType allRiskLevel = new AllOfType();
430 allRiskLevel.getMatch().add(matchRiskLevel);
432 // add a dummy MatchType object since while (matchList.size()>1 ...)
433 MatchType matchDummy2 = new MatchType();
435 AttributeValueType dummy2Value = new AttributeValueType();
436 dummy2Value.getContent().add("dummy");
437 matchDummy2.setAttributeValue(dummy2Value);
439 AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType();
440 designatorDummy2.setAttributeId("dummyId");
441 matchDummy2.setAttributeDesignator(designatorDummy2);
443 allRiskLevel.getMatch().add(matchDummy2);
444 AnyOfType anyRiskLevel = new AnyOfType();
445 anyRiskLevel.getAllOf().add(allRiskLevel);
446 target.getAnyOf().add(anyRiskLevel);
447 PolicyType policyType = new PolicyType();
448 policyType.setTarget(target);
450 restAdapter.setPolicyData(policyType);
452 controller.prePopulateDCAEMSPolicyData(restAdapter, entity);
454 logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType());
455 logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel());
456 logger.error("restAdapter.getGuard() : " + restAdapter.getGuard());
458 assertEquals("True", restAdapter.getGuard());
459 assertEquals("3", restAdapter.getRiskLevel());
460 assertEquals("test", restAdapter.getRiskType());
462 } catch (Exception e) {
463 logger.error("testPrePopulateDCAEMSPolicyData", e);
464 fail("testPrePopulateDCAEMSPolicyData failed due to: " + e);
467 logger.debug("testPrePopulateDCAEMSPolicyData: exit");
472 * Run the Map<String,String> convert(String, String) method test.
476 public void testConvert() {
477 logger.debug("testConvert: enter");
479 String str = "k1=v1,k2=v2,k3=v3";
481 Map<String, String> result = new CreateDcaeMicroServiceController().convert(str, split);
482 assertTrue(result != null && result.size() == 3);
484 logger.debug("testConvert: exit");
488 * Run the Map<String,String> convertMap(Map<String,String>, Map<String,String>) method test.
492 public void testConvertMap() {
493 logger.debug("testConvertMap: enter");
494 Map<String, String> attributesMap = new HashMap<String, String>();
496 attributesMap.put("keyOne", "valueOne");
497 attributesMap.put("keyTwo", "valueTwo");
498 attributesMap.put("keyThree", "valueThree");
499 Map<String, String> attributesRefMap = new HashMap<String, String>();
501 attributesRefMap.put("key4", "value4");
502 attributesRefMap.put("key5", "value5");
503 attributesRefMap.put("key6", "value6");
504 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
505 Map<String, String> attributesListRefMap = controller.getAttributesListRefMap();
506 LinkedList<String> list = new LinkedList<String>();
508 attributesListRefMap.put("key7", "value7");
512 Map<String, LinkedList<String>> arrayTextList = controller.getArrayTextList();
513 arrayTextList.put("key8", list);
515 Map<String, String> result = controller.convertMap(attributesMap, attributesRefMap);
517 assertTrue(result != null && result.size() == 8);
519 assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]"));
521 logger.debug("testConvertMap: exit");
525 * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test.
530 public void testSetMsModelData() {
532 logger.debug("testSetMSModelData: enter");
534 HttpServletRequest request = createMock(HttpServletRequest.class);
535 expect(request.getContentType())
536 .andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p");
537 expect(request.getMethod()).andReturn("post");
538 expect(request.getHeader("Content-length")).andReturn("7809");
540 expect(request.getContentLength()).andReturn(7809);
543 // value of fileName needs to be matched to your local directory
544 String fileName = "";
546 ClassLoader classLoader = getClass().getClassLoader();
547 fileName = new File(classLoader.getResource("schedulerPolicies-v1707.xmi").getFile()).getAbsolutePath();
548 } catch (Exception e1) {
549 logger.error("Exception Occured while loading file" + e1);
551 expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName));
552 expect(request.getCharacterEncoding()).andReturn("UTF-8");
553 expect(request.getContentLength()).andReturn(1024);
556 } catch (Exception e) {
557 logger.error("testSetMSModelData" + e);
561 logger.debug("testSetMSModelData: exit");
568 private class MockServletInputStream extends ServletInputStream {
570 InputStream fis = null;
572 public MockServletInputStream(String fileName) {
574 fis = new FileInputStream(fileName);
575 } catch (Exception genExe) {
576 genExe.printStackTrace();
581 public int read() throws IOException {
582 if (fis.available() > 0) {
589 public int read(byte[] bytes, int len, int size) throws IOException {
590 if (fis.available() > 0) {
591 int length = fis.read(bytes, len, size);
598 public boolean isFinished() {
603 public boolean isReady() {
608 public void setReadListener(ReadListener arg0) {