- AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType();
- designatorDummy2.setAttributeId("dummyId");
- matchDummy2.setAttributeDesignator(designatorDummy2);
-
- allRiskLevel.getMatch().add(matchDummy2);
-
- anyRiskLevel.getAllOf().add(allRiskLevel);
- target.getAnyOf().add(anyRiskLevel);
-
- policyType.setTarget(target);
-
- restAdapter.setPolicyData(policyType);
-
- controller.prePopulateDCAEMSPolicyData(restAdapter, entity);
-
- logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType());
- logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel());
- logger.error("restAdapter.getGuard() : " + restAdapter.getGuard());
-
- assertEquals("True", restAdapter.getGuard());
- assertEquals("3", restAdapter.getRiskLevel());
- assertEquals("test", restAdapter.getRiskType());
-
- } catch (Exception e) {
- logger.error("testPrePopulateDCAEMSPolicyData", e);
- fail("testPrePopulateDCAEMSPolicyData failed due to: " + e);
- }
-
- logger.debug("testPrePopulateDCAEMSPolicyData: exit");
-
- }
-
- /**
- * Run the Map<String,String> convert(String, String) method test
- */
-
- @Test
- public void testConvert(){
- logger.debug("testConvert: enter");
-
- String str = "k1=v1,k2=v2,k3=v3";
- String split = ",";
- Map<String,String> result = CreateDcaeMicroServiceController.convert(str, split);
- assertTrue(result != null && result.size() == 3);
-
- logger.debug("testConvert: exit");
- }
-
- /**
- * Run the Map<String,String> convertMap(Map<String,String>,
- * Map<String,String>) method test
- */
-
- @Test
- public void testConvertMap(){
- logger.debug("testConvertMap: enter");
-
- CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
- Map<String,String> attributesMap = new HashMap<String, String>();
- Map<String,String> attributesRefMap = new HashMap<String, String>();
- Map<String,String> attributesListRefMap = controller.getAttributesListRefMap();
- Map<String, LinkedList<String>> arrayTextList = controller.getArrayTextList();
- LinkedList<String> list = new LinkedList<String>();
-
- attributesMap.put("keyOne", "valueOne");
- attributesMap.put("keyTwo", "valueTwo");
- attributesMap.put("keyThree", "valueThree");
-
- attributesRefMap.put("key4", "value4");
- attributesRefMap.put("key5", "value5");
- attributesRefMap.put("key6", "value6");
-
- attributesListRefMap.put("key7", "value7");
-
- list.add("l1");
- list.add("l2");
- arrayTextList.put("key8", list);
-
- Map<String,String> result = controller.convertMap(attributesMap, attributesRefMap);
-
- assertTrue(result != null && result.size() == 8);
-
- assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]"));
-
- logger.debug("testConvertMap: exit");
- }
-
- /**
- * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse)
- * method test
- */
-
- //@Ignore
- @Test
- public void testSetMSModelData() {
-
- logger.debug("testSetMSModelData: enter");
-
- CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- HttpServletRequest request = createMock(HttpServletRequest.class);
- expect(request.getContentType()).andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p");
- expect(request.getMethod()).andReturn("post");
- expect(request.getHeader("Content-length")).andReturn("7809");
-
- expect(request.getContentLength()).andReturn(7809);
-
- try {
- // value of fileName needs to be matched to your local directory
- String fileName = "";
- try {
- ClassLoader classLoader = getClass().getClassLoader();
- fileName = new File(classLoader.getResource("schedulerPolicies-v1707.xmi").getFile()).getAbsolutePath();
- } catch (Exception e1) {
- logger.error("Exception Occured while loading file"+e1);
- }
- expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName));
- expect(request.getCharacterEncoding()).andReturn("UTF-8");
- expect(request.getContentLength()).andReturn(1024);
- replay(request);
-
- } catch (Exception e) {
- logger.error("testSetMSModelData" + e);
- e.printStackTrace();
- }
-
- //assertTrue(false);
-
- logger.debug("testSetMSModelData: exit");
- }
-
- /**
- *
- * @ Get File Stream
- *
- */
- private class MockServletInputStream extends ServletInputStream {
-
- InputStream fis = null;
- public MockServletInputStream(String fileName) {
- try {
- fis = new FileInputStream(fileName);
- } catch (Exception genExe) {
- genExe.printStackTrace();
- }
- }
- @Override
- public int read() throws IOException {
- if(fis.available() > 0) {
- return fis.read();
- }
- return 0;
- }
-
- @Override
- public int read(byte[] bytes, int len, int size) throws IOException {
- if(fis.available() > 0) {
- int length = fis.read(bytes, len, size);
- return length;
- }
- return -1;
- }
- @Override
- public boolean isFinished() {
- return false;
- }
- @Override
- public boolean isReady() {
- return false;
- }
- @Override
- public void setReadListener(ReadListener arg0) {
-
- }
- }
-
-}
\ No newline at end of file
+ AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType();
+ designatorDummy2.setAttributeId("dummyId");
+ matchDummy2.setAttributeDesignator(designatorDummy2);
+
+ allRiskLevel.getMatch().add(matchDummy2);
+
+ anyRiskLevel.getAllOf().add(allRiskLevel);
+ target.getAnyOf().add(anyRiskLevel);
+
+ policyType.setTarget(target);
+
+ restAdapter.setPolicyData(policyType);
+
+ controller.prePopulateDCAEMSPolicyData(restAdapter, entity);
+
+ logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType());
+ logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel());
+ logger.error("restAdapter.getGuard() : " + restAdapter.getGuard());
+
+ assertEquals("True", restAdapter.getGuard());
+ assertEquals("3", restAdapter.getRiskLevel());
+ assertEquals("test", restAdapter.getRiskType());
+
+ } catch (Exception e) {
+ logger.error("testPrePopulateDCAEMSPolicyData", e);
+ fail("testPrePopulateDCAEMSPolicyData failed due to: " + e);
+ }
+
+ logger.debug("testPrePopulateDCAEMSPolicyData: exit");
+
+ }
+
+ /**
+ * Run the Map<String,String> convert(String, String) method test
+ */
+
+ @Test
+ public void testConvert() {
+ logger.debug("testConvert: enter");
+
+ String str = "k1=v1,k2=v2,k3=v3";
+ String split = ",";
+ Map<String, String> result = CreateDcaeMicroServiceController.convert(str, split);
+ assertTrue(result != null && result.size() == 3);
+
+ logger.debug("testConvert: exit");
+ }
+
+ /**
+ * Run the Map<String,String> convertMap(Map<String,String>, Map<String,String>) method test
+ */
+
+ @Test
+ public void testConvertMap() {
+ logger.debug("testConvertMap: enter");
+
+ CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
+ Map<String, String> attributesMap = new HashMap<String, String>();
+ Map<String, String> attributesRefMap = new HashMap<String, String>();
+ Map<String, String> attributesListRefMap = controller.getAttributesListRefMap();
+ Map<String, LinkedList<String>> arrayTextList = controller.getArrayTextList();
+ LinkedList<String> list = new LinkedList<String>();
+
+ attributesMap.put("keyOne", "valueOne");
+ attributesMap.put("keyTwo", "valueTwo");
+ attributesMap.put("keyThree", "valueThree");
+
+ attributesRefMap.put("key4", "value4");
+ attributesRefMap.put("key5", "value5");
+ attributesRefMap.put("key6", "value6");
+
+ attributesListRefMap.put("key7", "value7");
+
+ list.add("l1");
+ list.add("l2");
+ arrayTextList.put("key8", list);
+
+ Map<String, String> result = controller.convertMap(attributesMap, attributesRefMap);
+
+ assertTrue(result != null && result.size() == 8);
+
+ assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]"));
+
+ logger.debug("testConvertMap: exit");
+ }
+
+ /**
+ * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test
+ */
+
+ // @Ignore
+ @Test
+ public void testSetMSModelData() {
+
+ logger.debug("testSetMSModelData: enter");
+
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ expect(request.getContentType())
+ .andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p");
+ expect(request.getMethod()).andReturn("post");
+ expect(request.getHeader("Content-length")).andReturn("7809");
+
+ expect(request.getContentLength()).andReturn(7809);
+
+ try {
+ // value of fileName needs to be matched to your local directory
+ String fileName = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ fileName =
+ new File(classLoader.getResource("schedulerPolicies-v1707.xmi").getFile())
+ .getAbsolutePath();
+ } catch (Exception e1) {
+ logger.error("Exception Occured while loading file" + e1);
+ }
+ expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName));
+ expect(request.getCharacterEncoding()).andReturn("UTF-8");
+ expect(request.getContentLength()).andReturn(1024);
+ replay(request);
+
+ } catch (Exception e) {
+ logger.error("testSetMSModelData" + e);
+ e.printStackTrace();
+ }
+
+ logger.debug("testSetMSModelData: exit");
+ }
+
+ /**
+ *
+ * @ Get File Stream
+ *
+ */
+ private class MockServletInputStream extends ServletInputStream {
+
+ InputStream fis = null;
+
+ public MockServletInputStream(String fileName) {
+ try {
+ fis = new FileInputStream(fileName);
+ } catch (Exception genExe) {
+ genExe.printStackTrace();
+ }
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (fis.available() > 0) {
+ return fis.read();
+ }
+ return 0;
+ }
+
+ @Override
+ public int read(byte[] bytes, int len, int size) throws IOException {
+ if (fis.available() > 0) {
+ int length = fis.read(bytes, len, size);
+ return length;
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean isFinished() {
+ return false;
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setReadListener(ReadListener arg0) {
+
+ }
+ }
+}