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;
33 import com.fasterxml.jackson.databind.DeserializationFeature;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.github.fge.jackson.JsonLoader;
37 import java.io.BufferedReader;
39 import java.io.FileInputStream;
40 import java.io.IOException;
41 import java.io.InputStream;
42 import java.io.StringReader;
43 import java.util.ArrayList;
44 import java.util.HashMap;
45 import java.util.LinkedList;
46 import java.util.List;
48 import javax.servlet.ReadListener;
49 import javax.servlet.ServletInputStream;
50 import javax.servlet.http.HttpServletRequest;
51 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
52 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
53 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
54 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
55 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
56 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
58 import org.junit.Before;
59 import org.junit.Test;
60 import org.onap.policy.common.logging.flexlogger.FlexLogger;
61 import org.onap.policy.common.logging.flexlogger.Logger;
62 import org.onap.policy.rest.adapter.PolicyRestAdapter;
63 import org.onap.policy.rest.dao.CommonClassDao;
64 import org.onap.policy.rest.jpa.ConfigurationDataEntity;
65 import org.onap.policy.rest.jpa.MicroServiceModels;
66 import org.onap.policy.rest.jpa.PolicyEntity;
67 import org.springframework.mock.web.MockHttpServletRequest;
68 import org.springframework.mock.web.MockHttpServletResponse;
71 * The class <code>CreateDcaeMicroServiceControllerTest</code> contains tests for the class
73 * <p/>All JUnits are designed to run in the local development environment where they have write privileges
74 * and can execute time-sensitive tasks.
78 public class CreateDcaeMicroServiceControllerTest {
80 private static Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceControllerTest.class);
81 private static CommonClassDao commonClassDao;
82 private String jsonString = null;
83 private String configBodyString = null;
84 private HttpServletRequest request = null;
89 * @throws Exception should not throw one
92 public void setUp() throws Exception {
93 logger.info("setUp: Entering");
94 commonClassDao = mock(CommonClassDao.class);
95 MicroServiceModels testData = new MicroServiceModels();
96 testData.setVersion("OpenOnap-Junit");
97 testData.setModelName("modelName");
98 testData.setRuleFormation("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, "
99 + "Contains, FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
100 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
101 testData.setAttributes(
102 "ParentCorrelation Name=String:defaultValue-null:required-true:MANY-false:description-null,"
103 + "CorrelationWindow=String:defaultValue-null:required-true:MANY-false:description-null,"
104 + "EmailNotification=String:defaultValue-null:required-true:MANY-false:description-null,"
105 + "CorrelationPriority=string:defaultValue-null:required-true:MANY-false:description-null,");
106 testData.setRefAttributes("SymptomTriggerSignature=resource-model-symptomEntity:MANY-true:description-null,"
107 + "triggerSignature=resource-model-entity:MANY-true:description-null,"
108 + "SelectServerScope=SELECTSERVERSCOPE:MANY-false,logicalConnector=LOGICALCONNECTOR:MANY-false,"
109 + "ParentCorrelationTraversal=PARENTCORRELATIONTRAVERSAL:MANY-false,");
110 testData.setSubAttributes(
111 "{\"symptomAlarms\":{\"symptomContains\":\"SYMPTOMCONTAINS:defaultValue-null:required-true:MANY-false:"
112 + "description-null\",\"symptomFilterValue\":\"string:defaultValue-null:"
113 + "required-true:MANY-false:"
114 + "description-null\",\"symptomVnfType\":\"SYMPTOMVNFTYPE:defaultValue-null:"
115 + "required-true:MANY-false:"
116 + "description-null\"},\"symptomElement\":{\"symptomSignatures\":\"symptomRange:required-true:"
117 + "MANY-true:description-null\",\"symptomTraversal\":\"SYMPTOMTRAVERSAL:defaultValue-null:"
118 + "required-true:MANY-false:description-null\"},\"alarms\":{\"Contains\":\"CONTAINS:"
119 + "defaultValue-null:required-true:MANY-false:description-null\",\"VnfType\":\"VNFTYPE:"
120 + "defaultValue-null:required-true:MANY-false:description-null\",\"FilterValue\":\"string:"
121 + "defaultValue-null:required-true:MANY-false:description-null\"},\"resource-model-entity\":"
122 + "{\"signaturesAlarm\":\"element:required-false:MANY-false:description-null\"},\"range\":"
123 + "{\"alarmSignature\":\"alarms:required-true:MANY-false:description-null\"},\"symptomRange\":"
124 + "{\"symptomSignature\":\"symptomAlarms:required-true:MANY-false:description-null\"},"
126 + "{\"alarmSignatures\":\"range:required-true:MANY-true:description-null\",\"traversal\":"
127 + "\"TRAVERSAL:" + "defaultValue-null:required-true:MANY-false:description-null\"},"
128 + "\"resource-model-symptomEntity\":"
129 + "{\"signaturesSymptom\":\"symptomElement:required-false:MANY-false:description-null\"}}");
130 testData.setAnnotation(
131 "alarmSignatures=matching-true, symptomContains=matching-true, symptomSignatures=matching-true, "
132 + "symptomTraversal=matching-true, symptomVnfType=matching-true, Contains=matching-true, "
133 + "SelectServerScope=matching-true, VnfType=matching-true, traversal=matching-true, "
134 + "logicalConnector=matching-true, ParentCorrelationTraversal=matching-true");
135 testData.setEnumValues("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
136 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures.symptomSignature"
137 + "[symptomVnfType, symptomContains, symptomFilterValue]");
138 testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
139 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
140 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
141 List<Object> microServiceModelsData = new ArrayList<Object>();
142 microServiceModelsData.add(testData);
144 // mock the getDataById() call
145 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName:version", "TESTMODEL" + ":" + "TODAY"))
146 .thenReturn(microServiceModelsData);
148 jsonString = "{\"policyData\":{\"error\":\"\",\"inprocess\":false,\"model\":{\"name\":\"DCAE\","
149 + "\"subScopename\":\"\",\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":"
150 + "\"2019-02-26 09:56:23.0\",\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":"
151 + "\"\",\"createdBy\":\"super-admin\",\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\","
152 + "\"content\":\"\",\"recursive\":false},\"tempModel\":{\"name\":\"DCAE\",\"subScopename\":\"\","
153 + "\"path\":[],\"type\":\"dir\",\"size\":0,\"createdDate\":\"2019-02-26 09:56:23.0\","
154 + "\"modifiedDate\":\"2019-02-26 09:56:23.0\",\"version\":\"\",\"createdBy\":\"super-admin\","
155 + "\"modifiedBy\":\"super-admin\",\"roleType\":\"super-admin\",\"content\":\"\","
156 + "\"recursive\":false},\"$$hashKey\":\"object:354\",\"policy\":{\"policyType\":\"Config\","
157 + "\"configPolicyType\":\"Micro Service\",\"serviceType\":\"TESTMODEL\",\"version\":\"TODAY\","
158 + "\"ruleGridData\":[\"Correlation Priority\",\"Correlation Window\","
159 + "\"Email Notification for failures\",\"Select Server Scope\","
160 + "\"Parent Correlation Name\",\"Parent Correlation Traversal\","
161 + "\"traversal\",\"FilterValue\"],\"policyName\":\"testttt\",\"onapName\":"
162 + "\"asdafadf\",\"guard\":\"True\",\"riskType\":\"sfsgs\",\"riskLevel\":\"1\","
163 + "\"priority\":\"1\",\"configName\":\"Search\",\"location\":\"Search\","
164 + "\"uuid\":\"Search\",\"policyScope\":\"PolicyScope_ssaaa123\"}},"
165 + "\"policyJSON\":{\"DCAEProcessingRules@0.processingRules_json\":"
166 + "\"eyJuYW1lIjogIkpvaG4iLCAiYWdlIjogIjI4IiwgImNpdHkiOiAiTmV3IFlvcmsifQ==\"}}";
168 configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\","
169 + "\"templateVersion\":\"1607\",\"version\":\"HD\",\"priority\":\"2\","
170 + "\"content\":{\"lastPolled\":\"1\",\"boolen-test\":\"true\",\"created\":\"test\","
171 + "\"retiredDate\":\"test\",\"scope\":\"SNIRO_PLACEMENT_VDHV\",\"name\":\"test\","
172 + "\"lastModified\":\"test\",\"state\":\"CREATED\",\"type\":\"CONFIG\",\"intent\":\"test\","
173 + "\"target\":\"SNIRO\"}}";
175 request = mock(HttpServletRequest.class);
176 BufferedReader br = new BufferedReader(new StringReader(jsonString));
177 // mock the getReader() call
178 when(request.getReader()).thenReturn(br);
180 logger.info("setUp: exit");
184 * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test.
188 public void testSetDataToPolicyRestAdapter() {
190 logger.debug("testSetDataToPolicyRestAdapter: enter");
192 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
194 JsonNode root = null;
195 ObjectMapper mapper = new ObjectMapper();
196 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
197 PolicyRestAdapter policyData = null;
199 root = JsonLoader.fromString(jsonString);
200 policyData = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
201 } catch (Exception e) {
202 logger.error("testSetDataToPolicyRestAdapter", e);
204 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
205 PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root);
206 assertTrue(result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty());
208 logger.debug("result.getJsonBody() : " + result.getJsonBody());
209 logger.debug("testSetDataToPolicyRestAdapter: exit");
213 * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, HttpServletResponse) method test.
217 public void testGetDcaeMsTemplateData() {
219 logger.debug("testGetDCAEMSTemplateData: enter");
221 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
222 MockHttpServletResponse response = new MockHttpServletResponse();
223 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
226 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
228 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
229 // mock the getReader() call
230 when(request.getReader()).thenReturn(br);
232 List<Object> microServiceModelsData = new ArrayList<Object>();
233 MicroServiceModels testData = new MicroServiceModels();
234 testData.setVersion("1707.4.1.2-Junit");
235 microServiceModelsData.add(testData);
236 // mock the getDataById() call with the same MS model name
237 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
238 .thenReturn(microServiceModelsData);
240 controller.getDCAEMSTemplateData(request, response);
243 response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData"));
245 logger.debug("response: " + response.getContentAsString());
247 } catch (Exception e) {
248 logger.error("testGetDCAEMSTemplateData", e);
251 logger.debug("testGetDCAEMSTemplateData: exit");
255 * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse) method test.
259 public void testGetModelServiceVersionData() {
261 logger.debug("testGetModelServiceVersionData: enter");
263 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
264 MockHttpServletResponse response = new MockHttpServletResponse();
265 String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
268 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
270 BufferedReader br = new BufferedReader(new StringReader(msModelJson));
271 // mock the getReader() call
272 when(request.getReader()).thenReturn(br);
274 List<Object> microServiceModelsData = new ArrayList<Object>();
275 MicroServiceModels testData = new MicroServiceModels();
276 testData.setVersion("1707.4.1.2-Junit");
277 microServiceModelsData.add(testData);
279 // mock the getDataById() call with the same MS model name
280 when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody"))
281 .thenReturn(microServiceModelsData);
282 controller.getModelServiceVersionData(request, response);
284 assertTrue(response.getContentAsString() != null
285 && response.getContentAsString().contains("1707.4.1.2-Junit"));
287 logger.debug("response: " + response.getContentAsString());
289 } catch (Exception e) {
290 logger.error("testGetModelServiceVersionData", e);
291 fail("testGetModelServiceVersionData failed due to: " + e);
294 logger.debug("testGetModelServiceVersionData: exit");
298 * Run the void getDCAEPriorityValuesData(HttpServletRequest, HttpServletResponse) method test.
302 public void testGetDcaePriorityValuesData() {
304 logger.debug("testGetDCAEPriorityValuesData: enter");
306 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
308 MockHttpServletRequest request = new MockHttpServletRequest();
309 MockHttpServletResponse response = new MockHttpServletResponse();
311 controller.getDCAEPriorityValuesData(request, response);
313 response.getContentAsString() != null && response.getContentAsString().contains("priorityDatas"));
314 logger.debug("response: " + response.getContentAsString());
315 } catch (Exception e) {
316 logger.error("testGetDCAEPriorityValuesData", e);
317 fail("testGetDCAEPriorityValuesData failed due to: " + e);
320 logger.debug("testGetDCAEPriorityValuesData: exit");
324 * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test.
328 public void testPrePopulateDcaeMsPolicyData() {
330 logger.debug("testPrePopulateDCAEMSPolicyData: enter");
332 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
334 // populate an entity object for testing
335 PolicyEntity entity = new PolicyEntity();
336 ConfigurationDataEntity configData = new ConfigurationDataEntity();
337 configData.setConfigBody(configBodyString);
338 entity.setConfigurationData(configData);
340 JsonNode root = null;
341 ObjectMapper mapper = new ObjectMapper();
342 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
343 PolicyRestAdapter restAdapter = null;
346 root = JsonLoader.fromString(jsonString);
347 restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
349 // create guard attribute
350 MatchType matchType = new MatchType();
352 AttributeValueType attributeValue1 = new AttributeValueType();
353 attributeValue1.getContent().add("True");
354 matchType.setAttributeValue(attributeValue1);
356 AttributeDesignatorType designator = new AttributeDesignatorType();
357 designator.setAttributeId("guard");
358 matchType.setAttributeDesignator(designator);
359 AllOfType alltype = new AllOfType();
360 alltype.getMatch().add(matchType);
362 // add a dummy MatchType object since while (matchList.size()>1 ...)
363 MatchType matchDummy = new MatchType();
365 AttributeValueType dummyValue = new AttributeValueType();
366 dummyValue.getContent().add("dummy");
367 matchDummy.setAttributeValue(dummyValue);
369 AttributeDesignatorType designatorDummy = new AttributeDesignatorType();
370 designatorDummy.setAttributeId("dummyId");
371 matchDummy.setAttributeDesignator(designatorDummy);
373 alltype.getMatch().add(matchDummy);
374 AnyOfType anyOfType = new AnyOfType();
375 anyOfType.getAllOf().add(alltype);
377 TargetType target = new TargetType();
378 target.getAnyOf().add(anyOfType);
380 // create RiskType attribute
381 AnyOfType anyRiskType = new AnyOfType();
382 AllOfType allRiskType = new AllOfType();
383 MatchType matchRiskType = new MatchType();
385 AttributeValueType riskTypeValue = new AttributeValueType();
386 riskTypeValue.getContent().add("test");
387 matchRiskType.setAttributeValue(riskTypeValue);
389 AttributeDesignatorType designatorRiskType = new AttributeDesignatorType();
390 designatorRiskType.setAttributeId("RiskType");
391 matchRiskType.setAttributeDesignator(designatorRiskType);
392 allRiskType.getMatch().add(matchRiskType);
394 // add a dummy MatchType object since while (matchList.size()>1 ...)
395 MatchType matchDummy1 = new MatchType();
397 AttributeValueType dummy1Value = new AttributeValueType();
398 dummy1Value.getContent().add("dummy");
399 matchDummy1.setAttributeValue(dummy1Value);
401 AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType();
402 designatorDummy1.setAttributeId("dummyId");
403 matchDummy1.setAttributeDesignator(designatorDummy1);
405 allRiskType.getMatch().add(matchDummy1);
407 anyRiskType.getAllOf().add(allRiskType);
409 target.getAnyOf().add(anyRiskType);
411 // create RiskLevel attribute
412 MatchType matchRiskLevel = new MatchType();
414 AttributeValueType riskLevel = new AttributeValueType();
415 riskLevel.getContent().add("3");
416 matchRiskLevel.setAttributeValue(riskLevel);
418 AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType();
419 designatorRiskLevel.setAttributeId("RiskLevel");
420 matchRiskLevel.setAttributeDesignator(designatorRiskLevel);
421 AllOfType allRiskLevel = new AllOfType();
422 allRiskLevel.getMatch().add(matchRiskLevel);
424 // add a dummy MatchType object since while (matchList.size()>1 ...)
425 MatchType matchDummy2 = new MatchType();
427 AttributeValueType dummy2Value = new AttributeValueType();
428 dummy2Value.getContent().add("dummy");
429 matchDummy2.setAttributeValue(dummy2Value);
431 AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType();
432 designatorDummy2.setAttributeId("dummyId");
433 matchDummy2.setAttributeDesignator(designatorDummy2);
435 allRiskLevel.getMatch().add(matchDummy2);
436 AnyOfType anyRiskLevel = new AnyOfType();
437 anyRiskLevel.getAllOf().add(allRiskLevel);
438 target.getAnyOf().add(anyRiskLevel);
439 PolicyType policyType = new PolicyType();
440 policyType.setTarget(target);
442 restAdapter.setPolicyData(policyType);
444 controller.prePopulateDCAEMSPolicyData(restAdapter, entity);
446 logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType());
447 logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel());
448 logger.error("restAdapter.getGuard() : " + restAdapter.getGuard());
450 assertEquals("True", restAdapter.getGuard());
451 assertEquals("3", restAdapter.getRiskLevel());
452 assertEquals("test", restAdapter.getRiskType());
454 } catch (Exception e) {
455 logger.error("testPrePopulateDCAEMSPolicyData", e);
456 fail("testPrePopulateDCAEMSPolicyData failed due to: " + e);
459 logger.debug("testPrePopulateDCAEMSPolicyData: exit");
464 * Run the Map<String,String> convert(String, String) method test.
468 public void testConvert() {
469 logger.debug("testConvert: enter");
471 String str = "k1=v1,k2=v2,k3=v3";
473 Map<String, String> result = new CreateDcaeMicroServiceController().convert(str, split);
474 assertTrue(result != null && result.size() == 3);
476 logger.debug("testConvert: exit");
480 * Run the Map<String,String> convertMap(Map<String,String>, Map<String,String>) method test.
484 public void testConvertMap() {
485 logger.debug("testConvertMap: enter");
486 Map<String, String> attributesMap = new HashMap<String, String>();
488 attributesMap.put("keyOne", "valueOne");
489 attributesMap.put("keyTwo", "valueTwo");
490 attributesMap.put("keyThree", "valueThree");
491 Map<String, String> attributesRefMap = new HashMap<String, String>();
493 attributesRefMap.put("key4", "value4");
494 attributesRefMap.put("key5", "value5");
495 attributesRefMap.put("key6", "value6");
496 CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
497 Map<String, String> attributesListRefMap = controller.getAttributesListRefMap();
498 LinkedList<String> list = new LinkedList<String>();
500 attributesListRefMap.put("key7", "value7");
504 Map<String, LinkedList<String>> arrayTextList = controller.getArrayTextList();
505 arrayTextList.put("key8", list);
507 Map<String, String> result = controller.convertMap(attributesMap, attributesRefMap);
509 assertTrue(result != null && result.size() == 8);
511 assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]"));
513 logger.debug("testConvertMap: exit");
517 * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test.
522 public void testSetMsModelData() {
524 logger.debug("testSetMSModelData: enter");
526 HttpServletRequest request = createMock(HttpServletRequest.class);
527 expect(request.getContentType())
528 .andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p");
529 expect(request.getMethod()).andReturn("post");
530 expect(request.getHeader("Content-length")).andReturn("7809");
532 expect(request.getContentLength()).andReturn(7809);
535 // value of fileName needs to be matched to your local directory
536 String fileName = "";
538 ClassLoader classLoader = getClass().getClassLoader();
539 fileName = new File(classLoader.getResource("schedulerPolicies-v1707.xmi").getFile()).getAbsolutePath();
540 } catch (Exception e1) {
541 logger.error("Exception Occured while loading file" + e1);
543 expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName));
544 expect(request.getCharacterEncoding()).andReturn("UTF-8");
545 expect(request.getContentLength()).andReturn(1024);
548 } catch (Exception e) {
549 logger.error("testSetMSModelData" + e);
553 logger.debug("testSetMSModelData: exit");
560 private class MockServletInputStream extends ServletInputStream {
562 InputStream fis = null;
564 public MockServletInputStream(String fileName) {
566 fis = new FileInputStream(fileName);
567 } catch (Exception genExe) {
568 genExe.printStackTrace();
573 public int read() throws IOException {
574 if (fis.available() > 0) {
581 public int read(byte[] bytes, int len, int size) throws IOException {
582 if (fis.available() > 0) {
583 int length = fis.read(bytes, len, size);
590 public boolean isFinished() {
595 public boolean isReady() {
600 public void setReadListener(ReadListener arg0) {