|
| 1 | +/* |
| 2 | + * Copyright (c) "Neo4j" |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | +package org.neo4j.driver.integration; |
| 20 | + |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import org.neo4j.driver.Config; |
| 24 | +import org.neo4j.driver.Driver; |
| 25 | +import org.neo4j.driver.GraphDatabase; |
| 26 | +import org.neo4j.driver.net.ServerAddress; |
| 27 | +import org.neo4j.driver.net.ServerAddressResolver; |
| 28 | + |
| 29 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 30 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 31 | +import static org.mockito.ArgumentMatchers.any; |
| 32 | +import static org.mockito.Mockito.mock; |
| 33 | +import static org.mockito.Mockito.verify; |
| 34 | +import static org.mockito.Mockito.when; |
| 35 | +import static org.neo4j.driver.Logging.none; |
| 36 | + |
| 37 | +class ResolverIT |
| 38 | +{ |
| 39 | + @Test |
| 40 | + void shouldFailInitialDiscoveryWhenConfiguredResolverThrows() |
| 41 | + { |
| 42 | + ServerAddressResolver resolver = mock( ServerAddressResolver.class ); |
| 43 | + when( resolver.resolve( any( ServerAddress.class ) ) ).thenThrow( new RuntimeException( "Resolution failure!" ) ); |
| 44 | + |
| 45 | + Config config = Config.builder() |
| 46 | + .withoutEncryption() |
| 47 | + .withLogging( none() ) |
| 48 | + .withResolver( resolver ) |
| 49 | + .build(); |
| 50 | + final Driver driver = GraphDatabase.driver( "neo4j://my.server.com:9001", config ); |
| 51 | + |
| 52 | + RuntimeException error = assertThrows( RuntimeException.class, driver::verifyConnectivity ); |
| 53 | + assertEquals( "Resolution failure!", error.getMessage() ); |
| 54 | + verify( resolver ).resolve( ServerAddress.of( "my.server.com", 9001 ) ); |
| 55 | + } |
| 56 | +} |
0 commit comments