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;
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;
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;
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;
72 * The class <code>CreateDcaeMicroServiceControllerTest</code> contains tests for the class
73 * {@link <code>CreateDcaeMicroServiceController</code>}*
75 * All JUnits are designed to run in the local development environment where they have write privileges and can execute
76 * time-sensitive tasks.
80 public class CreateDcaeMicroServiceControllerTest {
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;
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\"},"
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);
141 // mock the getDataById() call
142 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName:version", "TESTMODEL" + ":" + "TODAY"))
143 .thenReturn(microServiceModelsData);
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.signaturesAlarm.alarmSignatures@0.traversal\":\"testttt\","
167 + "\"triggerSignature@0.signaturesAlarm.alarmSignatures@0.alarmSignature@0.VnfType\":"
168 + "\" testttt\",\"triggerSignature@0.signaturesAlarm.alarmSignatures@0."
169 + "alarmSignature@0.Contains\":\"AND\",\"triggerSignature@0.signaturesAlarm."
170 + "alarmSignatures@0.alarmSignature@0.FilterValue\":\"testttt\"}}";
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\"}}";
179 request = mock(HttpServletRequest.class);
180 BufferedReader br = new BufferedReader(new StringReader(jsonString));
181 // mock the getReader() call
182 when(request.getReader()).thenReturn(br);
184 logger.info("setUp: exit");
188 * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test.
192 public void testSetDataToPolicyRestAdapter() {
194 logger.debug("testSetDataToPolicyRestAdapter: enter");
196 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
198 JsonNode root = null;
199 ObjectMapper mapper = new ObjectMapper();
200 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
201 PolicyRestAdapter policyData = null;
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);
208 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
209 PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root);
210 assertTrue(result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty());
212 logger.debug("result.getJsonBody() : " + result.getJsonBody());
213 logger.debug("testSetDataToPolicyRestAdapter: exit");
217 * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, HttpServletResponse) method test.
221 public void testGetDcaeMsTemplateData() {
223 logger.debug("testGetDCAEMSTemplateData: enter");
225 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
226 MockHttpServletResponse response = new MockHttpServletResponse();
227 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
230 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
232 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
233 // mock the getReader() call
234 when(request.getReader()).thenReturn(br);
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);
244 controller.getDCAEMSTemplateData(request, response);
247 response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData"));
249 logger.debug("response: " + response.getContentAsString());
251 } catch (Exception e) {
252 logger.error("testGetDCAEMSTemplateData", e);
255 logger.debug("testGetDCAEMSTemplateData: exit");
259 * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse) method test.
263 public void testGetModelServiceVersionData() {
265 logger.debug("testGetModelServiceVersionData: enter");
267 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
268 MockHttpServletResponse response = new MockHttpServletResponse();
269 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
272 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
274 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
275 // mock the getReader() call
276 when(request.getReader()).thenReturn(br);
278 List<Object> microServiceModelsData = new ArrayList<Object>();
279 MicroServiceModels testData = new MicroServiceModels();
280 testData.setVersion("1707.4.1.2-Junit");
281 microServiceModelsData.add(testData);
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);
288 assertTrue(response.getContentAsString() != null
289 && response.getContentAsString().contains("1707.4.1.2-Junit"));
291 logger.debug("response: " + response.getContentAsString());
293 } catch (Exception e) {
294 logger.error("testGetModelServiceVersionData", e);
295 fail("testGetModelServiceVersionData failed due to: " + e);
298 logger.debug("testGetModelServiceVersionData: exit");
302 * Run the void getDCAEPriorityValuesData(HttpServletRequest, HttpServletResponse) method test.
306 public void testGetDcaePriorityValuesData() {
308 logger.debug("testGetDCAEPriorityValuesData: enter");
310 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
312 MockHttpServletRequest request = new MockHttpServletRequest();
313 MockHttpServletResponse response = new MockHttpServletResponse();
315 controller.getDCAEPriorityValuesData(request, response);
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);
324 logger.debug("testGetDCAEPriorityValuesData: exit");
328 * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test.
332 public void testPrePopulateDcaeMsPolicyData() {
334 logger.debug("testPrePopulateDCAEMSPolicyData: enter");
336 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
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);
344 JsonNode root = null;
345 ObjectMapper mapper = new ObjectMapper();
346 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
347 PolicyRestAdapter restAdapter = null;
350 root = JsonLoader.fromString(jsonString);
351 restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
352 TargetType target = new TargetType();
354 // create guard attribute
355 AnyOfType anyOfType = new AnyOfType();
356 AllOfType alltype = new AllOfType();
357 MatchType matchType = new MatchType();
359 AttributeValueType attributeValue1 = new AttributeValueType();
360 attributeValue1.getContent().add("True");
361 matchType.setAttributeValue(attributeValue1);
363 AttributeDesignatorType designator = new AttributeDesignatorType();
364 designator.setAttributeId("guard");
365 matchType.setAttributeDesignator(designator);
366 alltype.getMatch().add(matchType);
368 // add a dummy MatchType object since while (matchList.size()>1 ...)
369 MatchType matchDummy = new MatchType();
371 AttributeValueType dummyValue = new AttributeValueType();
372 dummyValue.getContent().add("dummy");
373 matchDummy.setAttributeValue(dummyValue);
375 AttributeDesignatorType designatorDummy = new AttributeDesignatorType();
376 designatorDummy.setAttributeId("dummyId");
377 matchDummy.setAttributeDesignator(designatorDummy);
379 alltype.getMatch().add(matchDummy);
380 anyOfType.getAllOf().add(alltype);
382 target.getAnyOf().add(anyOfType);
384 // create RiskType attribute
385 AnyOfType anyRiskType = new AnyOfType();
386 AllOfType allRiskType = new AllOfType();
387 MatchType matchRiskType = new MatchType();
389 AttributeValueType riskTypeValue = new AttributeValueType();
390 riskTypeValue.getContent().add("test");
391 matchRiskType.setAttributeValue(riskTypeValue);
393 AttributeDesignatorType designatorRiskType = new AttributeDesignatorType();
394 designatorRiskType.setAttributeId("RiskType");
395 matchRiskType.setAttributeDesignator(designatorRiskType);
396 allRiskType.getMatch().add(matchRiskType);
398 // add a dummy MatchType object since while (matchList.size()>1 ...)
399 MatchType matchDummy1 = new MatchType();
401 AttributeValueType dummy1Value = new AttributeValueType();
402 dummy1Value.getContent().add("dummy");
403 matchDummy1.setAttributeValue(dummy1Value);
405 AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType();
406 designatorDummy1.setAttributeId("dummyId");
407 matchDummy1.setAttributeDesignator(designatorDummy1);
409 allRiskType.getMatch().add(matchDummy1);
411 anyRiskType.getAllOf().add(allRiskType);
413 target.getAnyOf().add(anyRiskType);
415 // create RiskLevel attribute
416 MatchType matchRiskLevel = new MatchType();
418 AttributeValueType riskLevel = new AttributeValueType();
419 riskLevel.getContent().add("3");
420 matchRiskLevel.setAttributeValue(riskLevel);
422 AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType();
423 designatorRiskLevel.setAttributeId("RiskLevel");
424 matchRiskLevel.setAttributeDesignator(designatorRiskLevel);
425 AllOfType allRiskLevel = new AllOfType();
426 allRiskLevel.getMatch().add(matchRiskLevel);
428 // add a dummy MatchType object since while (matchList.size()>1 ...)
429 MatchType matchDummy2 = new MatchType();
431 AttributeValueType dummy2Value = new AttributeValueType();
432 dummy2Value.getContent().add("dummy");
433 matchDummy2.setAttributeValue(dummy2Value);
435 AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType();
436 designatorDummy2.setAttributeId("dummyId");
437 matchDummy2.setAttributeDesignator(designatorDummy2);
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);
446 restAdapter.setPolicyData(policyType);
448 controller.prePopulateDCAEMSPolicyData(restAdapter, entity);
450 logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType());
451 logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel());
452 logger.error("restAdapter.getGuard() : " + restAdapter.getGuard());
454 assertEquals("True", restAdapter.getGuard());
455 assertEquals("3", restAdapter.getRiskLevel());
456 assertEquals("test", restAdapter.getRiskType());
458 } catch (Exception e) {
459 logger.error("testPrePopulateDCAEMSPolicyData", e);
460 fail("testPrePopulateDCAEMSPolicyData failed due to: " + e);
463 logger.debug("testPrePopulateDCAEMSPolicyData: exit");
468 * Run the Map<String,String> convert(String, String) method test.
472 public void testConvert() {
473 logger.debug("testConvert: enter");
475 String str = "k1=v1,k2=v2,k3=v3";
477 Map<String, String> result = new CreateDcaeMicroServiceController().convert(str, split);
478 assertTrue(result != null && result.size() == 3);
480 logger.debug("testConvert: exit");
484 * Run the Map<String,String> convertMap(Map<String,String>, Map<String,String>) method test.
488 public void testConvertMap() {
489 logger.debug("testConvertMap: enter");
490 Map<String, String> attributesMap = new HashMap<String, String>();
492 attributesMap.put("keyOne", "valueOne");
493 attributesMap.put("keyTwo", "valueTwo");
494 attributesMap.put("keyThree", "valueThree");
495 Map<String, String> attributesRefMap = new HashMap<String, String>();
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>();
504 attributesListRefMap.put("key7", "value7");
508 Map<String, LinkedList<String>> arrayTextList = controller.getArrayTextList();
509 arrayTextList.put("key8", list);
511 Map<String, String> result = controller.convertMap(attributesMap, attributesRefMap);
513 assertTrue(result != null && result.size() == 8);
515 assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]"));
517 logger.debug("testConvertMap: exit");
521 * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test.
526 public void testSetMsModelData() {
528 logger.debug("testSetMSModelData: enter");
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");
536 expect(request.getContentLength()).andReturn(7809);
539 // value of fileName needs to be matched to your local directory
540 String fileName = "";
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);
547 expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName));
548 expect(request.getCharacterEncoding()).andReturn("UTF-8");
549 expect(request.getContentLength()).andReturn(1024);
552 } catch (Exception e) {
553 logger.error("testSetMSModelData" + e);
557 logger.debug("testSetMSModelData: exit");
564 private class MockServletInputStream extends ServletInputStream {
566 InputStream fis = null;
568 public MockServletInputStream(String fileName) {
570 fis = new FileInputStream(fileName);
571 } catch (Exception genExe) {
572 genExe.printStackTrace();
577 public int read() throws IOException {
578 if (fis.available() > 0) {
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);
594 public boolean isFinished() {
599 public boolean isReady() {
604 public void setReadListener(ReadListener arg0) {