Polish ApacheDSContainer LDAPs support

Issue gh-4096
This commit is contained in:
Rob Winch 2016-10-25 10:16:24 -05:00
parent 406bb1d4d5
commit 8e546454a5
1 changed files with 8 additions and 11 deletions

View File

@ -16,9 +16,8 @@
package org.springframework.security.ldap.server; package org.springframework.security.ldap.server;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -119,12 +118,11 @@ public class ApacheDSContainerTests {
try { try {
server.afterPropertiesSet(); server.afterPropertiesSet();
fail("Expected an IllegalArgumentException to be thrown.");
} }
catch (IllegalArgumentException e){ catch (IllegalArgumentException e){
assertEquals("When LdapOverSsl is enabled, the keyStoreFile property must be set.", e.getMessage()); assertThat(e).hasMessage("When LdapOverSsl is enabled, the keyStoreFile property must be set.");
return;
} }
fail("Expected an IllegalArgumentException to be thrown.");
} }
@Test @Test
@ -133,7 +131,7 @@ public class ApacheDSContainerTests {
final File temporaryKeyStoreFile = new File(temporaryFolder.getRoot(), "spring.keystore"); final File temporaryKeyStoreFile = new File(temporaryFolder.getRoot(), "spring.keystore");
FileCopyUtils.copy(keyStoreResource.getInputStream(), new FileOutputStream(temporaryKeyStoreFile)); FileCopyUtils.copy(keyStoreResource.getInputStream(), new FileOutputStream(temporaryKeyStoreFile));
assertTrue(temporaryKeyStoreFile.isFile()); assertThat(temporaryKeyStoreFile).isFile();
ApacheDSContainer server = new ApacheDSContainer("dc=springframework,dc=org", ApacheDSContainer server = new ApacheDSContainer("dc=springframework,dc=org",
"classpath:test-server.ldif"); "classpath:test-server.ldif");
@ -147,13 +145,12 @@ public class ApacheDSContainerTests {
try { try {
server.afterPropertiesSet(); server.afterPropertiesSet();
fail("Expected a RuntimeException to be thrown.");
} }
catch (RuntimeException e){ catch (RuntimeException e){
assertEquals("Server startup failed", e.getMessage()); assertThat(e).hasMessage("Server startup failed");
assertTrue("Expected an instance of 'UnrecoverableKeyException' but got " + ExceptionUtils.getRootCause(e).getClass().getName(), ExceptionUtils.getRootCause(e) instanceof UnrecoverableKeyException); assertThat(e).hasRootCauseInstanceOf(UnrecoverableKeyException.class);
return;
} }
fail("Expected a RuntimeException to be thrown.");
} }
/** /**
@ -175,7 +172,7 @@ public class ApacheDSContainerTests {
final File temporaryKeyStoreFile = new File(temporaryFolder.getRoot(), "spring.keystore"); final File temporaryKeyStoreFile = new File(temporaryFolder.getRoot(), "spring.keystore");
FileCopyUtils.copy(keyStoreResource.getInputStream(), new FileOutputStream(temporaryKeyStoreFile)); FileCopyUtils.copy(keyStoreResource.getInputStream(), new FileOutputStream(temporaryKeyStoreFile));
assertTrue(temporaryKeyStoreFile.isFile()); assertThat(temporaryKeyStoreFile).isFile();
ApacheDSContainer server = new ApacheDSContainer("dc=springframework,dc=org", ApacheDSContainer server = new ApacheDSContainer("dc=springframework,dc=org",
"classpath:test-server.ldif"); "classpath:test-server.ldif");