Browse Source
Removed deprecated types and adapt dependency tests accordingly. Refactored MongoExampleMapper to revert to use StringMatcher from Spring Data Commons' ExampleMatcher. Introduced MongoRegexCreator specific MatchMode, which is basically a copy of StringMatcher. Adapted MongoExampleMapper and MongoQueryCreator to translate from StringMatcher and Part.Type to MatchMode. Turned unit tests for MongoRegexCreator into parameterized ones. Original pull request: #470.pull/483/merge
8 changed files with 201 additions and 300 deletions
@ -1,31 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2017 the original author or authors. |
|
||||||
* |
|
||||||
* 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.springframework.data.mongodb.core; |
|
||||||
|
|
||||||
import org.springframework.data.mongodb.core.geo.GeoJsonModule; |
|
||||||
|
|
||||||
/** |
|
||||||
* Configuration class to expose {@link GeoJsonModule} as a Spring bean. |
|
||||||
* |
|
||||||
* @author Oliver Gierke |
|
||||||
* @author Jens Schauder |
|
||||||
* |
|
||||||
* @deprecated Use {@link org.springframework.data.mongodb.config.GeoJsonConfiguration} instead. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class GeoJsonConfiguration extends org.springframework.data.mongodb.config.GeoJsonConfiguration { |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,31 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2017 the original author or authors. |
|
||||||
* |
|
||||||
* 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.springframework.data.mongodb.core; |
|
||||||
|
|
||||||
/** |
|
||||||
* Index operations on a collection. |
|
||||||
* |
|
||||||
* @author Mark Pollack |
|
||||||
* @author Oliver Gierke |
|
||||||
* @author Christoph Strobl |
|
||||||
* @author Jens Schauder |
|
||||||
* |
|
||||||
* @deprecated Use {@link org.springframework.data.mongodb.core.index.IndexOperations} instead. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public interface IndexOperations extends org.springframework.data.mongodb.core.index.IndexOperations { |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,28 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2017 the original author or authors. |
|
||||||
* |
|
||||||
* 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.springframework.data.mongodb.core; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author Mark Paluch |
|
||||||
* @author Jens Schauder |
|
||||||
* @since 2.0 |
|
||||||
* |
|
||||||
* @deprecated Use {@link org.springframework.data.mongodb.core.index.IndexOperationsProvider} instead. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public interface IndexOperationsProvider extends org.springframework.data.mongodb.core.index.IndexOperationsProvider { |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,116 +1,92 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2017 the original author or authors. |
||||||
|
* |
||||||
|
* 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.springframework.data.mongodb.core.query; |
package org.springframework.data.mongodb.core.query; |
||||||
|
|
||||||
import static java.util.Arrays.*; |
import static java.util.Arrays.*; |
||||||
|
import static org.assertj.core.api.Assertions.*; |
||||||
import static org.springframework.data.mongodb.core.query.MongoRegexCreatorUnitTests.TestParameter.*; |
import static org.springframework.data.mongodb.core.query.MongoRegexCreatorUnitTests.TestParameter.*; |
||||||
|
|
||||||
import java.util.Arrays; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import org.assertj.core.api.SoftAssertions; |
|
||||||
import org.assertj.core.api.StringAssert; |
|
||||||
import org.junit.Test; |
import org.junit.Test; |
||||||
import org.springframework.data.repository.query.parser.Part.Type; |
import org.junit.runner.RunWith; |
||||||
|
import org.junit.runners.Parameterized; |
||||||
|
import org.junit.runners.Parameterized.Parameter; |
||||||
|
import org.junit.runners.Parameterized.Parameters; |
||||||
|
import org.springframework.data.mongodb.core.query.MongoRegexCreator.MatchMode; |
||||||
|
|
||||||
/** |
/** |
||||||
* Tests the creation of Regex's in {@link MongoRegexCreator} |
* Tests the creation of Regex's in {@link MongoRegexCreator} |
||||||
* |
* |
||||||
* @author Jens Schauder |
* @author Jens Schauder |
||||||
|
* @author Oliver Gierke |
||||||
*/ |
*/ |
||||||
|
@RunWith(Parameterized.class) |
||||||
public class MongoRegexCreatorUnitTests { |
public class MongoRegexCreatorUnitTests { |
||||||
|
|
||||||
List<TestParameter> testParameters = asList(TestParameter.test("anystring", null, "anystring", "type=null -> input"), |
@Parameters(name = "{index}: {0}") //
|
||||||
test(null, Type.AFTER, null, "source=null -> null"), //
|
public static List<TestParameter> parameters() { |
||||||
test("anystring", Type.REGEX, "anystring", "REGEX -> input"), //
|
|
||||||
test("one.two?three", Type.AFTER, "\\Qone.two?three\\E", |
return asList(//
|
||||||
"not(REGEX, LIKE, NOT_LIKE, PunctuationPattern -> quoted punctuation"), //
|
test(null, MatchMode.EXACT, null, "Null input string -> null"), //
|
||||||
test("*", Type.LIKE, ".*", "LIKE * -> .*"), test("*", Type.NOT_LIKE, ".*", "LIKE * -> .*"), //
|
test("anystring", null, "anystring", "type=null -> input"), //
|
||||||
test("*.*", Type.LIKE, ".*\\Q.\\E.*", "Wildcards & Punctuation"), //
|
test("anystring", MatchMode.REGEX, "anystring", "REGEX -> input"), //
|
||||||
test("*.", Type.LIKE, ".*\\Q.\\E", "Leading Wildcard & Punctuation"), //
|
test("*", MatchMode.LIKE, ".*", "LIKE * -> .*"), //
|
||||||
test(".*", Type.LIKE, "\\Q.\\E.*", "Trailing Wildcard & Punctuation"), //
|
test("*.*", MatchMode.LIKE, ".*\\Q.\\E.*", "Wildcards & Punctuation"), //
|
||||||
test("other", Type.LIKE, "other", "No Wildcard & Other"), //
|
test("*.", MatchMode.LIKE, ".*\\Q.\\E", "Leading Wildcard & Punctuation"), //
|
||||||
test("other*", Type.LIKE, "other.*", "Trailing Wildcard & Other"), //
|
test(".*", MatchMode.LIKE, "\\Q.\\E.*", "Trailing Wildcard & Punctuation"), //
|
||||||
test("*other", Type.LIKE, ".*other", "Leading Wildcard & Other"), //
|
test("other", MatchMode.LIKE, "other", "No Wildcard & Other"), //
|
||||||
test("o*t.*h.er", Type.LIKE, "\\Qo*t.*h.er\\E", "Dots & Stars"), //
|
test("other*", MatchMode.LIKE, "other.*", "Trailing Wildcard & Other"), //
|
||||||
test("other", Type.STARTING_WITH, "^other", "Dots & Stars"), //
|
test("*other", MatchMode.LIKE, ".*other", "Leading Wildcard & Other"), //
|
||||||
test("other", Type.ENDING_WITH, "other$", "Dots & Stars"), //
|
test("o*t.*h.er", MatchMode.LIKE, "\\Qo*t.*h.er\\E", "Dots & Stars"), //
|
||||||
test("other", Type.CONTAINING, ".*other.*", "Dots & Stars"), //
|
test("other", MatchMode.STARTING_WITH, "^other", "Dots & Stars"), //
|
||||||
test("other", Type.NOT_CONTAINING, ".*other.*", "Dots & Stars"), //
|
test("other", MatchMode.ENDING_WITH, "other$", "Dots & Stars"), //
|
||||||
test("other", Type.SIMPLE_PROPERTY, "^other$", "Dots & Stars"), //
|
test("other", MatchMode.CONTAINING, ".*other.*", "Dots & Stars"), //
|
||||||
test("other", Type.NEGATING_SIMPLE_PROPERTY, "^other$", "Dots & Stars")); |
test("other", MatchMode.EXACT, "^other$", "Dots & Stars")); |
||||||
|
|
||||||
Map<Type, String> expectedResultsForAllTypes = new HashMap<>(); |
|
||||||
{ |
|
||||||
expectedResultsForAllTypes.put(Type.BETWEEN, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.IS_NOT_NULL, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.IS_NULL, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.LESS_THAN, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.LESS_THAN_EQUAL, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.GREATER_THAN, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.GREATER_THAN_EQUAL, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.BEFORE, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.AFTER, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.NOT_LIKE, "\\Qo*t.*h.er\\E.*"); |
|
||||||
expectedResultsForAllTypes.put(Type.LIKE, "\\Qo*t.*h.er\\E.*"); |
|
||||||
expectedResultsForAllTypes.put(Type.STARTING_WITH, "^\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.ENDING_WITH, "\\Qo*t.*h.er*\\E$"); |
|
||||||
expectedResultsForAllTypes.put(Type.IS_NOT_EMPTY, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.IS_EMPTY, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.NOT_CONTAINING, ".*\\Qo*t.*h.er*\\E.*"); |
|
||||||
expectedResultsForAllTypes.put(Type.CONTAINING, ".*\\Qo*t.*h.er*\\E.*"); |
|
||||||
expectedResultsForAllTypes.put(Type.NOT_IN, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.IN, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.NEAR, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.WITHIN, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.REGEX, "o*t.*h.er*"); |
|
||||||
expectedResultsForAllTypes.put(Type.EXISTS, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.TRUE, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.FALSE, "\\Qo*t.*h.er*\\E"); |
|
||||||
expectedResultsForAllTypes.put(Type.NEGATING_SIMPLE_PROPERTY, "^\\Qo*t.*h.er*\\E$"); |
|
||||||
expectedResultsForAllTypes.put(Type.SIMPLE_PROPERTY, "^\\Qo*t.*h.er*\\E$"); |
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
@Test |
@Parameter(0) //
|
||||||
public void testSpecialCases() { |
public TestParameter parameter; |
||||||
SoftAssertions.assertSoftly(sa -> testParameters.forEach(tp -> tp.check(sa))); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
@Test |
||||||
public void testAllTypes() { |
public void testSpecialCases() { |
||||||
SoftAssertions.assertSoftly( |
parameter.check(); |
||||||
sa -> Arrays.stream(Type.values()).forEach(t -> //
|
|
||||||
test("o*t.*h.er*", t, expectedResultsForAllTypes.getOrDefault(t,"missed one"), t.toString())//
|
|
||||||
.check(sa))); |
|
||||||
} |
} |
||||||
|
|
||||||
|
@lombok.RequiredArgsConstructor(staticName = "test") |
||||||
static class TestParameter { |
static class TestParameter { |
||||||
|
|
||||||
TestParameter(String source, Type type, String expectedResult, String comment) { |
|
||||||
this.source = source; |
|
||||||
this.type = type; |
|
||||||
this.expectedResult = expectedResult; |
|
||||||
this.comment = comment; |
|
||||||
} |
|
||||||
|
|
||||||
static TestParameter test(String source, Type type, String expectedResult, String comment) { |
|
||||||
return new TestParameter(source, type, expectedResult, comment); |
|
||||||
} |
|
||||||
|
|
||||||
private final String source; |
private final String source; |
||||||
private final Type type; |
private final MatchMode mode; |
||||||
private final String expectedResult; |
private final String expectedResult, comment; |
||||||
private final String comment; |
|
||||||
|
|
||||||
private StringAssert check(SoftAssertions sa) { |
void check() { |
||||||
|
|
||||||
return sa |
assertThat(MongoRegexCreator.INSTANCE.toRegularExpression(source, mode))//
|
||||||
.assertThat( //
|
.as(comment)//
|
||||||
MongoRegexCreator.INSTANCE.toRegularExpression(source, type)) //
|
|
||||||
.describedAs(comment) //
|
|
||||||
.isEqualTo(expectedResult); |
.isEqualTo(expectedResult); |
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
|
/* |
||||||
|
* (non-Javadoc) |
||||||
|
* @see java.lang.Object#toString() |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return String.format("Mode: %s, %s", mode, comment); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue