@Test public void testConvert() throws Exception { System.out.println("convert"); String refValue = UUID.randomUUID().toString() + ":" + UUID.randomUUID().toString(); ReferenceField instance = new ReferenceField(); assertEquals(refValue, instance.convert(refValue)); try { instance.convert(null); fail("null value not checked"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_MISMATCH, ex.getErrorCode()); } try { instance.convert(""); fail("invalid REF formated accepted"); } catch (OperationException ex) { assertEquals(ErrorCode.INVALID_REF_FORMAT, ex.getErrorCode()); } try { instance.convert(UUID.randomUUID().toString()); fail("invalid REF formated accepted"); } catch (OperationException ex) { assertEquals(ErrorCode.INVALID_REF_FORMAT, ex.getErrorCode()); } try { instance.convert(1000); fail("invalid input data type accepted"); } catch (OperationException ex) { assertEquals(ErrorCode.DATATYPE_MISMATCH, ex.getErrorCode()); } }
@Override public String convert(Object objValue) throws OperationException { String value; if (objValue == null || !(objValue instanceof String)) { throw new OperationException(ErrorCode.DATATYPE_MISMATCH, "Input must be of String type. Cannot convert " + objValue + " to a String value"); } value = (String) objValue; if (!value.matches(REGEX_PATTERN)) { throw new OperationException(ErrorCode.INVALID_REF_FORMAT, value + " is not of a valid REF format specification. Supported format [UUID]:[UUID]"); } return value; }
ReferenceField implements FieldType<String> { @Override public String convert(Object objValue) throws OperationException { String value; if (objValue == null || !(objValue instanceof String)) { throw new OperationException(ErrorCode.DATATYPE_MISMATCH, "Input must be of String type. Cannot convert " + objValue + " to a String value"); } value = (String) objValue; if (!value.matches(REGEX_PATTERN)) { throw new OperationException(ErrorCode.INVALID_REF_FORMAT, value + " is not of a valid REF format specification. Supported format [UUID]:[UUID]"); } return value; } }
ReferenceField implements FieldType<String> { @Override public String convert(Object objValue) throws OperationException { String value; if (objValue == null || !(objValue instanceof String)) { throw new OperationException(ErrorCode.DATATYPE_MISMATCH, "Input must be of String type. Cannot convert " + objValue + " to a String value"); } value = (String) objValue; if (!value.matches(REGEX_PATTERN)) { throw new OperationException(ErrorCode.INVALID_REF_FORMAT, value + " is not of a valid REF format specification. Supported format [UUID]:[UUID]"); } return value; } ReferenceField();  ReferenceField(final String scope); }
ReferenceField implements FieldType<String> { @Override public String convert(Object objValue) throws OperationException { String value; if (objValue == null || !(objValue instanceof String)) { throw new OperationException(ErrorCode.DATATYPE_MISMATCH, "Input must be of String type. Cannot convert " + objValue + " to a String value"); } value = (String) objValue; if (!value.matches(REGEX_PATTERN)) { throw new OperationException(ErrorCode.INVALID_REF_FORMAT, value + " is not of a valid REF format specification. Supported format [UUID]:[UUID]"); } return value; } ReferenceField();  ReferenceField(final String scope); @Override Types getType(); String getScope(); boolean isScoped(); @Override String getDefaultValue(); @Override boolean hasDefaultValue(); @Override String convert(Object objValue); @Override JSONObject toJson(); }
ReferenceField implements FieldType<String> { @Override public String convert(Object objValue) throws OperationException { String value; if (objValue == null || !(objValue instanceof String)) { throw new OperationException(ErrorCode.DATATYPE_MISMATCH, "Input must be of String type. Cannot convert " + objValue + " to a String value"); } value = (String) objValue; if (!value.matches(REGEX_PATTERN)) { throw new OperationException(ErrorCode.INVALID_REF_FORMAT, value + " is not of a valid REF format specification. Supported format [UUID]:[UUID]"); } return value; } ReferenceField();  ReferenceField(final String scope); @Override Types getType(); String getScope(); boolean isScoped(); @Override String getDefaultValue(); @Override boolean hasDefaultValue(); @Override String convert(Object objValue); @Override JSONObject toJson();  }