DATAKV-136 - Choose SecureRandom algorithm based on operating system and availability.
We now distinguish between operating systems when choosing a SecureRandom algorithm. Additionally we check the availability of the implementations and choose the first one available. Original pull request: #21.
This commit is contained in:
committed by
Mark Paluch
parent
906a6daa3f
commit
66534d2ae0
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2016 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.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsInstanceOf.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class DefaultIdentifierGeneratorUnitTests {
|
||||
|
||||
DefaultIdentifierGenerator generator = DefaultIdentifierGenerator.INSTANCE;
|
||||
|
||||
/**
|
||||
* @DATAKV-136
|
||||
*/
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class)
|
||||
public void shouldThrowExceptionForUnsupportedType() {
|
||||
generator.generateIdentifierOfType(ClassTypeInformation.from(Date.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @DATAKV-136
|
||||
*/
|
||||
@Test
|
||||
public void shouldGenerateUUIDValueCorrectly() {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(UUID.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(UUID.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @DATAKV-136
|
||||
*/
|
||||
@Test
|
||||
public void shouldGenerateStringValueCorrectly() {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(String.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(String.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @DATAKV-136
|
||||
*/
|
||||
@Test
|
||||
public void shouldGenerateLongValueCorrectly() {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(Long.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(Long.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @DATAKV-136
|
||||
*/
|
||||
@Test
|
||||
public void shouldGenerateIntValueCorrectly() {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(Integer.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(Integer.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user