@Test public void testcheckPredefine() throws Exception { Class<UpdateNode> class1 = UpdateNode.class; Method method = class1.getDeclaredMethod("checkPredefine", new Class[]{List.class}); method.setAccessible(true); when(property.getPropertyName()).thenReturn(propertyName); when(property.getPropertyName().getValue()).thenReturn(new String("mac-address")); when(property.getPropertyValues()).thenReturn(propertyValues); when(property.getPropertyValues().getStringValue()).thenReturn(stringValues); when(stringValue.getValue()).thenReturn(new String("test")); when(valueCheck.checkMac(stringValue.getValue())).thenReturn(false); Assert.assertEquals(method.invoke(updateNode, propertyList), "The mac-address is not legal."); when(property.getPropertyName().getValue()).thenReturn(new String("ip-address")); when(property.getPropertyValues().getStringValue()).thenReturn(stringValues); when(stringValue.getValue()).thenReturn(new String("/")); when(valueCheck.checkIpPrefix(stringValue.getValue())).thenReturn(false); Assert.assertEquals(method.invoke(updateNode, propertyList), "The ip-address is not legal."); when(property.getPropertyName().getValue()).thenReturn(new String("gateway-ip")); when(property.getPropertyValues().getStringValue()).thenReturn(stringValues); when(valueCheck.checkIpAddress(stringValue.getValue())).thenReturn(false); Assert.assertEquals(method.invoke(updateNode, propertyList), "The gateway-ip is not legal."); when(property.getPropertyName().getValue()).thenReturn(new String("ac-info-network")); when(property.getPropertyValues().getStringValue()).thenReturn(stringValues); when(stringValue.getValue()).thenReturn(new String("layer4")); Assert.assertEquals(method.invoke(updateNode, propertyList), "The ac-info-network is not legal."); when(property.getPropertyName().getValue()).thenReturn(new String("operating-mode")); when(property.getPropertyValues().getStringValue()).thenReturn(stringValues); when(stringValue.getValue()).thenReturn(new String("layer4")); Assert.assertEquals(method.invoke(updateNode, propertyList), "The operating-mode is not legal."); }
private String checkPredefine(List<Property> nodeProperties){ String errorInfo = null; for (Property property : nodeProperties){ if (property.getPropertyName().getValue().equals(NEMOConstants.mac_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkMac(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ip_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (stringValue.getValue().contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValue.getValue()); } else { legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.gateway_ip)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.gateway_ip + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ac_info_network)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.ac_info_network + " is not legal."; } } } if (property.getPropertyName().getValue().equals(NEMOConstants.operating_mode)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.operating_mode + " is not legal."; } } } } return errorInfo; }
UpdateNode { private String checkPredefine(List<Property> nodeProperties){ String errorInfo = null; for (Property property : nodeProperties){ if (property.getPropertyName().getValue().equals(NEMOConstants.mac_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkMac(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ip_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (stringValue.getValue().contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValue.getValue()); } else { legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.gateway_ip)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.gateway_ip + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ac_info_network)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.ac_info_network + " is not legal."; } } } if (property.getPropertyName().getValue().equals(NEMOConstants.operating_mode)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.operating_mode + " is not legal."; } } } } return errorInfo; } }
UpdateNode { private String checkPredefine(List<Property> nodeProperties){ String errorInfo = null; for (Property property : nodeProperties){ if (property.getPropertyName().getValue().equals(NEMOConstants.mac_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkMac(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ip_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (stringValue.getValue().contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValue.getValue()); } else { legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.gateway_ip)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.gateway_ip + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ac_info_network)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.ac_info_network + " is not legal."; } } } if (property.getPropertyName().getValue().equals(NEMOConstants.operating_mode)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.operating_mode + " is not legal."; } } } } return errorInfo; } UpdateNode(DataBroker dataBroker,TenantManage tenantManage); }
UpdateNode { private String checkPredefine(List<Property> nodeProperties){ String errorInfo = null; for (Property property : nodeProperties){ if (property.getPropertyName().getValue().equals(NEMOConstants.mac_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkMac(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ip_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (stringValue.getValue().contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValue.getValue()); } else { legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.gateway_ip)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.gateway_ip + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ac_info_network)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.ac_info_network + " is not legal."; } } } if (property.getPropertyName().getValue().equals(NEMOConstants.operating_mode)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.operating_mode + " is not legal."; } } } } return errorInfo; } UpdateNode(DataBroker dataBroker,TenantManage tenantManage); String NodeHandling(UserId userId,Node node); }
UpdateNode { private String checkPredefine(List<Property> nodeProperties){ String errorInfo = null; for (Property property : nodeProperties){ if (property.getPropertyName().getValue().equals(NEMOConstants.mac_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkMac(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ip_address)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (stringValue.getValue().contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValue.getValue()); } else { legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.gateway_ip)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ legalValue = valueCheck.checkIpAddress(stringValue.getValue()); } if (!legalValue){ errorInfo = "The " + NEMOConstants.gateway_ip + " is not legal."; } } if (property.getPropertyName().getValue().equals(NEMOConstants.ac_info_network)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.ac_info_network + " is not legal."; } } } if (property.getPropertyName().getValue().equals(NEMOConstants.operating_mode)){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); Boolean legalValue = true; for (StringValue stringValue : stringValues){ if (!(stringValue.getValue().equals(NEMOConstants.layer2)||stringValue.getValue().equals(NEMOConstants.layer3))){ errorInfo = "The " + NEMOConstants.operating_mode + " is not legal."; } } } } return errorInfo; } UpdateNode(DataBroker dataBroker,TenantManage tenantManage); String NodeHandling(UserId userId,Node node);  }