private void assertSuccess( LoginContext subject, String query, Consumer<ResourceIterator<Map<String,Object>>> resultConsumer ) { assertThat( execute( subject, query, resultConsumer ), equalTo( "" ) ); }
public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24 { final Set<Number> s = new HashSet<Number>(); s.add(Integer.valueOf(2)); assertThat(s, new IsCollectionContaining<Number>(new IsEqual<Number>(Integer.valueOf(2)))); assertThat(s, IsCollectionContaining.hasItem(Integer.valueOf(2))); }
private static boolean areArraysEqual(Object actualArray, Object expectedArray) { return areArrayLengthsEqual(actualArray, expectedArray) && areArrayElementsEqual(actualArray, expectedArray); }
private static boolean areEqual(Object actual, Object expected) { if (actual == null) { return expected == null; } if (expected != null && isArray(actual)) { return isArray(expected) && areArraysEqual(actual, expected); } return actual.equals(expected); }
@Test public void testEmptyGraph() throws Throwable { // Given the database is empty // When Procedures procs = procs(); RawIterator<Object[],ProcedureException> stream = procs.procedureCallRead( procs.procedureGet( procedureName( "db", "schema" ) ).id(), new Object[0] ); // Then assertThat( asList( stream ), contains( equalTo( new Object[]{new ArrayList<>(), new ArrayList<>()} ) ) ); commit(); }
@Test public void testNodesShouldNotDependOnOrderOfCreationWithOverlap() throws Throwable { // Given // Node1: (:B {type:'B1}) // Node2: (:B {type:'B2', size: 5}) createNode( Arrays.asList( "B" ), Arrays.asList( "type" ), Arrays.asList( Values.stringValue( "B1" ) ) ); createNode( Arrays.asList( "B" ), Arrays.asList( "type", "size" ), Arrays.asList( Values.stringValue( "B2" ), Values.intValue( 5 ) ) ); // When RawIterator<Object[],ProcedureException> stream = procs().procedureCallRead( procs().procedureGet( procedureName( nodesProcedureName ) ).id(), new Object[0] ); // Then assertThat( asList( stream ), containsInAnyOrder( equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "type", Arrays.asList( "String" ), true) ), equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "size", Arrays.asList( "Integer" ), false) ) ) ); // printStream( stream ); }
private void assertNotEquals( ValueTuple a, ValueTuple b ) { assertThat( a, not( equalTo( b ) ) ); assertThat( b, not( equalTo( a ) ) ); } }
@Test public void liftedFragmentLightCycleAreEqualsWhenTheSourceIsTheSame() { final DefaultFragmentLightCycle<Fragment> lightCycle = new DefaultFragmentLightCycle<>(); final FragmentLightCycle<Fragment> lift1 = LightCycles.lift(lightCycle); final FragmentLightCycle<Fragment> lift2 = LightCycles.lift(lightCycle); assertThat(lift1, not(sameInstance(lift2))); assertThat(lift1, equalTo(lift2)); }
@Test public void shouldNotIndexNodesWithWrongLabel() throws Exception { // Given File file = new File( dbRule.getDatabaseDirAbsolutePath() ); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); inserter.createNode( map("name", "Bob"), label( "User" ), label("Admin")); inserter.createDeferredSchemaIndex( label( "Banana" ) ).on( "name" ).create(); // When inserter.shutdown(); // Then GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { assertThat( count( db.findNodes( label( "Banana" ), "name", "Bob" ) ), equalTo( 0L ) ); } finally { db.shutdown(); } }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue1 = 87; final Object finalValue2 = 3.14; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "b", finalValue2 ); inserter.setNodeProperty( nodeId, "a", finalValue2 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue1 ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue1 ) ); assertThat( db.getNodeById( nodeId ).getProperty( "b" ), equalTo( finalValue2 ) ); } finally { db.shutdown(); } }
@Test public void shouldTransitionToFailedStateIfPopulationJobCrashes() throws Exception { // GIVEN IndexPopulator failingPopulator = mock( IndexPopulator.class ); doThrow( new RuntimeException( "BORK BORK" ) ).when( failingPopulator ).add( any(Collection.class) ); FlippableIndexProxy index = new FlippableIndexProxy(); createNode( map( name, "Taylor" ), FIRST ); IndexPopulationJob job = newIndexPopulationJob( failingPopulator, index, EntityType.NODE, indexDescriptor( FIRST, name, false ) ); // WHEN job.run(); // THEN assertThat( index.getState(), equalTo( InternalIndexState.FAILED ) ); }
@Test public void testInferredStatementCount() throws Exception { assertThat(testCon.isEmpty(), is(equalTo(true))); int inferred = getTotalStatementCount(testCon); URI root = vf.createURI("urn:root"); testCon.add(root, RDF.TYPE, RDF.LIST); testCon.remove(root, RDF.TYPE, RDF.LIST); assertThat(testCon.isEmpty(), is(equalTo(true))); assertThat(getTotalStatementCount(testCon), is(equalTo(inferred))); }
@Test public void testGetNamespace() throws Exception { setupNamespaces(); assertThat(testCon.getNamespace(EXAMPLE), is(equalTo(EXAMPLE_NS))); assertThat(testCon.getNamespace(RDFS_PREFIX), is(equalTo(RDFS_NS))); assertThat(testCon.getNamespace(RDF_PREFIX), is(equalTo("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))); assertThat(testCon.getNamespace("undefined"), is(nullValue())); }
@Test public void supportsMixedTypes() { final Matcher<SampleSubClass> matcher = allOf( equalTo(new SampleBaseClass("bad")), is(notNullValue()), equalTo(new SampleBaseClass("good")), equalTo(new SampleSubClass("ugly"))); assertDoesNotMatch("didn't fail last sub-matcher", matcher, new SampleSubClass("good")); }
/** * A shortcut to the frequently used <code>not(equalTo(x))</code>. * <p/> * For example: * <pre>assertThat(cheese, is(not(smelly)))</pre> * instead of: * <pre>assertThat(cheese, is(not(equalTo(smelly))))</pre> * * @param value * the value that any examined object should <b>not</b> equal */ @Factory public static <T> Matcher<T> not(T value) { return not(equalTo(value)); } }
@Test public void testClear() throws Exception { testCon.add(bob, name, nameBob); assertThat(testCon.hasStatement(null, name, nameBob, false), is(equalTo(true))); testCon.clear(); assertThat(testCon.hasStatement(null, name, nameBob, false), is(equalTo(false))); }
@Test public void testQueryDefaultGraph() throws Exception { URI graph = vf.createURI("urn:test:default"); testCon.add(vf.createURI(URN_TEST_S1), vf.createURI(URN_TEST_P1), vf.createURI(URN_TEST_O1)); assertThat(size(graph), is(equalTo(0))); testCon.add(vf.createURI("urn:test:s2"), vf.createURI(URN_TEST_P2), vf.createURI("urn:test:o2"), graph); assertThat(size(graph), is(equalTo(1))); }
@Test public void createdNodeShouldShowUpInIndexQuery() { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" ); createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); // WHEN Transaction tx = beansAPI.beginTx(); long sizeBeforeDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); createNode( beansAPI, map( "name", "Mattias" ), LABEL1 ); long sizeAfterDelete = count( beansAPI.findNodes( LABEL1, "name", "Mattias" ) ); tx.close(); // THEN assertThat( sizeBeforeDelete, equalTo(1L) ); assertThat( sizeAfterDelete, equalTo(2L) ); }