@Override public void validateBeforeCommit( Value[] tuple ) { validator.validate( tuple ); }
public static <T> Validator<T> all( Validator<T>... validators ) { return value -> { for ( Validator<T> validator : validators ) { validator.validate( value ); } }; } }
@Override public void validateBeforeCommit( Value[] tuple ) { validator.validate( tuple[0] ); } }
@SafeVarargs private final <T> T validated( T value, Validator<T>... validators ) { if ( value != null ) { for ( Validator<T> validator : validators ) { validator.validate( value ); } } return value; } }
@Override public boolean matches( final Object item ) { final File store = (File) item; try { Validators.CONTAINS_EXISTING_DATABASE.validate( store ); return true; } catch ( Exception e ) { return false; } }
private static Validator<File[]> filesExist( PrintStream err ) { return files -> { for ( File file : files ) { if ( file.getName().startsWith( ":" ) ) { err.println( "It looks like you're trying to specify default label or relationship type (" + file.getName() + "). Please put such directly on the key, f.ex. " + Options.NODE_DATA.argument() + ":MyLabel" ); } Validators.REGEX_FILE_EXISTS.validate( file ); } }; }
private void validate( String fileByName ) { Validators.REGEX_FILE_EXISTS.validate( directory.file( fileByName ) ); }
@Override public void execute( String[] args ) throws IncorrectUsage, CommandFailed { final Path databaseDirectory = arguments.parse( args ).getMandatoryPath( "store" ); Validators.CONTAINS_EXISTING_DATABASE.validate( databaseDirectory.toFile() ); try ( DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); JobScheduler jobScheduler = createInitialisedScheduler(); PageCache pageCache = StandalonePageCacheFactory.createPageCache( fileSystem, jobScheduler ) ) { DatabaseLayout databaseLayout = DatabaseLayout.of( databaseDirectory.toFile() ); final String storeVersion = new StoreVersionCheck( pageCache ) .getVersion( databaseLayout.metadataStore() ) .orElseThrow( () -> new CommandFailed( String.format( "Could not find version metadata in store '%s'", databaseDirectory ) ) ); final String fmt = "%-30s%s"; out.accept( String.format( fmt, "Store format version:", storeVersion ) ); RecordFormats format = RecordFormatSelector.selectForVersion( storeVersion ); out.accept( String.format( fmt, "Store format introduced in:", format.introductionVersion() ) ); findSuccessor( format ) .map( next -> String.format( fmt, "Store format superseded in:", next.introductionVersion() ) ) .ifPresent( out ); } catch ( Exception e ) { throw new CommandFailed( e.getMessage(), e ); } }
@Test void tooLongArrayIsNotAllowed() { int length = MAX_TERM_LENGTH + 1; IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> getValidator().validate( RandomUtils.nextBytes( length ) ) ); assertThat( iae.getMessage(), containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); }
@Test void stringOverExceedLimitNotAllowed() { int length = MAX_TERM_LENGTH * 2; IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> getValidator().validate( RandomStringUtils.randomAlphabetic( length ) ) ); assertThat( iae.getMessage(), containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); }
@Test void shortStringIsValidValue() { getValidator().validate( RandomStringUtils.randomAlphabetic( 5 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( 10 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( 250 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( 450 ) ); getValidator().validate( RandomStringUtils.randomAlphabetic( MAX_TERM_LENGTH ) ); }
@Test void nullIsNotAllowed() { IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> getValidator().validate( null ) ); assertEquals( iae.getMessage(), "Null value" ); }
@Test public void shouldValidateInList() { try { Validators.inList(new String[] { "foo", "bar", "baz" }).validate( "qux" ); fail( "Should have failed to find item in list." ); } catch ( IllegalArgumentException e ) { assertThat( e.getMessage(), containsString( "'qux' found but must be one of: [foo, bar, baz]." ) ); } try { Validators.inList(new String[] { "foo", "bar", "baz" }).validate( "bar" ); } catch ( IllegalArgumentException e ) { fail( "Should have found item in list." ); } }
@Test void shouldInterpretOrphan() { // GIVEN int expectedValue = 42; Args args = Args.parse( String.valueOf( expectedValue ) ); @SuppressWarnings( "unchecked" ) Validator<Integer> validator = mock( Validator.class ); // WHEN int value = args.interpretOrphan( 0, mandatory(), toInt(), validator ); // THEN assertEquals( expectedValue, value ); verify( validator ).validate( expectedValue ); }
@Test void shouldInterpretOption() { // GIVEN int expectedValue = 42; Args args = Args.parse( "--arg", String.valueOf( expectedValue )); @SuppressWarnings( "unchecked" ) Validator<Integer> validator = mock( Validator.class ); // WHEN int value = args.interpretOption( "arg", mandatory(), toInt(), validator ); // THEN assertEquals( expectedValue, value ); verify( validator ).validate( expectedValue ); }
private void verifyData( int expectedNodeCount, int expectedRelationshipCount, Validator<Node> nodeAdditionalValidation, Validator<Relationship> relationshipAdditionalValidation ) { GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { int nodeCount = 0; int relationshipCount = 0; for ( Node node : db.getAllNodes() ) { assertTrue( node.hasProperty( "name" ) ); nodeAdditionalValidation.validate( node ); nodeCount++; } assertEquals( expectedNodeCount, nodeCount ); for ( Relationship relationship : db.getAllRelationships() ) { assertTrue( relationship.hasProperty( "created" ) ); relationshipAdditionalValidation.validate( relationship ); relationshipCount++; } assertEquals( expectedRelationshipCount, relationshipCount ); tx.success(); } }
Validators.CONTAINS_EXISTING_DATABASE.validate( databaseLayout.databaseDirectory() );
@Override public void validateBeforeCommit( Value[] tuple ) { validator.validate( tuple[0] ); } }