@Test(groups="checkintest") public void validateStringCOctetStringWithByteArray() throws Exception { StringValidator.validateString("".getBytes("UTF-8"), StringParameter.SYSTEM_ID); StringValidator.validateString("System ID".getBytes("UTF-8"), StringParameter.SYSTEM_ID); StringValidator.validateString("123456789012345".getBytes("UTF-8"), StringParameter.SYSTEM_ID); try { StringValidator.validateString("1234567890123456".getBytes("UTF-8"), StringParameter.SYSTEM_ID); fail("PDUStringException expected"); } catch (PDUStringException e) { assertEquals(e.getMessage(), "C-Octet String value '1234567890123456' length must be less than 16. " + "Actual length is 16"); } }
public static void validateString(String value, StringParameter param) throws PDUStringException { if (param.getType() == StringType.C_OCTET_STRING) { if (param.isRangeMinAndMax()) { if (!isCOctetStringValid(value, param.getMax())) { throw new PDUStringException(C_OCTET_STRING_VALUE + value + "' length must be less than " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } else if (!isCOctetStringNullOrNValValid(value, param.getMax())) { throw new PDUStringException( C_OCTET_STRING_VALUE + value + "' length should be 1 or " + (param.getMax() - 1) + ACTUAL_LENGTH_IS + value.length(), param); } } else if (param.getType() == StringType.OCTET_STRING && !isOctetStringValid(value, param.getMax())) { throw new PDUStringException("Octet String value '" + value + "' length must be less than or equal to " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } }
StringValidator { public static void validateString(String value, StringParameter param) throws PDUStringException { if (param.getType() == StringType.C_OCTET_STRING) { if (param.isRangeMinAndMax()) { if (!isCOctetStringValid(value, param.getMax())) { throw new PDUStringException(C_OCTET_STRING_VALUE + value + "' length must be less than " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } else if (!isCOctetStringNullOrNValValid(value, param.getMax())) { throw new PDUStringException( C_OCTET_STRING_VALUE + value + "' length should be 1 or " + (param.getMax() - 1) + ACTUAL_LENGTH_IS + value.length(), param); } } else if (param.getType() == StringType.OCTET_STRING && !isOctetStringValid(value, param.getMax())) { throw new PDUStringException("Octet String value '" + value + "' length must be less than or equal to " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } }
StringValidator { public static void validateString(String value, StringParameter param) throws PDUStringException { if (param.getType() == StringType.C_OCTET_STRING) { if (param.isRangeMinAndMax()) { if (!isCOctetStringValid(value, param.getMax())) { throw new PDUStringException(C_OCTET_STRING_VALUE + value + "' length must be less than " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } else if (!isCOctetStringNullOrNValValid(value, param.getMax())) { throw new PDUStringException( C_OCTET_STRING_VALUE + value + "' length should be 1 or " + (param.getMax() - 1) + ACTUAL_LENGTH_IS + value.length(), param); } } else if (param.getType() == StringType.OCTET_STRING && !isOctetStringValid(value, param.getMax())) { throw new PDUStringException("Octet String value '" + value + "' length must be less than or equal to " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } private  StringValidator(); }
StringValidator { public static void validateString(String value, StringParameter param) throws PDUStringException { if (param.getType() == StringType.C_OCTET_STRING) { if (param.isRangeMinAndMax()) { if (!isCOctetStringValid(value, param.getMax())) { throw new PDUStringException(C_OCTET_STRING_VALUE + value + "' length must be less than " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } else if (!isCOctetStringNullOrNValValid(value, param.getMax())) { throw new PDUStringException( C_OCTET_STRING_VALUE + value + "' length should be 1 or " + (param.getMax() - 1) + ACTUAL_LENGTH_IS + value.length(), param); } } else if (param.getType() == StringType.OCTET_STRING && !isOctetStringValid(value, param.getMax())) { throw new PDUStringException("Octet String value '" + value + "' length must be less than or equal to " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } private  StringValidator(); static void validateString(String value, StringParameter param); static void validateString(byte[] value, StringParameter param); }
StringValidator { public static void validateString(String value, StringParameter param) throws PDUStringException { if (param.getType() == StringType.C_OCTET_STRING) { if (param.isRangeMinAndMax()) { if (!isCOctetStringValid(value, param.getMax())) { throw new PDUStringException(C_OCTET_STRING_VALUE + value + "' length must be less than " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } else if (!isCOctetStringNullOrNValValid(value, param.getMax())) { throw new PDUStringException( C_OCTET_STRING_VALUE + value + "' length should be 1 or " + (param.getMax() - 1) + ACTUAL_LENGTH_IS + value.length(), param); } } else if (param.getType() == StringType.OCTET_STRING && !isOctetStringValid(value, param.getMax())) { throw new PDUStringException("Octet String value '" + value + "' length must be less than or equal to " + param.getMax() + ACTUAL_LENGTH_IS + value.length(), param); } } private  StringValidator(); static void validateString(String value, StringParameter param); static void validateString(byte[] value, StringParameter param);  }