- logger.error("testGetDCAEPriorityValuesData", e);
- fail("testGetDCAEPriorityValuesData failed due to: " + e);
- }
-
- logger.debug("testGetDCAEPriorityValuesData: exit");
- }
-
- /**
- * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter,
- * PolicyEntity) method test
- */
-
- @Test
- public void testPrePopulateDCAEMSPolicyData() {
-
- logger.debug("testPrePopulateDCAEMSPolicyData: enter");
-
- CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
-
- // populate an entity object for testing
- PolicyEntity entity = new PolicyEntity();
- ConfigurationDataEntity configData = new ConfigurationDataEntity();
- configData.setConfigBody(configBodyString);
- entity.setConfigurationData(configData);
-
- JsonNode root = null;
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- PolicyRestAdapter restAdapter = null;
-
- try {
- root = JsonLoader.fromString(jsonString);
- restAdapter = (PolicyRestAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
- PolicyType policyType = new PolicyType();
- TargetType target = new TargetType();
-
- // create guard attribute
- AnyOfType anyOfType = new AnyOfType();
- AllOfType alltype = new AllOfType();
- MatchType matchType = new MatchType();
- // set value
- AttributeValueType attributeValue1 = new AttributeValueType();
- attributeValue1.getContent().add("True");
- matchType.setAttributeValue(attributeValue1);
+ logger.error("testSetDataToPolicyRestAdapter", e);
+ }
+
+ PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root);
+ assertTrue(
+ result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty());
+
+ logger.debug("result.getJsonBody() : " + result.getJsonBody());
+ logger.debug("testSetDataToPolicyRestAdapter: exit");
+ }
+
+ /**
+ * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, HttpServletResponse) method
+ * test
+ */
+
+ @Test
+ public void testGetDCAEMSTemplateData() {
+
+ logger.debug("testGetDCAEMSTemplateData: enter");
+
+ CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
+ try {
+
+ CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
+
+ BufferedReader br = new BufferedReader(new StringReader(msModelJson));
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+
+ List<Object> microServiceModelsData = new ArrayList<Object>();
+ MicroServiceModels testData = new MicroServiceModels();
+ testData.setVersion("1707.4.1.2-Junit");
+ microServiceModelsData.add(testData);
+ // mock the getDataById() call with the same MS model name
+ when(commonClassDao.getDataById(MicroServiceModels.class, "modelName",
+ "DkatPolicyBody")).thenReturn(microServiceModelsData);
+
+ controller.getDCAEMSTemplateData(request, response);
+
+ assertTrue(response.getContentAsString() != null
+ && response.getContentAsString().contains("dcaeModelData"));
+
+ logger.debug("response: " + response.getContentAsString());
+
+ } catch (Exception e) {
+ logger.error("testGetDCAEMSTemplateData", e);
+ }
+
+ logger.debug("testGetDCAEMSTemplateData: exit");
+ }
+
+ /**
+ * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse)
+ * method test
+ */
+
+ @Test
+ public void testGetModelServiceVersionData() {
+
+ logger.debug("testGetModelServiceVersionData: enter");
+
+ CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}";
+ try {
+
+ CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
+
+ BufferedReader br = new BufferedReader(new StringReader(msModelJson));
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+
+ List<Object> microServiceModelsData = new ArrayList<Object>();
+ MicroServiceModels testData = new MicroServiceModels();
+ testData.setVersion("1707.4.1.2-Junit");
+ microServiceModelsData.add(testData);
+
+ // mock the getDataById() call with the same MS model name
+ when(commonClassDao.getDataById(MicroServiceModels.class, "modelName",
+ "DkatPolicyBody")).thenReturn(microServiceModelsData);
+ controller.getModelServiceVersionData(request, response);
+
+ assertTrue(response.getContentAsString() != null
+ && response.getContentAsString().contains("1707.4.1.2-Junit"));
+
+ logger.debug("response: " + response.getContentAsString());
+
+ } catch (Exception e) {
+ logger.error("testGetModelServiceVersionData", e);
+ fail("testGetModelServiceVersionData failed due to: " + e);
+ }
+
+ logger.debug("testGetModelServiceVersionData: exit");
+ }
+
+ /**
+ * Run the void getDCAEPriorityValuesData(HttpServletRequest, HttpServletResponse) method test
+ */
+
+ @Test
+ public void testGetDCAEPriorityValuesData() {
+
+ logger.debug("testGetDCAEPriorityValuesData: enter");
+
+ CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
+
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ try {
+ controller.getDCAEPriorityValuesData(request, response);
+ assertTrue(response.getContentAsString() != null
+ && response.getContentAsString().contains("priorityDatas"));
+ logger.debug("response: " + response.getContentAsString());
+ } catch (Exception e) {
+ logger.error("testGetDCAEPriorityValuesData", e);
+ fail("testGetDCAEPriorityValuesData failed due to: " + e);
+ }
+
+ logger.debug("testGetDCAEPriorityValuesData: exit");
+ }
+
+ /**
+ * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test
+ */
+
+ @Test
+ public void testPrePopulateDCAEMSPolicyData() {
+
+ logger.debug("testPrePopulateDCAEMSPolicyData: enter");
+
+ CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController();
+
+ // populate an entity object for testing
+ PolicyEntity entity = new PolicyEntity();
+ ConfigurationDataEntity configData = new ConfigurationDataEntity();
+ configData.setConfigBody(configBodyString);
+ entity.setConfigurationData(configData);
+
+ JsonNode root = null;
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ PolicyRestAdapter restAdapter = null;
+
+ try {
+ root = JsonLoader.fromString(jsonString);
+ restAdapter = (PolicyRestAdapter) mapper.readValue(
+ root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
+ PolicyType policyType = new PolicyType();
+ TargetType target = new TargetType();
+
+ // create guard attribute
+ AnyOfType anyOfType = new AnyOfType();
+ AllOfType alltype = new AllOfType();
+ MatchType matchType = new MatchType();
+ // set value
+ AttributeValueType attributeValue1 = new AttributeValueType();
+ attributeValue1.getContent().add("True");
+ matchType.setAttributeValue(attributeValue1);