TextPatternValidationUtils { public static boolean validateTextPatternValue( TextPattern textPattern, String value ) { StringBuilder builder = new StringBuilder(); builder.append( "^" ); textPattern.getSegments().forEach( ( segment ) -> builder.append( segment.getMethod().getType().getValueRegex( segment.getParameter() ) ) ); builder.append( "$" ); return Pattern.compile( builder.toString() ).matcher( value ).matches(); }  static boolean validateSegmentValue( TextPatternSegment segment, String value ); static boolean validateTextPatternValue( TextPattern textPattern, String value ); static long getTotalValuesPotential( TextPatternSegment generatedSegment ); static boolean validateValueType( TextPattern textPattern, ValueType valueType );  }
@Test public void testValidationUtilsValidateTextPatternValue() throws TextPatternParser.TextPatternParsingException { TextPattern tp = TextPatternParser .parse( "\"FOOBAR\"+RANDOM(xxx)+\"-\"+SEQUENTIAL(##)+ORG_UNIT_CODE(...)+CURRENT_DATE(yyyy)" ); assertTrue( TextPatternValidationUtils.validateTextPatternValue( tp, "FOOBARabc-01OSL1990" ) ); assertFalse( TextPatternValidationUtils.validateTextPatternValue( tp, "FOOBAR abc - 01 OSL 1990" ) ); assertFalse( TextPatternValidationUtils.validateTextPatternValue( tp, "FOOBARabc-01 OSL 1990" ) ); assertFalse( TextPatternValidationUtils.validateTextPatternValue( tp, "FOOBARabc-01OSL 1990" ) ); assertFalse( TextPatternValidationUtils.validateTextPatternValue( tp, "" ) ); }