@Test public void keySetUnaffectedByChanges() { Map<Integer, String> map = new CopyOnWriteHashMap<>(); map.put( 0, "0" ); map.put( 1, "1" ); map.put( 2, "2" ); assertThat( map, hasKey( 0 ) ); assertThat( map, hasKey( 1 ) ); assertThat( map, hasKey( 2 ) ); Iterator<Integer> keys = map.keySet().iterator(); map.remove( 1 ); List<Integer> keysBeforeDeletion = Iterators.asList( keys ); assertThat( keysBeforeDeletion, contains( 0, 1, 2 ) ); }
@Test public void shouldRespondWithMetadataToDiscardAll() throws Throwable { // When negotiateBoltV3(); connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), DiscardAllMessage.INSTANCE ) ); // Then Matcher<Map<? extends String,?>> entryTypeMatcher = hasEntry( is( "type" ), equalTo( "r" ) ); Matcher<Map<? extends String,?>> entryFieldsMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldsMatcher, hasKey( "t_first" ) ) ), msgSuccess( allOf( entryTypeMatcher, hasKey( "t_last" ), hasKey( "bookmark" ) ) ) ) ); }
@Test public void shouldRemoveClaimWhenPassingNull() throws Exception { Algorithm algorithm = mock(Algorithm.class); JWTVerifier verifier = JWTVerifier.init(algorithm) .withIssuer("iss") .withIssuer(null) .build(); assertThat(verifier.claims, is(notNullValue())); assertThat(verifier.claims, not(hasKey("iss"))); }
@Test public void canReadMapWithNestedMap() throws Exception { Map<String, Object> map = input.readMap( "{\"nested\": {\"key\": \"valuable\"}}" ); assertNotNull( map ); assertThat( map, hasKey( "nested" ) ); assertEquals( "map contained extra values", 1, map.size() ); Object nested = map.get( "nested" ); assertThat( nested, instanceOf( Map.class ) ); @SuppressWarnings( "unchecked" ) Map<String, String> nestedMap = (Map<String, String>) nested; assertThat( nestedMap, hasEntry( "key", "valuable" ) ); }
@Test public void canReadMapWithNestedMap() throws Exception { Map<String, Object> map = input.readMap( "{\"nested\": {\"key\": \"valuable\"}}" ); assertNotNull( map ); assertThat( map, hasKey( "nested" ) ); assertEquals( "map contained extra values", 1, map.size() ); Object nested = map.get( "nested" ); assertThat( nested, instanceOf( Map.class ) ); @SuppressWarnings( "unchecked" ) Map<String, String> nestedMap = (Map<String, String>) nested; assertThat( nestedMap, hasEntry( "key", "valuable" ) ); }
@Test public void shouldRespondWithAvailableIndexRelationshipRoots() { String indexName = "someRelationships"; helper.createRelationshipIndex( indexName ); Response response = service.getRelationshipIndexRoot(); assertEquals( 200, response.getStatus() ); try ( Transaction ignored = graph.beginTx() ) { Map<String, Object> resultAsMap = output.getResultAsMap(); assertThat( resultAsMap.size(), is( 1 ) ); assertThat( resultAsMap, hasKey( indexName ) ); } }
@Test public void shouldRunSimpleStatement() throws Throwable { // When negotiateBoltV3(); connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), PullAllMessage.INSTANCE ) ); // Then Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); Matcher<Map<? extends String,?>> entryTypeMatcher = hasEntry( is( "type" ), equalTo( "r" ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ), msgRecord( eqRecord( equalTo( longValue( 1L ) ), equalTo( longValue( 1L ) ) ) ), msgRecord( eqRecord( equalTo( longValue( 2L ) ), equalTo( longValue( 4L ) ) ) ), msgRecord( eqRecord( equalTo( longValue( 3L ) ), equalTo( longValue( 9L ) ) ) ), msgSuccess( allOf( entryTypeMatcher, hasKey( "t_last" ), hasKey( "bookmark" ) ) ) ) ); }
@Test public void shouldNegotiateProtocolV3() throws Exception { connection.connect( address ).send( util.acceptedVersions( 3, 0, 0, 0 ) ).send( util.chunk( new HelloMessage( map( "user_agent", USER_AGENT ) ) ) ); assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 3} ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( hasKey( "server" ), hasKey( "connection_id" ) ) ) ) ); }
private void createAndRollback( TransportConnection client ) throws Exception { client.send( createAndRollback ); Matcher<Map<? extends String,?>> entryMatcher = hasEntry( is( "fields" ), equalTo( emptyList() ) ); Matcher<Map<String,?>> messageMatcher = CoreMatchers.allOf( entryMatcher, hasKey( "result_available_after" ) ); assertThat( client, util.eventuallyReceives( msgSuccess( messageMatcher ), msgSuccess(), msgSuccess( messageMatcher ), msgSuccess(), msgSuccess( messageMatcher ), msgSuccess() ) ); // Verify no visible data client.send( matchAll ); Matcher<Map<? extends String,?>> fieldsMatcher = hasEntry( is( "fields" ), equalTo( singletonList( "n" ) ) ); assertThat( client, util.eventuallyReceives( msgSuccess(CoreMatchers.allOf( fieldsMatcher, hasKey( "result_available_after" ) ) ), msgSuccess() ) ); } };
@Test public void shouldRespondWithMetadataToDiscardAll() throws Throwable { // When connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( new InitMessage( "TestClient/1.1", emptyMap() ), new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), DiscardAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); Matcher<Map<? extends String,?>> entryFieldsMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); Matcher<Map<? extends String,?>> entryTypeMatcher = hasEntry( is( "type" ), equalTo( "r" ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess( CoreMatchers.allOf( entryFieldsMatcher, hasKey( "result_available_after" ) ) ), msgSuccess( CoreMatchers.allOf( entryTypeMatcher, hasKey( "result_consumed_after" ) ) ) ) ); }
@Test public void shouldCloseConnectionInStreaming() throws Throwable { // Given negotiateBoltV3(); // When connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ) ); Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ) ) ); // you shall be in the streaming state now connection.send( util.chunk( GOODBYE_MESSAGE ) ); // Then assertThat( connection, serverImmediatelyDisconnects() ); assertThat( server, eventuallyClosesTransaction() ); }
@Test public void shouldRespondWithAvailableIndexNodeRoots() { int numberOfAutoIndexesWhichCouldNotBeDeletedAtTestSetup = helper.getNodeIndexes().length; String indexName = "someNodes"; helper.createNodeIndex( indexName ); Response response = service.getNodeIndexRoot(); assertEquals( 200, response.getStatus() ); try ( Transaction ignored = graph.beginTx() ) { Map<String, Object> resultAsMap = output.getResultAsMap(); assertThat( resultAsMap.size(), is( numberOfAutoIndexesWhichCouldNotBeDeletedAtTestSetup + 1 ) ); assertThat( resultAsMap, hasKey( indexName ) ); } }
@Test public void shouldCloseConnectionInTxStreaming() throws Throwable { // Given negotiateBoltV3(); // When connection.send( util.chunk( new BeginMessage(), new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ) ); Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ) ) ); // you shall be in the tx_streaming state now connection.send( util.chunk( GOODBYE_MESSAGE ) ); // Then assertThat( connection, serverImmediatelyDisconnects() ); assertThat( server, eventuallyClosesTransaction() ); }
@Test public void shouldRespondWith404AndSensibleEntityBodyWhenNodeToBeDeletedCannotBeFound() throws Exception { JaxRsResponse response = sendDeleteRequestToServer(NON_EXISTENT_NODE_ID); assertEquals( 404, response.getStatus() ); Map<String, Object> jsonMap = JsonHelper.jsonToMap( response.getEntity() ); assertThat( jsonMap, hasKey( "message" ) ); assertNotNull( jsonMap.get( "message" ) ); }
@Test public void shouldFailNicelyOnPointsWhenProtocolDoesNotSupportThem() throws Throwable { // only V1 protocol does not support points assumeThat( neo4jPack.version(), equalTo( Neo4jPackV1.VERSION ) ); // When connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( new InitMessage( "TestClient/1.1", emptyMap() ), new RunMessage( "RETURN point({x:13, y:37, crs:'cartesian'}) as p" ), PullAllMessage.INSTANCE ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); Matcher<Map<? extends String,?>> fieldsMatcher = hasEntry( is( "fields" ), equalTo( singletonList( "p" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess( CoreMatchers.allOf( fieldsMatcher, hasKey( "result_available_after" ) ) ), msgFailure( Status.Request.Invalid, "Point is not supported as a return type in Bolt" ) ) ); }
@SuppressWarnings( "unchecked" ) @Test public void canListExtensionMethodsForServerExtension() throws Exception { JaxRsResponse response = RestRequest.req().get(functionalTestHelper.extensionUri()); assertThat(response.getStatus(), equalTo( 200 )); Map<String, Object> json = JsonHelper.jsonToMap( response.getEntity() ); String refNodeService = (String) json.get(FunctionalTestPlugin.class.getSimpleName()); response.close(); response = RestRequest.req().get(refNodeService); String result = response.getEntity(); assertThat(response.getStatus(), equalTo( 200 )); json = JsonHelper.jsonToMap(result); json = (Map<String, Object>) json.get("graphdb"); assertThat(json, hasKey( FunctionalTestPlugin.CREATE_NODE )); response.close(); } }
@Test // SPR-12592 @SuppressWarnings("resource") public void initializeOnce() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(HandlerMappingConfiguration.class); context.refresh(); assertThat(context.getBean(ResourceUrlProvider.class).getHandlerMap(), Matchers.hasKey(pattern("/resources/**"))); }
@Test // SPR-12592 @SuppressWarnings("resource") public void initializeOnce() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(HandlerMappingConfiguration.class); context.refresh(); ResourceUrlProvider urlProviderBean = context.getBean(ResourceUrlProvider.class); assertThat(urlProviderBean.getHandlerMap(), Matchers.hasKey("/resources/**")); assertFalse(urlProviderBean.isAutodetect()); }
@Test public void testByName() throws Exception { ctx = Configurator.initialize("-config", null); LogManager.getLogger("org.apache.test.TestConfigurator"); Configuration config = ctx.getConfiguration(); assertNotNull("No configuration", config); assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName()); final Map<String, Appender> map = config.getAppenders(); assertNotNull("Appenders map should not be null.", map); assertThat(map, hasSize(greaterThan(0))); assertThat("Wrong configuration", map, hasKey("List")); Configurator.shutdown(ctx); config = ctx.getConfiguration(); assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName()); }
@Documented( "Nodes with relationships cannot be deleted.\n" + "\n" + "The relationships on a node has to be deleted before the node can be\n" + "deleted.\n" + " \n" + "TIP: You can use `DETACH DELETE` in Cypher to delete nodes and their relationships in one go." ) @Test public void shouldRespondWith409AndSensibleEntityBodyWhenNodeCannotBeDeleted() throws Exception { long id = helper.createNode(); helper.createRelationship( "LOVES", id, helper.createNode() ); JaxRsResponse response = sendDeleteRequestToServer(id); assertEquals( 409, response.getStatus() ); Map<String, Object> jsonMap = JsonHelper.jsonToMap( response.getEntity() ); assertThat( jsonMap, hasKey( "message" ) ); assertNotNull( jsonMap.get( "message" ) ); gen.get().expectedStatus( 409 ) .delete( functionalTestHelper.dataUri() + "node/" + id ); }