-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-836 - Ignore duplicates in constraint definitions.
This will fix the handling of multiple defines, e.g. coming from multiple relationship entities, constraints with the same type and field. Fixes #836.
- Loading branch information
1 parent
73ee67a
commit 41702d5
Showing
5 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...tests/src/test/java/org/neo4j/ogm/autoindex/DuplicatedConstraintAutoIndexManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.ogm.autoindex; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.Test; | ||
import org.neo4j.ogm.domain.autoindex.RelationshipEntityWithSameType1; | ||
import org.neo4j.ogm.domain.autoindex.RelationshipEntityWithSameType2; | ||
|
||
/** | ||
* @author Gerrit Meier | ||
*/ | ||
public class DuplicatedConstraintAutoIndexManagerTest extends BaseAutoIndexManagerTestClass { | ||
|
||
private static final String INDEX = "INDEX ON :`SAME_TYPE`(`id`)"; | ||
private static final String CONSTRAINT = "CONSTRAINT ON (`same_type`:`SAME_TYPE`) ASSERT `same_type`.`id` IS UNIQUE"; | ||
|
||
public DuplicatedConstraintAutoIndexManagerTest() { | ||
super(new String[] { CONSTRAINT }, RelationshipEntityWithSameType1.class, RelationshipEntityWithSameType2.class); | ||
} | ||
|
||
@Override | ||
protected void additionalTearDown() { | ||
executeDrop(CONSTRAINT); | ||
executeDrop(INDEX); | ||
} | ||
|
||
@Test | ||
public void shouldNotFailOnDuplicatedConstraint() { | ||
|
||
runAutoIndex("update"); | ||
|
||
executeForIndexes(indexes -> assertThat(indexes).hasSize(expectedNumberOfAdditionalIndexes)); | ||
executeForConstraints(constraints -> assertThat(constraints).hasSize(1)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...n-tests/src/test/java/org/neo4j/ogm/domain/autoindex/RelationshipEntityWithSameType1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.neo4j.ogm.domain.autoindex; | ||
|
||
import org.neo4j.ogm.annotation.Id; | ||
import org.neo4j.ogm.annotation.RelationshipEntity; | ||
|
||
/** | ||
* @author Gerrit Meier | ||
*/ | ||
@RelationshipEntity(type = "SAME_TYPE") | ||
public class RelationshipEntityWithSameType1 { | ||
|
||
@Id | ||
private Long id; | ||
} |
14 changes: 14 additions & 0 deletions
14
...n-tests/src/test/java/org/neo4j/ogm/domain/autoindex/RelationshipEntityWithSameType2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.neo4j.ogm.domain.autoindex; | ||
|
||
import org.neo4j.ogm.annotation.Id; | ||
import org.neo4j.ogm.annotation.RelationshipEntity; | ||
|
||
/** | ||
* @author Gerrit Meier | ||
*/ | ||
@RelationshipEntity(type = "SAME_TYPE") | ||
public class RelationshipEntityWithSameType2 { | ||
|
||
@Id | ||
private Long id; | ||
} |