DATACOUCH-82 - Implement custom FieldNamingStrategies and abbreviation support.

This commit is contained in:
Michael Nitschinger
2014-04-14 14:30:07 +02:00
parent 8c6614e7d3
commit e9ae5ba1c5
11 changed files with 389 additions and 7 deletions

View File

@@ -74,7 +74,7 @@ public class BasicCouchbasePersistentPropertyTests {
*/
private CouchbasePersistentProperty getPropertyFor(Field field) {
return new BasicCouchbasePersistentProperty(field, null, entity,
new SimpleTypeHolder());
new SimpleTypeHolder(), FallbackFieldNamingStrategy.INSTANCE);
}
/**

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2014 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.couchbase.core.mapping;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
/**
* Unit tests for {@link CamelCaseAbbreviatingFieldNamingStrategy}.
*
* @author Oliver Gierke
* @author Michael Nitschinger
* @since 1.1
*/
@RunWith(MockitoJUnitRunner.class)
public class CamelCaseAbbreviatingFieldNamingStrategyUnitTests {
FieldNamingStrategy strategy = new CamelCaseAbbreviatingFieldNamingStrategy();
@Mock
CouchbasePersistentProperty property;
@Test
public void shouldConvertPropertyNames() {
assertFieldNameForPropertyName("fooBar", "fb");
assertFieldNameForPropertyName("fooBARFooBar", "fbfb");
}
private void assertFieldNameForPropertyName(final String propertyName, final String fieldName) {
when(property.getName()).thenReturn(propertyName);
assertThat(strategy.getFieldName(property), is(fieldName));
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2014 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.couchbase.core.mapping;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
/**
* Unit tests for {@link SnakeCaseFieldNamingStrategy}.
*
* @author Ryan Tenney
* @author Michael Nitschinger
* @since 1.1
*/
@RunWith(MockitoJUnitRunner.class)
public class SnakeCaseFieldNamingStrategyUnitTests {
FieldNamingStrategy strategy = new SnakeCaseFieldNamingStrategy();
@Mock
CouchbasePersistentProperty property;
@Test
public void shouldConvertPropertyNames() {
assertFieldNameForPropertyName("fooBar", "foo_bar");
assertFieldNameForPropertyName("FooBar", "foo_bar");
assertFieldNameForPropertyName("foo_bar", "foo_bar");
assertFieldNameForPropertyName("FOO_BAR", "foo_bar");
}
private void assertFieldNameForPropertyName(final String propertyName, final String fieldName) {
when(property.getName()).thenReturn(propertyName);
assertThat(strategy.getFieldName(property), is(fieldName));
}
}