public static <T, E extends Exception> void assertEventually( String reason, ThrowingSupplier<T, E> actual, Matcher<? super T> matcher, long timeout, TimeUnit timeUnit ) throws E, InterruptedException { assertEventually( ignored -> reason, actual, matcher, timeout, timeUnit ); }
public static void assertObjectOrArrayEquals( Object expected, Object actual ) { assertObjectOrArrayEquals( "", expected, actual ); }
public static void assertObjectOrArrayEquals( String message, Object expected, Object actual ) { if ( expected.getClass().isArray() ) { if ( !ArrayUtil.equals( expected, actual ) ) { throw newAssertionError( message, expected, actual ); } } else { if ( !Objects.equals( expected, actual ) ) { throw newAssertionError( message, expected, actual ); } } }
@Test public void shouldFailSetPasswordWithTooManyArguments() { String[] arguments = {"", "123", "321"}; assertException( () -> setPasswordCommand.execute( arguments ), IncorrectUsage.class, "unrecognized arguments: '123 321'" ); }
@Test public void shouldFailForNoArguments() { assertException( () -> setDefaultAdmin.execute( new String[0] ), IncorrectUsage.class, "not enough arguments" ); }
@Test public void shouldStartStopNeoServerWithoutAnyConfigFiles() throws Throwable { // When int resultCode = ServerBootstrapper.start( bootstrapper, withConnectorsOnRandomPortsConfig( "--home-dir", tempDir.newFolder( "home-dir" ).getAbsolutePath(), "-c", configOption( data_directory, tempDir.getRoot().getAbsolutePath() ), "-c", configOption( logs_directory, tempDir.getRoot().getAbsolutePath() ), "-c", "dbms.backup.enabled=false" ) ); // Then assertEquals( ServerBootstrapper.OK, resultCode ); assertEventually( "Server was not started", bootstrapper::isRunning, is( true ), 1, TimeUnit.MINUTES ); }
@Test public void shouldFailForTooManyArguments() { String[] arguments = {"", "123", "321"}; assertException( () -> setDefaultAdmin.execute( arguments ), IncorrectUsage.class, "unrecognized arguments: '123 321'" ); }
@Test public void shouldFailSetPasswordWithNoArguments() { assertException( () -> setPasswordCommand.execute( new String[0] ), IncorrectUsage.class, "not enough arguments" ); }
@Test public void shouldNotAllowComplexNames() throws Exception { // Given FileUserRepository users = new FileUserRepository( fs, authFile, logProvider ); // When users.assertValidUsername( "neo4j" ); users.assertValidUsername( "johnosbourne" ); users.assertValidUsername( "john_osbourne" ); assertException( () -> users.assertValidUsername( null ), InvalidArgumentsException.class, "The provided username is empty." ); assertException( () -> users.assertValidUsername( "" ), InvalidArgumentsException.class, "The provided username is empty." ); assertException( () -> users.assertValidUsername( "," ), InvalidArgumentsException.class, "Username ',' contains illegal characters. Use ascii characters that are not ',', ':' or whitespaces" + "." ); assertException( () -> users.assertValidUsername( "with space" ), InvalidArgumentsException.class, "Username 'with space' contains illegal characters. Use ascii characters that are not ',', ':' or " + "whitespaces." ); assertException( () -> users.assertValidUsername( "with:colon" ), InvalidArgumentsException.class, "Username 'with:colon' contains illegal characters. Use ascii characters that are not ',', ':' or " + "whitespaces." ); assertException( () -> users.assertValidUsername( "withå" ), InvalidArgumentsException.class, "Username 'withå' contains illegal characters. Use ascii characters that are not ',', ':' or " + "whitespaces." ); }
@Test public void shouldFailWhenAuthTokenIsInvalid() throws Throwable { manager.start(); assertException( () -> manager.login( map( AuthToken.SCHEME_KEY, "supercool", AuthToken.PRINCIPAL, "neo4j" ) ), InvalidAuthTokenException.class, "Unsupported authentication token, scheme 'supercool' is not supported." ); assertException( () -> manager.login( map( AuthToken.SCHEME_KEY, "none" ) ), InvalidAuthTokenException.class, "Unsupported authentication token, scheme 'none' is only allowed when auth is disabled" ); assertException( () -> manager.login( map( "key", "value" ) ), InvalidAuthTokenException.class, "Unsupported authentication token, missing key `scheme`" ); assertException( () -> manager.login( map( AuthToken.SCHEME_KEY, "basic", AuthToken.PRINCIPAL, "neo4j" ) ), InvalidAuthTokenException.class, "Unsupported authentication token, missing key `credentials`" ); assertException( () -> manager.login( map( AuthToken.SCHEME_KEY, "basic", AuthToken.CREDENTIALS, "very-secret" ) ), InvalidAuthTokenException.class, "Unsupported authentication token, missing key `principal`" ); }
@Test public void shouldCreateGeneralIndex() { // GIVEN IndexDescriptor descriptor = forLabel( LABEL_ID, PROPERTY_ID_1 ); StoreIndexDescriptor indexRule = descriptor.withId( RULE_ID ); // THEN assertThat( indexRule.getId(), equalTo( RULE_ID ) ); assertFalse( indexRule.canSupportUniqueConstraint() ); assertThat( indexRule.schema(), equalTo( descriptor.schema() ) ); assertThat( indexRule, equalTo( descriptor ) ); assertThat( indexRule.providerDescriptor(), equalTo( PROVIDER_DESCRIPTOR ) ); assertException( indexRule::getOwningConstraint, IllegalStateException.class ); assertException( () -> indexRule.withOwningConstraint( RULE_ID_2 ), IllegalStateException.class ); }
@Test public void shouldCreateNodeKeyConstraint() { // GIVEN ConstraintDescriptor descriptor = nodeKeyForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor ); // THEN assertThat( constraintRule.getId(), equalTo( RULE_ID ) ); assertThat( constraintRule.schema(), equalTo( descriptor.schema() ) ); assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertException( constraintRule::getOwnedIndex, IllegalStateException.class ); }
@Test public void shouldCreateUniquenessConstraint() { // GIVEN ConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor ); // THEN assertThat( constraintRule.getId(), equalTo( RULE_ID ) ); assertThat( constraintRule.schema(), equalTo( descriptor.schema() ) ); assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertException( constraintRule::getOwnedIndex, IllegalStateException.class ); }
@Test public void shouldCreateExistenceConstraint() { // GIVEN ConstraintDescriptor descriptor = existsForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor ); // THEN assertThat( constraintRule.getId(), equalTo( RULE_ID ) ); assertThat( constraintRule.schema(), equalTo( descriptor.schema() ) ); assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertException( constraintRule::getOwnedIndex, IllegalStateException.class ); }
@Test public void shouldEnforceOnSetLabel() throws Exception { // given createNodeWithLabelAndProps( label, this.aValues ); // when newTransaction(); long node = createNode(); setProperties( node, bValues ); // ok because no label is set assertException( () -> { addLabel( node, label ); // boom! }, UniquePropertyValueValidationException.class ); commit(); }
@Test public void shouldEnforceOnSetLabelInTx() throws Exception { // given createNodeWithLabelAndProps( label, aValues ); // when newTransaction(); long nodeB = createNode(); setProperties( nodeB, bValues ); assertException( () -> { addLabel( nodeB, label ); // boom! }, UniquePropertyValueValidationException.class ); commit(); }
@Test public void shouldEnforceOnSetProperty() throws Exception { // given createNodeWithLabelAndProps( label, this.aValues ); // when newTransaction(); long node = createLabeledNode( label ); int lastPropertyOffset = numberOfProps - 1; for ( int prop = 0; prop < lastPropertyOffset; prop++ ) { setProperty( node, prop, aValues[prop] ); // still ok } assertException( () -> { setProperty( node, lastPropertyOffset, aValues[lastPropertyOffset] ); // boom! }, UniquePropertyValueValidationException.class ); commit(); }
@Test public void shouldEnforceOnSetPropertyInTx() throws Exception { // when newTransaction(); long aNode = createLabeledNode( label ); setProperties( aNode, aValues ); long nodeB = createLabeledNode( label ); int lastPropertyOffset = numberOfProps - 1; for ( int prop = 0; prop < lastPropertyOffset; prop++ ) { setProperty( nodeB, prop, bValues[prop] ); // still ok } assertException( () -> { setProperty( nodeB, lastPropertyOffset, bValues[lastPropertyOffset] ); // boom! }, UniquePropertyValueValidationException.class ); commit(); }
@Test public void shouldPreventConflictingDataInTx() throws Throwable { // Given // When newTransaction(); long n1 = createLabeledNode( label ); long n2 = createLabeledNode( label ); setProperties( n1, aValues ); int lastPropertyOffset = numberOfProps - 1; for ( int prop = 0; prop < lastPropertyOffset; prop++ ) { setProperty( n2, prop, aValues[prop] ); // still ok } assertException( () -> { setProperty( n2, lastPropertyOffset, aValues[lastPropertyOffset] ); // boom! }, UniquePropertyValueValidationException.class ); // Then should fail commit(); }
@Test public void shouldForwardMetadataFromRequestData() throws Exception { // Given RequestData mock = new RequestData( "127.0.0.1", true, 1, "TheLocalName", "129.0.0.1", 2, "authorization/auth" ); InternalJettyServletRequest req = new InternalJettyServletRequest( "POST", "https://localhost:7473/db/data/node", "", new InternalJettyServletResponse(), mock ); // When & then assertEquals( "127.0.0.1", req.getRemoteAddr()); assertException( req::getRemoteHost, UnsupportedOperationException.class, "Remote host-name lookup might prove expensive, this should be explicitly considered." ); assertTrue( req.isSecure() ); assertEquals( 1, req.getRemotePort()); assertEquals( "TheLocalName", req.getLocalName()); assertEquals( "129.0.0.1", req.getLocalAddr()); assertEquals( 2, req.getLocalPort()); assertEquals( "authorization/auth", req.getAuthType()); }