@Test public void testcheckProperty() throws Exception { Class<UpdateNode> class1 = UpdateNode.class; Method method = class1.getDeclaredMethod("checkProperty", new Class[]{List.class, List.class}); method.setAccessible(true); when(property.getPropertyName()).thenReturn(propertyName); when(propertyDefinition.getPropertyName()).thenReturn(propertyName2); when(property.getPropertyName().getValue()).thenReturn(new String("propertyname")); Assert.assertEquals(method.invoke(updateNode, propertyList,propertyDefinitions), "The property propertyname has not been defined."); }
private String checkProperty(List<Property> nodeProperties, List<PropertyDefinition> nodePropertyDefinitions){ Boolean propertyHasDefine = false; String errorInfo = null; for (Property property : nodeProperties){ if (errorInfo != null){ break; } else{ for (PropertyDefinition propertydefinition : nodePropertyDefinitions){ if (property.getPropertyName().equals(propertydefinition.getPropertyName())){ propertyHasDefine = true; PropertyValues propertyValues = property.getPropertyValues(); PropertyDefinition.PropertyValueType propertyValueType = propertydefinition.getPropertyValueType(); if (propertyValues != null && propertyValueType != null){ if (propertydefinition.getIsReadOnly()!=null && PropertyDefinition.IsReadOnly.ReadOnly == propertydefinition.getIsReadOnly()){ if (propertydefinition.getIsRequired().getIntValue() == 1){ errorInfo = "The property "+ property.getPropertyName().getValue()+" is readonly, can not be written."; break; } } else if (propertyValueType.getIntValue() == 0 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() != null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be string"; break; } else if (propertyValueType.getIntValue() == 1 && !(propertyValues.getIntValue() != null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be integer"; break; } else if (propertyValueType.getIntValue() == 2 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() != null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be range"; break; } } } } if (!propertyHasDefine){ errorInfo = "The property "+property.getPropertyName().getValue()+" has not been defined."; } } } if (errorInfo == null){ Boolean requiredProperty = false; for (PropertyDefinition propertyDefinition : nodePropertyDefinitions){ if (propertyDefinition.getIsRequired()!=null){ if (propertyDefinition.getIsRequired().getIntValue() ==0){ for (Property property: nodeProperties){ if (property.getPropertyName().equals(propertyDefinition.getPropertyName())){ requiredProperty = true; } } if (!requiredProperty){ errorInfo = "The required property "+ propertyDefinition.getPropertyName().getValue() + " is not included in the intent."; break; } } } } } return errorInfo; }
UpdateNode { private String checkProperty(List<Property> nodeProperties, List<PropertyDefinition> nodePropertyDefinitions){ Boolean propertyHasDefine = false; String errorInfo = null; for (Property property : nodeProperties){ if (errorInfo != null){ break; } else{ for (PropertyDefinition propertydefinition : nodePropertyDefinitions){ if (property.getPropertyName().equals(propertydefinition.getPropertyName())){ propertyHasDefine = true; PropertyValues propertyValues = property.getPropertyValues(); PropertyDefinition.PropertyValueType propertyValueType = propertydefinition.getPropertyValueType(); if (propertyValues != null && propertyValueType != null){ if (propertydefinition.getIsReadOnly()!=null && PropertyDefinition.IsReadOnly.ReadOnly == propertydefinition.getIsReadOnly()){ if (propertydefinition.getIsRequired().getIntValue() == 1){ errorInfo = "The property "+ property.getPropertyName().getValue()+" is readonly, can not be written."; break; } } else if (propertyValueType.getIntValue() == 0 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() != null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be string"; break; } else if (propertyValueType.getIntValue() == 1 && !(propertyValues.getIntValue() != null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be integer"; break; } else if (propertyValueType.getIntValue() == 2 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() != null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be range"; break; } } } } if (!propertyHasDefine){ errorInfo = "The property "+property.getPropertyName().getValue()+" has not been defined."; } } } if (errorInfo == null){ Boolean requiredProperty = false; for (PropertyDefinition propertyDefinition : nodePropertyDefinitions){ if (propertyDefinition.getIsRequired()!=null){ if (propertyDefinition.getIsRequired().getIntValue() ==0){ for (Property property: nodeProperties){ if (property.getPropertyName().equals(propertyDefinition.getPropertyName())){ requiredProperty = true; } } if (!requiredProperty){ errorInfo = "The required property "+ propertyDefinition.getPropertyName().getValue() + " is not included in the intent."; break; } } } } } return errorInfo; } }
UpdateNode { private String checkProperty(List<Property> nodeProperties, List<PropertyDefinition> nodePropertyDefinitions){ Boolean propertyHasDefine = false; String errorInfo = null; for (Property property : nodeProperties){ if (errorInfo != null){ break; } else{ for (PropertyDefinition propertydefinition : nodePropertyDefinitions){ if (property.getPropertyName().equals(propertydefinition.getPropertyName())){ propertyHasDefine = true; PropertyValues propertyValues = property.getPropertyValues(); PropertyDefinition.PropertyValueType propertyValueType = propertydefinition.getPropertyValueType(); if (propertyValues != null && propertyValueType != null){ if (propertydefinition.getIsReadOnly()!=null && PropertyDefinition.IsReadOnly.ReadOnly == propertydefinition.getIsReadOnly()){ if (propertydefinition.getIsRequired().getIntValue() == 1){ errorInfo = "The property "+ property.getPropertyName().getValue()+" is readonly, can not be written."; break; } } else if (propertyValueType.getIntValue() == 0 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() != null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be string"; break; } else if (propertyValueType.getIntValue() == 1 && !(propertyValues.getIntValue() != null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be integer"; break; } else if (propertyValueType.getIntValue() == 2 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() != null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be range"; break; } } } } if (!propertyHasDefine){ errorInfo = "The property "+property.getPropertyName().getValue()+" has not been defined."; } } } if (errorInfo == null){ Boolean requiredProperty = false; for (PropertyDefinition propertyDefinition : nodePropertyDefinitions){ if (propertyDefinition.getIsRequired()!=null){ if (propertyDefinition.getIsRequired().getIntValue() ==0){ for (Property property: nodeProperties){ if (property.getPropertyName().equals(propertyDefinition.getPropertyName())){ requiredProperty = true; } } if (!requiredProperty){ errorInfo = "The required property "+ propertyDefinition.getPropertyName().getValue() + " is not included in the intent."; break; } } } } } return errorInfo; } UpdateNode(DataBroker dataBroker,TenantManage tenantManage); }
UpdateNode { private String checkProperty(List<Property> nodeProperties, List<PropertyDefinition> nodePropertyDefinitions){ Boolean propertyHasDefine = false; String errorInfo = null; for (Property property : nodeProperties){ if (errorInfo != null){ break; } else{ for (PropertyDefinition propertydefinition : nodePropertyDefinitions){ if (property.getPropertyName().equals(propertydefinition.getPropertyName())){ propertyHasDefine = true; PropertyValues propertyValues = property.getPropertyValues(); PropertyDefinition.PropertyValueType propertyValueType = propertydefinition.getPropertyValueType(); if (propertyValues != null && propertyValueType != null){ if (propertydefinition.getIsReadOnly()!=null && PropertyDefinition.IsReadOnly.ReadOnly == propertydefinition.getIsReadOnly()){ if (propertydefinition.getIsRequired().getIntValue() == 1){ errorInfo = "The property "+ property.getPropertyName().getValue()+" is readonly, can not be written."; break; } } else if (propertyValueType.getIntValue() == 0 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() != null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be string"; break; } else if (propertyValueType.getIntValue() == 1 && !(propertyValues.getIntValue() != null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be integer"; break; } else if (propertyValueType.getIntValue() == 2 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() != null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be range"; break; } } } } if (!propertyHasDefine){ errorInfo = "The property "+property.getPropertyName().getValue()+" has not been defined."; } } } if (errorInfo == null){ Boolean requiredProperty = false; for (PropertyDefinition propertyDefinition : nodePropertyDefinitions){ if (propertyDefinition.getIsRequired()!=null){ if (propertyDefinition.getIsRequired().getIntValue() ==0){ for (Property property: nodeProperties){ if (property.getPropertyName().equals(propertyDefinition.getPropertyName())){ requiredProperty = true; } } if (!requiredProperty){ errorInfo = "The required property "+ propertyDefinition.getPropertyName().getValue() + " is not included in the intent."; break; } } } } } return errorInfo; } UpdateNode(DataBroker dataBroker,TenantManage tenantManage); String NodeHandling(UserId userId,Node node); }
UpdateNode { private String checkProperty(List<Property> nodeProperties, List<PropertyDefinition> nodePropertyDefinitions){ Boolean propertyHasDefine = false; String errorInfo = null; for (Property property : nodeProperties){ if (errorInfo != null){ break; } else{ for (PropertyDefinition propertydefinition : nodePropertyDefinitions){ if (property.getPropertyName().equals(propertydefinition.getPropertyName())){ propertyHasDefine = true; PropertyValues propertyValues = property.getPropertyValues(); PropertyDefinition.PropertyValueType propertyValueType = propertydefinition.getPropertyValueType(); if (propertyValues != null && propertyValueType != null){ if (propertydefinition.getIsReadOnly()!=null && PropertyDefinition.IsReadOnly.ReadOnly == propertydefinition.getIsReadOnly()){ if (propertydefinition.getIsRequired().getIntValue() == 1){ errorInfo = "The property "+ property.getPropertyName().getValue()+" is readonly, can not be written."; break; } } else if (propertyValueType.getIntValue() == 0 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() != null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be string"; break; } else if (propertyValueType.getIntValue() == 1 && !(propertyValues.getIntValue() != null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() == null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be integer"; break; } else if (propertyValueType.getIntValue() == 2 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() != null)){ errorInfo = "The property value type "+property.getPropertyName().getValue()+" should be range"; break; } } } } if (!propertyHasDefine){ errorInfo = "The property "+property.getPropertyName().getValue()+" has not been defined."; } } } if (errorInfo == null){ Boolean requiredProperty = false; for (PropertyDefinition propertyDefinition : nodePropertyDefinitions){ if (propertyDefinition.getIsRequired()!=null){ if (propertyDefinition.getIsRequired().getIntValue() ==0){ for (Property property: nodeProperties){ if (property.getPropertyName().equals(propertyDefinition.getPropertyName())){ requiredProperty = true; } } if (!requiredProperty){ errorInfo = "The required property "+ propertyDefinition.getPropertyName().getValue() + " is not included in the intent."; break; } } } } } return errorInfo; } UpdateNode(DataBroker dataBroker,TenantManage tenantManage); String NodeHandling(UserId userId,Node node);  }