From 42e81bea3df4b5f439a24073c9095ee63f25f511 Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Mon, 6 Aug 2018 14:05:42 +0200 Subject: [PATCH] Fixed Test errors --- src/main/java/apoc/load/Xml.java | 2 +- src/main/java/apoc/schema/Schemas.java | 58 ++++++++++--------- .../apoc/refactor/GraphRefactoringTest.java | 4 +- src/test/java/apoc/schema/SchemasTest.java | 2 +- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/main/java/apoc/load/Xml.java b/src/main/java/apoc/load/Xml.java index c20eeb0623..aba6beb436 100644 --- a/src/main/java/apoc/load/Xml.java +++ b/src/main/java/apoc/load/Xml.java @@ -69,7 +69,7 @@ private Stream xmlXpathToMapResult(@Name("url") String url, boolean s FileUtils.checkReadAllowed(url); - Map headers = (HashMap) config.getOrDefault( "headers", Collections.emptyMap() ); + Map headers = (Map) config.getOrDefault( "headers", Collections.emptyMap() ); Document doc = documentBuilder.parse(Util.openInputStream(url, headers, null)); XPathFactory xPathFactory = XPathFactory.newInstance(); diff --git a/src/main/java/apoc/schema/Schemas.java b/src/main/java/apoc/schema/Schemas.java index b809c2720d..6d6ca55b14 100644 --- a/src/main/java/apoc/schema/Schemas.java +++ b/src/main/java/apoc/schema/Schemas.java @@ -20,6 +20,7 @@ import java.util.*; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -256,23 +257,14 @@ private Boolean constraintsExistsForRelationship(String type, List prope */ private Stream indexesAndConstraintsForNode() throws IndexNotFoundKernelException { Schema schema = db.schema(); - Stream indexes = Stream.empty(); - try ( Statement statement = tx.acquireStatement() ) { ReadOperations readOps = statement.readOperations(); StatementTokenNameLookup tokens = new StatementTokenNameLookup(readOps); Iterable indexesIterator = readOps::indexesGetAll; - indexes = StreamSupport.stream(indexesIterator.spliterator(), false) - .map(indexReference -> { - try { - return this.nodeInfoFromIndexDefinition(indexReference, readOps, tokens); - } catch (IndexNotFoundKernelException e) { - throw new RuntimeException("",e); - } - }); + return StreamSupport.stream(indexesIterator.spliterator(), false) + .map(indexReference -> this.nodeInfoFromIndexDefinition(indexReference, readOps, tokens)) + .sorted(Comparator.comparing(i -> i.label)); } - - return indexes; } /** @@ -295,23 +287,33 @@ private Stream constraintsForRelationship() { * @param schemaRead * @return */ - private IndexConstraintNodeInfo nodeInfoFromIndexDefinition(IndexDescriptor indexReference, ReadOperations schemaRead, TokenNameLookup tokens) throws IndexNotFoundKernelException { + private IndexConstraintNodeInfo nodeInfoFromIndexDefinition(IndexDescriptor indexReference, ReadOperations schemaRead, TokenNameLookup tokens) { String labelName = tokens.labelGetName(indexReference.schema().getLabelId()); - List properties = new ArrayList<>(); - Arrays.stream(indexReference.schema().getPropertyIds()).forEach((i) -> properties.add(tokens.propertyKeyGetName(i))); - return new IndexConstraintNodeInfo( - // Pretty print for index name - String.format(":%s(%s)", labelName, StringUtils.join(properties, ",")), - labelName, - properties, - schemaRead.indexGetState(indexReference).toString(), - indexReference.type() == IndexDescriptor.Type.UNIQUE ? "UNIQUENESS" : "INDEX", - schemaRead.indexGetState(indexReference).equals(InternalIndexState.FAILED) ? schemaRead.indexGetFailure(indexReference) : "NO FAILURE", - schemaRead.indexGetPopulationProgress(indexReference).getCompleted()/schemaRead.indexGetPopulationProgress(indexReference).getTotal()*100, - schemaRead.indexSize(indexReference), - schemaRead.indexUniqueValuesSelectivity(indexReference), - indexReference.userDescription(tokens) - ); + List properties = Arrays.stream(indexReference.schema().getPropertyIds()).mapToObj(tokens::propertyKeyGetName).collect(Collectors.toList()); + try { + return new IndexConstraintNodeInfo( + // Pretty print for index name + String.format(":%s(%s)", labelName, StringUtils.join(properties, ",")), + labelName, + properties, + schemaRead.indexGetState(indexReference).toString(), + indexReference.type() == IndexDescriptor.Type.UNIQUE ? "UNIQUENESS" : "INDEX", + schemaRead.indexGetState(indexReference).equals(InternalIndexState.FAILED) ? schemaRead.indexGetFailure(indexReference) : "NO FAILURE", + schemaRead.indexGetPopulationProgress(indexReference).getCompleted()/schemaRead.indexGetPopulationProgress(indexReference).getTotal()*100, + schemaRead.indexSize(indexReference), + schemaRead.indexUniqueValuesSelectivity(indexReference), + indexReference.userDescription(tokens) + ); + } catch (IndexNotFoundKernelException e) { + return new IndexConstraintNodeInfo( + // Pretty print for index name + String.format(":%s(%s)", labelName, StringUtils.join(properties, ",")), + labelName, properties, "NOT_FOUND", + indexReference.type() == IndexDescriptor.Type.UNIQUE ? "UNIQUENESS" : "INDEX", + "NOT_FOUND", 0, 0, 0, + indexReference.userDescription(tokens) + ); + } } /** diff --git a/src/test/java/apoc/refactor/GraphRefactoringTest.java b/src/test/java/apoc/refactor/GraphRefactoringTest.java index 8c9bd4e129..fad702b4a6 100644 --- a/src/test/java/apoc/refactor/GraphRefactoringTest.java +++ b/src/test/java/apoc/refactor/GraphRefactoringTest.java @@ -522,9 +522,9 @@ public void testMergeNodesAndMergeSameRelationshipsAndNodes() { assertEquals(4,resultingNode.getDegree(Direction.OUTGOING)); assertEquals(1,c.getDegree(Direction.INCOMING)); assertEquals(true, r.isType(RelationshipType.withName("HAS_REL"))); - assertEquals(Arrays.asList( "r1" , "r2").toArray(), new ArrayBackedList(r.getProperty("p")).toArray()); + assertEquals("r1", r.getProperty("p")); assertEquals(true, r1.isType(RelationshipType.withName("HAS_REL"))); - assertEquals(Arrays.asList( "r2" , "r1").toArray(), new ArrayBackedList(r1.getProperty("p")).toArray()); + assertEquals("r2", r1.getProperty("p")); } ); } diff --git a/src/test/java/apoc/schema/SchemasTest.java b/src/test/java/apoc/schema/SchemasTest.java index 52e3b31ae2..048b8982ab 100644 --- a/src/test/java/apoc/schema/SchemasTest.java +++ b/src/test/java/apoc/schema/SchemasTest.java @@ -268,7 +268,7 @@ public void testIndexes() { assertEquals("NO FAILURE", r.get("failure")); assertEquals(new Double(100), r.get("populationProgress")); assertEquals(new Double(1), r.get("valuesSelectivity")); - assertEquals("Index( GENERAL, bar )", r.get("userDescription")); + assertEquals("Index( GENERAL, :Foo(bar) )", r.get("userDescription")); assertTrue(!result.hasNext()); });