@Test public void testcheckPredefine() throws Exception { Class<UpdateFlow> class1 = UpdateFlow.class; Method method = class1.getDeclaredMethod("checkPredefine",new Class[]{List.class}); method.setAccessible(true); when(matchItem.getMatchItemName()).thenReturn(matchItemName); when(matchItem.getMatchItemName().getValue()).thenReturn(new String("src-ip")); when(matchItem.getMatchItemValue()).thenReturn(matchItemValue); when(matchItem.getMatchItemValue().getStringValue()).thenReturn(new String("110/")); Assert.assertEquals(method.invoke(updateFlow, matchItemList),"The " + NEMOConstants.ip_address + " is not legal."); when(matchItem.getMatchItemValue().getStringValue()).thenReturn(new String("110\\.")); Assert.assertEquals(method.invoke(updateFlow, matchItemList),"The " + NEMOConstants.ip_address + " is not legal."); when(matchItem.getMatchItemName().getValue()).thenReturn(new String("src-mac")); when(matchItem.getMatchItemValue()).thenReturn(matchItemValue); when(matchItem.getMatchItemValue().getStringValue()).thenReturn(new String("110:")); Assert.assertEquals(method.invoke(updateFlow, matchItemList), "The " + NEMOConstants.mac_address + " is not legal."); }
private String checkPredefine(List<MatchItem> matchItems){ String errorInfo = null; for (MatchItem matchItem :matchItems){ if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_ip)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_ip)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = true; if (stringValues.contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValues); } else { legalValue = valueCheck.checkIpAddress(stringValues); } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_mac)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_mac)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = valueCheck.checkMac(stringValues); if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } } return errorInfo; }
UpdateFlow { private String checkPredefine(List<MatchItem> matchItems){ String errorInfo = null; for (MatchItem matchItem :matchItems){ if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_ip)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_ip)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = true; if (stringValues.contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValues); } else { legalValue = valueCheck.checkIpAddress(stringValues); } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_mac)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_mac)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = valueCheck.checkMac(stringValues); if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } } return errorInfo; } }
UpdateFlow { private String checkPredefine(List<MatchItem> matchItems){ String errorInfo = null; for (MatchItem matchItem :matchItems){ if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_ip)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_ip)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = true; if (stringValues.contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValues); } else { legalValue = valueCheck.checkIpAddress(stringValues); } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_mac)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_mac)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = valueCheck.checkMac(stringValues); if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } } return errorInfo; } UpdateFlow(DataBroker dataBroker, TenantManage tenantManage); }
UpdateFlow { private String checkPredefine(List<MatchItem> matchItems){ String errorInfo = null; for (MatchItem matchItem :matchItems){ if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_ip)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_ip)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = true; if (stringValues.contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValues); } else { legalValue = valueCheck.checkIpAddress(stringValues); } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_mac)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_mac)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = valueCheck.checkMac(stringValues); if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } } return errorInfo; } UpdateFlow(DataBroker dataBroker, TenantManage tenantManage); String FlowHandling(UserId userId, Flow flow); }
UpdateFlow { private String checkPredefine(List<MatchItem> matchItems){ String errorInfo = null; for (MatchItem matchItem :matchItems){ if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_ip)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_ip)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = true; if (stringValues.contains("/")){ legalValue = valueCheck.checkIpPrefix(stringValues); } else { legalValue = valueCheck.checkIpAddress(stringValues); } if (!legalValue){ errorInfo = "The " + NEMOConstants.ip_address + " is not legal."; } } if (matchItem.getMatchItemName().getValue().equals(NEMOConstants.src_mac)||matchItem.getMatchItemName().getValue().equals(NEMOConstants.dst_mac)){ String stringValues = matchItem.getMatchItemValue().getStringValue(); Boolean legalValue = valueCheck.checkMac(stringValues); if (!legalValue){ errorInfo = "The " + NEMOConstants.mac_address + " is not legal."; } } } return errorInfo; } UpdateFlow(DataBroker dataBroker, TenantManage tenantManage); String FlowHandling(UserId userId, Flow flow);  }