DATACMNS-1496 - Removed deprecations at least introduced in Lovelace.

This commit is contained in:
Oliver Drotbohm
2019-03-13 16:21:31 +01:00
parent 78e635fba9
commit 0bf160eb97
39 changed files with 63 additions and 1901 deletions

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2011-2019 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.authentication;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
/**
* Unit tests for {@link UserCredentials}.
*
* @author Oliver Gierke
*/
public class UserCredentialsUnitTests {
@Test
public void treatsEmptyStringAsNull() {
UserCredentials credentials = new UserCredentials("", "");
assertThat(credentials.getUsername()).isNull();
assertThat(credentials.hasUsername()).isFalse();
assertThat(credentials.getPassword()).isNull();
assertThat(credentials.hasPassword()).isFalse();
}
@Test // DATACMNS-142
public void noCredentialsNullsUsernameAndPassword() {
assertThat(UserCredentials.NO_CREDENTIALS.getUsername()).isNull();
assertThat(UserCredentials.NO_CREDENTIALS.getPassword()).isNull();
}
@Test // DATACMNS-142
public void configuresUsernameCorrectly() {
UserCredentials credentials = new UserCredentials("username", null);
assertThat(credentials.hasUsername()).isTrue();
assertThat(credentials.getUsername()).isEqualTo("username");
assertThat(credentials.hasPassword()).isFalse();
assertThat(credentials.getPassword()).isNull();
}
@Test // DATACMNS-142
public void configuresPasswordCorrectly() {
UserCredentials credentials = new UserCredentials(null, "password");
assertThat(credentials.hasUsername()).isFalse();
assertThat(credentials.getUsername()).isNull();
assertThat(credentials.hasPassword()).isTrue();
assertThat(credentials.getPassword()).isEqualTo("password");
}
@Test // DATACMNS-275
public void returnsNullForNotSetObfuscatedPassword() {
assertThat(new UserCredentials(null, null).getObfuscatedPassword()).isNull();
}
@Test // DATACMNS-275
public void obfuscatesShortPasswordsEntirely() {
assertThat(new UserCredentials(null, "sa").getObfuscatedPassword()).isEqualTo("**");
assertThat(new UserCredentials(null, "s").getObfuscatedPassword()).isEqualTo("*");
}
@Test // DATACMNS-275
public void returnsObfuscatedPasswordCorrectly() {
assertThat(new UserCredentials(null, "password").getObfuscatedPassword()).isEqualTo("p******d");
}
@Test // DATACMNS-275
public void toStringDoesNotExposePlainPassword() {
UserCredentials credentials = new UserCredentials(null, "mypassword");
assertThat(credentials.toString()).doesNotContain(credentials.getPassword());
assertThat(credentials.toString()).contains(credentials.getObfuscatedPassword());
}
}

View File

@@ -45,14 +45,10 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
assertThat(metadata.getRevisionNumber()).isEmpty();
assertThat(metadata.getRevisionDate()).isEmpty();
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(metadata::getRequiredRevisionNumber);
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(metadata::getRequiredRevisionDate);
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(metadata::getRequiredRevisionInstant);
@@ -81,9 +77,6 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
softly.assertThat(metadata.getRevisionDate()).hasValue(sample.revisionDate);
softly.assertThat(metadata.getRequiredRevisionDate()).isEqualTo(sample.revisionDate);
softly.assertThat(metadata.getRevisionInstant()).hasValue(expectedInstant);
softly.assertThat(metadata.getRequiredRevisionInstant()).isEqualTo(expectedInstant);
@@ -99,9 +92,6 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
softly.assertThat(metadata.getRevisionDate()).hasValue(expectedLocalDateTime);
softly.assertThat(metadata.getRequiredRevisionDate()).isEqualTo(expectedLocalDateTime);
softly.assertThat(metadata.getRevisionInstant()).hasValue(sample.revisionInstant);
softly.assertThat(metadata.getRequiredRevisionInstant()).isEqualTo(sample.revisionInstant);
@@ -119,9 +109,6 @@ public class AnnotationRevisionMetadataUnitTests {
RevisionMetadata<Long> metadata = getMetadata(sample);
softly.assertThat(metadata.getRevisionDate()).hasValue(expectedLocalDateTime);
softly.assertThat(metadata.getRequiredRevisionDate()).isEqualTo(expectedLocalDateTime);
softly.assertThat(metadata.getRevisionInstant()).hasValue(expectedInstant);
softly.assertThat(metadata.getRequiredRevisionInstant()).isEqualTo(expectedInstant);

View File

@@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -65,15 +64,6 @@ public class RevisionUnitTests {
assertThat(Revision.of(firstMetadata, new Object()).getRevisionNumber()).isEqualTo(reference);
}
@Test // DATACMNS-187
public void returnsRevisionDate() {
Optional<LocalDateTime> reference = Optional.of(LocalDateTime.now());
when(firstMetadata.getRevisionDate()).thenReturn(reference);
assertThat(Revision.of(firstMetadata, new Object()).getRevisionDate()).isEqualTo(reference);
}
@Test // DATACMNS-1251
public void returnsRevisionInstant() {

View File

@@ -1,145 +0,0 @@
/*
* Copyright 2012-2019 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.mapping.context;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.HashSet;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.Persistable;
import org.springframework.data.support.IsNewStrategy;
import org.springframework.data.support.IsNewStrategyFactory;
/**
* Unit tests for {@link MappingContextIsNewStrategyFactory}.
*
* @author Oliver Gierke
*/
public class MappingContextIsNewStrategyFactoryUnitTests {
IsNewStrategyFactory factory;
@Before
public void setUp() {
SampleMappingContext context = new SampleMappingContext();
context.setInitialEntitySet(
new HashSet<>(Arrays.asList(Entity.class, VersionedEntity.class, PrimitiveIdEntity.class)));
context.afterPropertiesSet();
factory = new MappingContextIsNewStrategyFactory(PersistentEntities.of(context));
}
@Test
public void returnsPropertyIsNullOrZeroIsNewStrategyForVersionedEntity() {
IsNewStrategy strategy = factory.getIsNewStrategy(VersionedEntity.class);
VersionedEntity entity = new VersionedEntity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isTrue();
entity.version = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@Test
public void returnsPropertyIsNullOrZeroIsNewStrategyForPrimitiveVersionedEntity() {
IsNewStrategy strategy = factory.getIsNewStrategy(VersionedEntity.class);
VersionedEntity entity = new VersionedEntity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isTrue();
entity.version = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@Test
public void returnsPropertyIsNullIsNewStrategyForEntity() {
IsNewStrategy strategy = factory.getIsNewStrategy(Entity.class);
Entity entity = new Entity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@Test // DATACMNS-1326
public void entityWithPrimitiveDefaultIsNotConsideredNew() {
IsNewStrategy strategy = factory.getIsNewStrategy(PrimitiveIdEntity.class);
PrimitiveIdEntity entity = new PrimitiveIdEntity();
assertThat(strategy.isNew(entity)).isTrue();
entity.id = 1L;
assertThat(strategy.isNew(entity)).isFalse();
}
@SuppressWarnings("serial")
static class PersistableEntity implements Persistable<Long> {
@Version Long version;
@Id Long id;
boolean isNew = true;
public Long getId() {
return id;
}
public boolean isNew() {
return isNew;
}
}
static class VersionedEntity {
@Version Long version;
@Id Long id;
}
static class PrimitiveVersionedEntity {
@Version long version = 0;
@Id Long id;
}
static class Entity {
@Id Long id;
}
static class PrimitiveIdEntity {
@Id long id;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2011-2019 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.repository.core.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.Persistable;
/**
* Unit tests for {@link Persistable}.
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class PersistableEntityInformationUnitTests {
@SuppressWarnings({ "rawtypes", "unchecked" }) //
static final PersistableEntityInformation metadata = new PersistableEntityInformation(PersistableEntity.class);
@Mock Persistable<Long> persistable;
@Test
@SuppressWarnings("unchecked")
public void usesPersistablesGetId() throws Exception {
when(persistable.getId()).thenReturn(2L, 1L, 3L);
assertThat(metadata.getId(persistable)).isEqualTo(2L);
assertThat(metadata.getId(persistable)).isEqualTo(1L);
assertThat(metadata.getId(persistable)).isEqualTo(3L);
}
@Test
@SuppressWarnings("unchecked")
public void usesPersistablesIsNew() throws Exception {
when(persistable.isNew()).thenReturn(true, false);
assertThat(metadata.isNew(persistable)).isTrue();
assertThat(metadata.isNew(persistable)).isFalse();
}
@Test
public void returnsGivenClassAsEntityType() throws Exception {
PersistableEntityInformation<PersistableEntity, Long> info = new PersistableEntityInformation<>(
PersistableEntity.class);
assertThat(info.getJavaType()).isEqualTo(PersistableEntity.class);
}
static class PersistableEntity implements Persistable<Long> {
public Long getId() {
return null;
}
public boolean isNew() {
return false;
}
}
}

View File

@@ -1,83 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may
import java.io.Serializable;
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.repository.core.support;
import static org.assertj.core.api.Assertions.*;
import java.io.Serializable;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.repository.core.EntityInformation;
/**
* Unit tests for {@link ReflectionEntityInformation}.
*
* @author Oliver Gierke
*/
public class ReflectionEntityInformationUnitTests {
@Test
public void discoversAnnotationOnField() {
EntityInformation<Sample, Serializable> information = getEntityInformation(Sample.class);
assertThat(information.getIdType()).isEqualTo(String.class);
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-170
public void rejectsTypeWithoutAnnotatedField() {
getEntityInformation(Unannotated.class);
}
@Test // DATACMNS-357
public void detectsNewStateForEntitiesWithPrimitiveIds() {
PrimitiveId primitiveId = new PrimitiveId();
EntityInformation<PrimitiveId, Serializable> information = new ReflectionEntityInformation<>(
PrimitiveId.class);
assertThat(information.isNew(primitiveId)).isTrue();
primitiveId.id = 5L;
assertThat(information.isNew(primitiveId)).isFalse();
}
@Test // DATACMNS-867
public void detectsNewStateForEntityWithNullId() {
assertThat(new ReflectionEntityInformation<>(Sample.class).isNew(new Sample())).isTrue();
}
private static <T> EntityInformation<T, Serializable> getEntityInformation(Class<T> type) {
return new ReflectionEntityInformation<>(type, Id.class);
}
static class Sample {
@Id String id;
}
static class Unannotated {
String id;
}
static class PrimitiveId {
@Id long id;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2012-2019 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.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
/**
* Unit tests for {@link CachingIsNewStrategyFactory}.
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class CachingIsNewStrategyFactoryUnitTests {
static final IsNewStrategy REFERENCE = PersistableIsNewStrategy.INSTANCE;
@Mock
IsNewStrategyFactory delegate;
CachingIsNewStrategyFactory factory;
@Before
public void setUp() {
factory = new CachingIsNewStrategyFactory(delegate);
}
@Test
public void invokesDelegateForFirstInvocation() {
when(delegate.getIsNewStrategy(Object.class)).thenReturn(REFERENCE);
IsNewStrategy strategy = factory.getIsNewStrategy(Object.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
}
@Test
public void usesCachedValueForSecondInvocation() {
when(delegate.getIsNewStrategy(Mockito.any(Class.class))).thenReturn(REFERENCE);
IsNewStrategy strategy = factory.getIsNewStrategy(Object.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
verify(delegate, times(0)).getIsNewStrategy(String.class);
strategy = factory.getIsNewStrategy(Object.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
verify(delegate, times(0)).getIsNewStrategy(String.class);
strategy = factory.getIsNewStrategy(String.class);
assertThat(strategy).isEqualTo(REFERENCE);
verify(delegate, times(1)).getIsNewStrategy(Object.class);
verify(delegate, times(1)).getIsNewStrategy(String.class);
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.web;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.domain.Sort.Direction.*;
import org.junit.Rule;
import org.junit.Test;
@@ -51,10 +50,9 @@ public abstract class SortDefaultUnitTests {
@Test
public void parsesSimpleSortStringCorrectly() {
assertSortStringParsedInto(Sort.by(new Order("username")), SORT_1);
assertSortStringParsedInto(Sort.by(new Order(ASC, "username")), SORT_1);
assertSortStringParsedInto(Sort.by(new Order(ASC, "username"), //
new Order(DESC, "lastname"), new Order(DESC, "firstname")), SORT_2);
assertSortStringParsedInto(Sort.by(Order.asc("username")), SORT_1);
assertSortStringParsedInto(Sort.by(Order.asc("username"), //
Order.desc("lastname"), Order.desc("firstname")), SORT_2);
assertSortStringParsedInto(Sort.by("firstname", "lastname"), SORT_3);
}